0

I have a php page (a formular) that I can change the values. When I click on submit, I want to update my table with the new values.

Could you help me do it? I post my code, which does not the work because I am certainly missing something.

    <?php 
    //echo '<input id="input_itf" type="text" value="'.$vara.'"><br>';
    $requete = mysql_query("update `names` set `vara`=$vara, `varb`=$varb, `varc`=$varc, `vard`=$vard, `vare`=$vare, `varf`=$varf, 
    `varg`=$varg, `varh`=$varh, `vari`=$vari, `varj`=$varj, `vark`=$vark, `varl`=$varl, `varm`=$varm, `varn`=$varn
    `varo`=$varo, `varp`=$varp, `varq`=$varq, `varr`=$varr, `vars`=$vars, `vart`=$vart, `varu`=$varu, `varv`=$varv WHERE `id`=$id");
    $sql = stripslashes($requete);
    $req=mysql_query($sql) or die(mysql_error());
        while($d=mysql_fetch_array($req))
                { 
                    $nb_trouve++;                   
                    $id=$d['id'];
    $nb_trouve=0;


    mysql_close();
?>

Many thanks in advance for your help !

2
  • What happens when you run the code? Do you get any error? Commented Jul 17, 2015 at 16:06
  • Missing '}' in your while statement. Commented Jul 17, 2015 at 16:22

2 Answers 2

1

Your while block is missing a closing bracket }.

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

Comments

0

You declared mysql_query twice and a closing bracket was } missing too..

Try this...

<?php 

//echo '<input id="input_itf" type="text" value="'.$vara.'"><br>';
$requete = "update `names` set `vara`='$vara', `varb`='$varb',`varc`='$varc', `vard`='$vard', `vare`='$vare', `varf`='$varf',`varg`='$varg', `varh`='$varh', `vari`='$vari', `varj`='$varj', `vark`='$vark', `varl`='$varl', `varm`='$varm', `varn`='$varn'`varo`='$varo', `varp`='$varp', `varq`='$varq', `varr`='$varr', `vars`='$vars', `vart`='$vart', `varu`='$varu', `varv`='$varv' WHERE `id`='$id'";
$req=mysql_query($requete) or die(mysql_error());
while($d=mysql_fetch_array($req)){
    $nb_trouve++;
    $id=$d['id'];
    $nb_trouve=0;
}


mysql_close();
?>

4 Comments

Hello all, many thanks for your replies. I did try what you told me, but my query is not working, it should update my table but it doesn't do it. I also noticed that the update is not happening WHEN I click on my Submit button at the end of my formular (I want to only update the table when I validate on Submit).
@tom Try adding slashes to $var. abcdefghijklmnopqrstuv and remove stripslashes
@ Malik : what do you mean add slashes, like that: vara=/$vara/
@ Malik I don't understand where to put the slashes, I put them in the query like /$vara/ but it is not working either

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.