1

Hello i've actually a table to update throught php/html and have no clue why I got the error "Error" (which is my mysql_query die) I've tried if every variable in my code were send in my update.php and everything was here. So the problem come from my update.php code.

Here is my updating code:

<?php 
   include('config.inc.php');
   $idn = $_POST["idn"];
   $nom = $_POST['nom'];
   $prenom = $_POST["prenom"];
   $payss = $_POST["pays"];

   $req = "UPDATE membres SET prenom = '$prenom' , "
                             ." pays = '$payss' "
                             ." nom = '$nom' , "
                             ." where id = $idn ";
   $res = mysql_query( $req ) or die ("error updating!");
?>

Thanks for your answers !

4
  • 2
    remove the custom error and put mysql_error. Basically it should be because SET col = a, col2 = b, WHERE is invalid syntax, WHERE is not a column, it doesn't need a comma, also before the second column the one is needed Commented Aug 27, 2013 at 5:30
  • 1
    You're missing a comma in this line ." pays = '$payss' ", and have extra comma in this line ." nom = '$nom' , " Commented Aug 27, 2013 at 5:30
  • You should echo out the error like they do in the manual, and take note of the warning on top of the page, mysql_* functions are deprecated and should not be used. Commented Aug 27, 2013 at 5:31
  • 1
    consider to use mysql_real_escape_string($input) before converting to mysqli and PDO (prepared statement) because your code is vulnerable to SQL injection attack! Commented Aug 27, 2013 at 5:33

7 Answers 7

2
<?php 
include('config.inc.php');
$idn=$_POST["idn"];
$nom=$_POST['nom'];
$prenom=$_POST["prenom"];
$payss=$_POST["pays"];

$req="UPDATE membres SET prenom = '".addslashes($prenom)."' ,pays = '".addslashes($payss)."',nom = '".addslashes($nom)."' where id = '".$idn."'";
$res=mysql_query($req) or die ("error updating!");
?>
Sign up to request clarification or add additional context in comments.

Comments

0

try this one

$req="UPDATE membres SET prenom = '".$prenom."' , pays = '".$payss."'  nom = '".$nom."',  where id = ".$idn;

Comments

0
$req="UPDATE membres SET prenom = '$prenom' , pays = '$payss',  nom = '$nom'  where id = $idn ";

Comments

0

Maybe?

$req = "UPDATE `membres` SET `prenom` = '".$prenom."', 
        `pays` = '".$payss."'
        `nom` = '".$nom."'
        where `id` = ".$idn;
$res = mysql_query($req) or die ("error updating!");

Comments

0

Try this

$req="UPDATE membres SET prenom = $prenom, pays = $payss, nom = $nom where id = $idn "; 

Comments

0

I strongly recommend to use MySQLi with a prepared statement in order to avoid the risk of SQL injection.

$req = "UPDATE membres
           SET prenom = ?,
               pays = ?,
               nom = ?
         WHERE id = ?";

$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$stmt = $mysqli->prepare($req);
$stmt->bind_param("sssi", $prenom, $payss, $nom, $idn);
$stmt->execute();
$stmt->close();
$mysqli->close();

Comments

0

There is syntax error in you query . Add coma(",") after second param (after '$payss' ) and remove coma before where condition. here is updated query

$req = "UPDATE membres SET prenom = '$prenom' , "
                             ." pays = '$payss', "
                             ." nom = '$nom'  "
                             ." where id = $idn ";

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.