Jump to content

Update Statement Error


Boxerman

Recommended Posts

Hi guys,

 

sorry if this is the wrong section but its a mixture of sql and php.. however i believe it may be sql... sorry if i am wrong.

I'm having an issue with a script...

 

the SQL in this is the following:

 

<?php
if(isset($_GET['flag']))
{
$con = mysql_connect("localhost","*******","****************");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }
mysql_select_db("movies", $con);
$sql="UPDATE movies WHERE id = '$_GET['id']' set flag
VALUES
('1')";
if (!mysql_query($sql,$con))
 {
 die('Error: ' . mysql_error());
 }
echo "<font color='green'>Thanks for reporting!</font><br><br>";
mysql_close($con);
}
?>

 

What the aim of it is... to update a coloum in movies database called flag and just put 1 in there.

 

Again sorry if i am wrong!

 

Thanks,

B

Link to comment
https://forums.phpfreaks.com/topic/269459-update-statement-error/
Share on other sites

Assuming $_GET['id'] is an integer, you should validate it and cast it as int, and leave it unquoted in the query string. The code below doesn't address the validation part . . .

 

$id = (int) $_GET['id'];
$sql = "UPDATE movies SET flag = 1 WHERE id = $id";

Archived

This topic is now archived and is closed to further replies.

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