SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: SQL error

  1. #1
    SitePoint Addict einSTein's Avatar
    Join Date
    Aug 2006
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL error

    i have a problem with that code , this code enters the data of the second sql line only of the login table but it does not enter any entries in the user table
    Code MySQL:
    //entering the job seeker data in the user table
    $sql="INSERT INTO user (name, Addr, Nation, dob, Gen, cnt, mar, mil, phone, mobile, mail, user)
    VALUES
    ('$fn','$_POST[add]','$_POST[nat]','$dob','$_POST[gg]','$_POST[cnt]','$_POST[Mar]','$_POST[Mil]','$_POST[ph]','$_POST[mo]','$_POST[mail]','$_POST[user]')";
    //entering the user and pass in the login table
    $sql="INSERT INTO login (user, pass, type)
    VALUES
    ('$_POST[user]','$_POST[pass]','$_POST[type]')";
    if (!mysql_query($sql,$con))
    	{
    	die('Error: ' . mysql_error());
    	}
    	echo "<br>";
    echo "<br>Thanks for registration MR. $fn ";
    exit();

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Thats because you are overwriting the first $sql variable with the second one!

    PHP Code:
    $foo 1;
    $foo 2;

    // $foo will equal 2 
    Simply use 2 mysql_query calls
    PHP Code:
    //entering the job seeker data IN the user table
    $sql="INSERT INTO user (name, Addr, Nation, dob, Gen, cnt, mar, mil, phone, mobile, mail, user)
    VALUES
    ('
    $fn','$_POST[add]','$_POST[nat]','$dob','$_POST[gg]','$_POST[cnt]','$_POST[Mar]','$_POST[Mil]','$_POST[ph]','$_POST[mo]','$_POST[mail]','$_POST[user]')";
    //entering the user AND pass IN the login table
    $sql2="INSERT INTO login (user, pass, type)
    VALUES
    ('
    $_POST[user]','$_POST[pass]','$_POST[type]')";
    if (!
    mysql_query($sql,$con))
        {
        die(
    'Error: ' mysql_error());
        }
    if (!
    mysql_query($sql2,$con))
        {
        die(
    'Error: ' mysql_error());
        }
        echo 
    "<br>";
    echo 
    "<br>Thanks for registration MR. $fn ";
    exit(); 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    Chessplayer kleineme's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you only have a mysql_query() for the second $sql and not for the first one
    Never ascribe to malice,
    that which can be explained by incompetence.
    Your code should not look unmaintainable, just be that way.

  4. #4
    SitePoint Addict einSTein's Avatar
    Join Date
    Aug 2006
    Posts
    276
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx man its workin


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •