Jump to content

Problems with an Update Page


chadcwm

Recommended Posts

I'm setting up an update page for a database and it seems that the php is not grabbing the id from the link and using it. I've set other sites us just like this and they worked fine, but not now. The link is going to update.php?id=2

 

And here's the php:

<?
include("includes/session.php");
?>
<?
include("includes/dbinfo.inc.php");
mysql_connect(localhost,$db_username,$db_password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM portfolio WHERE id='$id'";
$result=mysql_query($query);
$num=mysql_numrows($result); 
mysql_close();

$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$category=mysql_result($result,$i,"category");
$client=mysql_result($result,$i,"client");
$description=mysql_result($result,$i,"description");
$image_name=mysql_result($result,$i,"image_name");

?>

<a href="work/fullsize/<? echo "$image_name"; ?>.jpg" target="_blank"><img src="http://www.cross-a.com/beta/work/fullsize/<? echo "$image_name"; ?>.jpg" height="114" width="200" title="<? echo "$description"; ?>" style="margin-bottom: 10px;"/></a>
<p><strong><? echo "$client"; ?></strong><br />
<? echo "$description"; ?></p>

<?
++$i;
} 
?>

</div>
</body>
</html>

 

Any help on why this is not working? If I add something like $id=2, then everything displays properly, so there's something going on there.

 

Thanks for any help!

Link to comment
https://forums.phpfreaks.com/topic/197750-problems-with-an-update-page/
Share on other sites

I don't see where you are assigning the $_GET['id'] value to the $id variable. If this method worked on other installations, it probably relied on REGISTER_GLOBALS = On.

Also, change your tags from the short open <? tags to the standard <?php open tags, and remove the single quotes from WHERE id = '$id' as integers should not be quoted in DB queries.

$id = (int) trim($_GET['id']) // assuming id should always be an integer, trim spaces and typecast it as (int) for the DB query

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.