Jump to content

Problem when turning register globals = off


MrVaux

Recommended Posts

I just decided to turn register globals from on to off.

 

This change made a lot of trouble for me.

I simply can´t update a record in the DB anymore. I get the following errormsg.

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /customers/websides.dk/websides.dk/httpd.www/luffe/liga/admin/form_edit_news.php on line 18

 

I believe the problem is that the variable is empty, but Im not sure.

 

How do I rewrite below to work with register globals = off

 

<?
include "admin_menu.php";
$id = $_GET['id'];
$news = $_GET['news'];

include "config.php";
$link = mysql_connect($dbhost, $dbuser, $dbpasswd) or die("Couldn't establish connection");
mysql_select_db($dbname);
$query = "SELECT * FROM league_news WHERE id = id";
$result = mysql_query($query);
$row = mysql_fetch_array($result);

echo "<H3>Info text</H3>\n";
echo "<table style='border-width:1px; border-style:dashed; border-color:#000000;' width='600px' cellpadding='4' cellspacing='0' bgcolor='#cee5cb'>\n";
echo "<tr>\n";
echo "<td width='100%'>$row[news]</td>\n";
echo "</tr>\n";

echo "<tr>\n";
echo "<input type='hidden' name='id' value='{$_GET[id]}'>";
echo "<td width='100%'></td>\n";
echo "</tr>\n";

echo "</table>\n";
echo "<br>\n";
echo "</form>\n";
echo "<a href='form_edit_news.php?id=$row[id]'><b>Edit info</b></a>";
?>

Link to comment
Share on other sites

I don't see an opening <form> tag in that code.

 

Actually the </form> tag is to be cleaned up since there is no form on that page. Thanks for notice.

 

$result = mysql_query($query) or die(mysql_error() . " IN: $query");

 

What does this do? Does it write out the errors in the query?

 

 

So it actually works at the moment, I think....

I changed the

 

$news = $_GET['news']; to $news = $_REQUEST['news'];

 

Thanks for all your input so far...

Link to comment
Share on other sites

Since you  are using $_GET, the information can be altered by input. Small Example:

 

Someone sends query directly from their browser:

http://yoursite.com/script.php?id=1<?phpinfo();?>

 

<?php
echo "<input type='hidden' name='id' value='{$_GET[id]}'>";
?>

 

will now output:

 

<input type='hidden' name='id' value='{<?phpinfo();?>}'>

This would allow them to view your php.ini settings. This would only be the beginning.

 

 

<?php
include ("admin_menu.php");

// if ID is to only return numbers, it'd be simpler to:
$id = preg_replace("[^0-9]", "", $_GET['id']);

//and 
$news = mysql_real_escape_string(strip_tags($_GET['news']));

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.