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
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";

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.