Jump to content

IS SOMETHING WRONG WITH THIS CODE


nikhar021

Recommended Posts

if(!empty($_POST['first1']))

    {

    $update1 = "UPDATE student1 SET first = '{$_POST[first1]}' WHERE id='{$_POST[id2]}' AND branch='{$_POST[branch2]}' ";

$result1 = mysql_query($update1) or

  die(mysql_error());

          echo "First name updated" ;

  $count++;

}  

Link to comment
https://forums.phpfreaks.com/topic/102546-is-something-wrong-with-this-code/
Share on other sites

There may be something wrong with your caps lock key too.

 

 

if(!empty($_POST['first1']))

    {

    $update1 = "UPDATE student1 SET first = '{$_POST['first1']}' WHERE id='{$_POST['id2']}' AND branch='{$_POST['branch2]'}' ";

  $result1 = mysql_query($update1) or

        die(mysql_error());

          echo "First name updated" ;

        $count++;

  }     

ya but this is the error im gettng in my browser

 

 

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 'CS'' at line 1

 

pls help

 

Which values are being posted to the MySQL query from $_POST?

Show the output of print_r($_POST); after you send info to the page.

ok this is wat i get

 

 

Array ( [id2] => [branch2] => CS [first1] => [last1] => [branch3] => CS [semester1] => 1 [fname1] => [mname1] => [add11] => [add21] => [city1] => Anuppur [state1] => [pin1] => [no1] => [email1] => [tenth1] => [twelth1] => [r11] => [r21] => [r31] => [r41] => [r51] => [r61] => [r71] => [r81] => [submit] => update ) 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 'CS'' at line 1

Because your are using raw _POST data in your query you are most probably typed a quote in your form which is causing the error. You should not place raw _POST data directly into a query as is very unsecure. I'd change your code to:

<?php

if(!empty($_POST['first1']))
{
    $first1  = mysql_real_escape_string($_POST['first1']);
    $id2     = mysql_real_escape_string($_POST['id2']);
    $branch2 = mysql_real_escape_string($_POST['branch2']);

    $update1 = "UPDATE student1 SET first = '$first1' WHERE id='$id2' AND branch='$branch2'";
    $result1 = mysql_query($update1) or die(mysql_error());

    echo "First name updated" ;
    $count++;
}

?>

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.