Page 1 of 1

Problems with my code

Posted: Sat Nov 23, 2013 1:47 pm
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.

Re: Problems with my code

Posted: Sun Nov 24, 2013 1:24 pm
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.

Re: Problems with my code

Posted: Mon Nov 25, 2013 7:29 am
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.

Re: Problems with my code

Posted: Tue Nov 26, 2013 3:37 am
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.