Page 1 of 1

Problem with update query not getting post variables

Posted: Fri Sep 15, 2006 6:31 am
by genista
Hi All,

I have a script that allows a user to update their details, the problem I am having is getting the update query to .. update. I have managed to print the $POST variables and the checkboxes are populating true, which is what I want, but then when I print the update query they are coming out as null...

Code: Select all

if(isset($_POST['submit'])){ 
  $first_name=$_POST['first_name'];
	$last_name=$_POST['last_name']; 
    $address_line1=$_POST['address_line1']; 
    $address_line2=$_POST['address_line2']; 
    $town=$_POST['town']; 
    $county=$_POST['county'];
    $postcode=$_POST['postcode'];
if (isset($_POST['test'])) {
    $test = "null";
}  
 $query = "UPDATE suppliers SET `first_name`='$first_name', 
	`last_name`='$last_name', 
	`password`='$password', 
	`address_line1`='$address_line1', 
	`address_line2`='$address_line2', 
	`town`='$town' , `county`='$county', 
	`postcode`='$postcode', 
                `test` = '$test'
	WHERE `username` = '". mysql_real_escape_string($_SESSION['username']). "' 
              LIMIT 1";

$result = mysql_query($query, $link) or die('Update failed: ' . mysql_error()); 
 echo $query; 
//print_r($query);  
 mysql_info($link) ; 
    if(mysql_affected_rows($link) == 0) 
    { 
      //$link next to affected rows and mysql query
        echo ''; 
    } 
     
    else 
    { 
        echo 'Your profile has been updated successfully, please click <a href=suppliers.php>here</a> for other options.'; 
    }           
 }

?>

So that is the update script, the html that a user fills in for a checkbox looks like this:

Code: Select all

if(isset($_POST['test']) != "true") { 
   $test = "null"; 
}

Please help, I have been looking at this for hours... :)

Posted: Fri Sep 15, 2006 11:23 am
by genista
Should I put this bracket below the query?

Code: Select all

$test = "null"; 
[b]}[/b]  
 $query = "UPDATE