Problems with my code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
afrancis
Forum Newbie
Posts: 2
Joined: Sat Nov 23, 2013 1:38 pm

Problems with my code

Post by afrancis »

I have a site with the following code

Code: Select all

$uploadid = $_SESSION['loginID'];
$uploaddate = date("j-n-y, G:i:s");
echo ("uploadid is $uploadid<BR>");
echo ("uploaddate is $uploaddate<BR>");
echo ("description is: $newdesc<BR>");

// setup SQL statement 
$sql="UPDATE memgallery SET gal_desc='$newdesc', upload_id='$uploadid', upload_date='$uploaddate' WHERE gal_id='$gal_id'";

// execute SQL statement 
$result = mysql_db_query($dbname,"$sql",$link); 

// check for errors 
if (!$result) { echo("ERROR: " . mysql_error() . "\n$sql\n"); }

echo "The Description has been updated";
The code seems to work but does not update the table.
I use the same code for another table and it works fine

Code: Select all

//create short names from form information
	$new_prof_name = $_POST["new_prof_name"];
	$new_profile = $_POST["new_profile"];

// Remove unwanted characters from input
$new_profile = AddSlashes($new_profile);

$new_profile = nl2br($new_profile);
// setup SQL statement 
$sql="UPDATE memprofile SET prof_name='$new_prof_name', profile='$new_profile' , upload_date='$changedate' where upload_id='$loginid'";

// execute SQL statement 
$result = mysql_db_query($dbname,"$sql",$link); 

// check for errors 
if (!$result) { echo("ERROR: " . mysql_error() . "\n$sql\n"); }

echo "Your Profile has been updated";


Can someone help please or am In the wrong forum.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Problems with my code

Post by Eric! »

Perhaps it doesn't work because $gal_id isn't set correctly for your table. It is impossible to debug your code for you because we don't know the contents of your database or your variables.

By the way you should not be using mysql_ functions. You should usemysqli_ or PDO. The old mysql_ functions will be removed in future versions of PHP.
afrancis
Forum Newbie
Posts: 2
Joined: Sat Nov 23, 2013 1:38 pm

Re: Problems with my code

Post by afrancis »

I changed the $gal_id to something else and got an error. however there are no errors when I use $gal_id. The table just doesn't update.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Problems with my code

Post by Eric! »

By set correctly, I mean the value you set for $gal_id. If there is no matching value in your database for the value you use in $gal_id then UPDATE won't do anything.
Post Reply