0

I want to update a row in my database. There is only one row in this database no other rows will be added at this stage.

I am using this PHP code but it does not update the value gives me error:

Error: 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 '(credits) VALUES ('')' at line 1

This is my code

 <?php
 $con = mysql_connect("localhost","stingin_epanic","****");
 if (!$con)
   {
   die('Could not connect: ' . mysql_error());
   }

  mysql_select_db("stingin_epanic", $con);

  $sql="UPDATE avis_credits (credits)
  VALUES
 ('$_UPDATE[credits]')";

  if (!mysql_query($sql,$con))
   {
   die('Error: ' . mysql_error());
   }
 echo "Number added thank you";

 mysql_close($con);

 ?>

I know it is something Stupid But Really battelling here

2

4 Answers 4

2

Have a look at the UPDATE syntax in mysql.

UPDATE avis_credits SET credits = 'your_value'

WATCH OUT

Please do not use the mysql_* functions anymore. Switch to the mysqli_ functions or PDO. The mysql_ - functions are deprecated and won't be supported >= PHP 5.5.

Sign up to request clarification or add additional context in comments.

Comments

0

Echo out your $sql and see what it looks like. My guess is that the values are simply empty based on the error being shown, always do a quick debug.

1 Comment

@TobiasKun that too, but at least debug and see what it looks like to learn how to fix a SQL error.
0

You shouldn't be using deprecated mysql_* functions.

Your SQL is not correct.

"UPDATE avis_credits set credits = '$_UPDATE[credits]'";

If you can use PDO or mysqli.

Comments

0
<?php
$dsn = "mysql:host=localhost;dbname=stingin_epanic;charset=utf8";
$opt = array(
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$pdo = new PDO($dsn,'stingin_epanic','', $opt);

$sql = "UPDATE avis_credits SET credits = ? WHERE some_id = ?";
$stm = $pdo->prepare($sql);
$stm->execute(array($_POST['credits'], $_POST['id']));

Assuming you have $_POST, not whatever $_UPDATE

Note the WHERE part. With UPDATE query you have to always use it to address a row to change, mind you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.