Jump to content

Need some help with pdo update to database


vet911
Go to solution Solved by vet911,

Recommended Posts


I'm trying to update the itemno specified from available (1) to (0). I'm getting this error message and can't seem to figure it out. I must be missing something really easy. Any help would be appreciated.

 

This is the error message: 

connected

tv-jw10-976

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id='78'' at line 5

Updated

$getid = $_POST['id'];
$getitemno = $_POST['itemno'];
$getavailability = $_POST['availability'];
try 
{ echo "$getitemno";
 // UPDATE data 
$sql = "UPDATE cut_stones SET itemno= :itemno, availability= :availability, WHERE id='$getid'";
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':itemno', $_POST['$itemno'], PDO::PARAM_STR);
$stmt->bindParam(':availability', $_POST['availability'], PDO::PARAM_INT);
$stmt->execute(); 
} 
catch(PDOException $e) 
{ 
echo $e->getMessage();
}
// if successfully updated. 
$dhb = null; 
echo " Updated";
?>
Edited by vet911
Link to comment
Share on other sites

I updated the code, I don't get any error message. But when I look at the database it doesn't change availability to (0).

Still lost.

try
	{
	echo "$getitemno";
    // UPDATE data
	$sql = "UPDATE cut_stones 
			SET 
			itemno= :itemno, 
			availability= :availability
			WHERE id= :id";
    $stmt = $dbh->prepare($sql);
	$stmt->bindParam(':id', $_POST['$id'], PDO::PARAM_INT);	
	$stmt->bindParam(':itemno', $_POST['$itemno'], PDO::PARAM_STR);    
	$stmt->bindParam(':availability', $_POST['availability'], PDO::PARAM_INT);	
	$stmt->execute(); 
    
	}
	catch(PDOException $e)
	{
		echo $e->getMessage();
	}
// if successfully updated.
$dhb = null;
	 
	 echo "       Updated";
	 
?>
Link to comment
Share on other sites

  • Solution
$getid = $_POST['id'];
	$getitemno = $_POST['itemno'];
	$getavailability = $_POST['availability'];
		
// Connect to server and select database.
	try
	{
	echo "$getitemno";
    // UPDATE data
	$sql = "UPDATE cut_stones 
			SET 
			itemno= :itemno, 
			availability= :availability
			WHERE id= :id";
    $stmt = $dbh->prepare($sql);
	$stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT);	
	$stmt->bindParam(':itemno', $_POST['itemno'], PDO::PARAM_STR);    
	$stmt->bindParam(':availability', $_POST['availability'], PDO::PARAM_INT);	
	$stmt->execute(); 
    
	}
	catch(PDOException $e)
	{
		echo $e->getMessage();
	}
// if successfully updated.
$dhb = null;
	 
	 echo "       Updated";

I figured it out. I have listed the code above.

Thanks for the help.

Edited by vet911
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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