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

  }     

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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++;
}

?>

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.