I need some help with this.
When I use the UPDATE function for the targeted key id nothing changes in my MySQL database. I printed all the variables and they all contain the correct values. I did not get any errors and the mysql_query for the UPDATE function returned true.
As you can see in the code below I am passing the row number as $row= $_GET['row']; then add 1 to get the id number $id_new which I will use in the UPDATE function for WHERE id='$id_new'. This should update the correct row in the table. But when I submit the changes nothing happens. Now for the very strange part. When I add 2 instead of 1 to $row it does update the values in that row. But I need the updat to happen in the row above that one.
If you need me to post the code from the form that passes the values, I will be glad to do so, but I really think the bug lays within the snippet below. I know it is something small that I overlooked. So I hope with the help of you guys I can fix this. Any help would be greatly appreciated.
usr_update_link.php:
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
//variables passed from usr_links_display.php
$topic= $_GET['topic'];
$location= $_GET['link_location'];
$links= $_GET['links'];
$row= $_GET['row'];
$id_new=($row+1);
//I tried $id_new=($row+2); and it worked for the next row???????
//declare database variables
$host="localhost"; // Host name
$username="***"; // Mysql username
$password="***"; // Mysql password
$db_name="chrisuc6_Portfolio"; // Database name
$table = links;// Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$query="SELECT * FROM links";
$update_done =mysql_query("UPDATE links SET topic='$topic', links='$links', links_href='$location' WHERE id='$id_new'")or die(mysql_error());
mysql_close();
if($update_done)
{
echo $id_new;
echo "\n<br>You will be automatically relinked to the main selection page in a few seconds.";
echo "<meta http-equiv=\"refresh\" content=\"3;URL=usr_links_change.php\">";
}
else
{
echo "The link has not be updated\n<br>";
}
?>