my php/mysql code isnt working!! Help please!

Discussion in 'PHP' started by Crayz, Aug 20, 2006.

  1. #1
    $add = 'INSERT INTO `ibtn_sites` (url, username, pass, illcount, status, name, email) VALUES (\'$surl\', \'$username\', \'$password\', \'0\', \'0\', \'$sname\', \'$email\');';
    mysql_query($add); 
    
    Code (markup):
    This code inserts the variable names into the fields, instead of the variable data

    This is what I use for the variables:

    $var = $_POST['name'];
    Code (markup):
    I have a form set up properly on another page
     
    Crayz, Aug 20, 2006 IP
  2. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Your add variable is set by using a string with single quotes. Essentially, variables are not interpreted in strings defined with single quotes. Change your line to either:
    $add = 'INSERT INTO `ibtn_sites` (url, username, pass, illcount, status, name, email) VALUES (\'' . $surl . '\', \'' . $username. '\', \'' . $password . '\', \'0\', \'0\', \'' . $sname . '\', \'' . $email . '\');';

    or:
    $add = "INSERT INTO `ibtn_sites` (url, username, pass, illcount, status, name, email) VALUES ('$surl', '$username', '$password', '0', '0', '$sname', '$email');";

    A quick note, too: if those zeros are meant to be numbers (as opposed to strings), you shouldn't put quotes around them. MySQL will accept it when not in strict mode, but I promise you you will have troubles with it later on.
     
    TwistMyArm, Aug 20, 2006 IP
  3. Crayz

    Crayz Well-Known Member

    Messages:
    708
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    120
    #3
    Oh, I see. Thanks!
     
    Crayz, Aug 20, 2006 IP