help please!

Discussion in 'MySQL' started by alsenor, Aug 16, 2006.

  1. #1
    I am trying to make my first insertion into mySQL, and keep getting an error msg.

    Here is what I write:

    INSERT my_members
    { values (firstname, lastname, email)}

    and this is the msg:
    Parse error: parse error, unexpected T_STRING in /home/alsenor/public_html/current/welcome.php on line 43

    Does the type of error give me a clue to what is wrong?
     
    alsenor, Aug 16, 2006 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It would if you showed us line 43 of your script (and surrounding).

    Your INSERT query looks wrong as well though.
     
    T0PS3O, Aug 16, 2006 IP
  3. alsenor

    alsenor Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It is the INSERT line which is line 43.
    I took the text right out of Kevin's book!
     
    alsenor, Aug 16, 2006 IP
  4. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #4
    We still need to see full and surrounding code.

    Would also be handy to know which language you are coding in.
     
    T0PS3O, Aug 16, 2006 IP
  5. ThomasNederman

    ThomasNederman Peon

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    $link = mysql_connect(HOST, USER, PASS) or die('Could not connect: ' . mysql_error());
    mysql_select_db(DB) or die('Could not select database');
    $Q = "INSERT my_members values ('".$_GET['username']."', '".$_GET['lastname']."','".$_GET['email']."');";
    $Result = mysql_query($Q) or die("ERROR:" . mysql_error());

    Should work better, maybe adapt it a bit
     
    ThomasNederman, Aug 16, 2006 IP
  6. alsenor

    alsenor Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Sorry, I wasn't sure about how much I should put in here!
    The language is supposed to be SQL I thought. :confused:

    <?php

    require_once('DB.php');
    $db_user = 'alsenor';
    $db_pword= 'myPWord';
    $db_name = 'bs_db';
    $db_engine = 'mysql';
    $db_host = 'localhost';

    $datasource= $db_engine .'://'.$db_user.':'.$db_pword.'@'.$db_host.'/'.$db_name;
    $db =& DB::connect($datasource);
    if(DB::isError($db)) {
    echo "db_connect error";
    die($db->getDebugInfo());

    $firstname = $_REQUEST['firstname'];
    $lastname = $_REQUEST['lastname'];
    $email= $_REQUEST['email'];
    $screenname = $_REQUEST['screenname'];
    $login_name = $_REQUEST['loginname'];
    $password = $_REQUEST['password'];
    $secret = $_REQUEST['secretquestion'];
    $answer = $_REQUEST['secretanswer'];


    INSERT bs_members
    { VALUES (firstname, lastname, email)
    INSERT bs_accounts
    values ($screenname, $loginname, $password, $secretquestion, $secretanswer);}
    ?>
     
    alsenor, Aug 16, 2006 IP
  7. ThomasNederman

    ThomasNederman Peon

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    <?php

    require_once('DB.php');
    $db_user = 'alsenor';
    $db_pword= 'myPWord';
    $db_name = 'bs_db';
    $db_engine = 'mysql';
    $db_host = 'localhost';

    $firstname = $_REQUEST['firstname'];
    $lastname = $_REQUEST['lastname'];
    $email= $_REQUEST['email'];
    $screenname = $_REQUEST['screenname'];
    $login_name = $_REQUEST['loginname'];
    $password = $_REQUEST['password'];
    $secret = $_REQUEST['secretquestion'];
    $answer = $_REQUEST['secretanswer'];



    $link = mysql_connect(HOST, USER, PASS) or die('Could not connect: ' . mysql_error());
    mysql_select_db(DB) or die('Could not select database');

    $Q = "insert into bs_members values ('".$firstname."', '".$lastname ."','".$email."');";

    $Result = mysql_query($Q) or die("ERROR:" . mysql_error());

    $Q = "INSERT into bs_accounts values ('".$screenname."','".$loginname.",".$password.",".$secretquestion.",". $secretanswer.");";

    $Result = mysql_query($Q) or die("ERROR:" . mysql_error());
     
    ThomasNederman, Aug 16, 2006 IP
  8. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #8
    
    $sql="INSERT INTO bs_members (firstname, lastname, email, screenname, login_name, password, secret, answer) VALUES($firstname, $lastname, $email, $screenname, $login_name, $password, $secret, $answer)";
    mysql_query($sql);
    
    PHP:
    Not exactly sure what you are trying to insert? But if that what the fields in bs_member are called then it should work.
     
    smatts9, Aug 16, 2006 IP
  9. alsenor

    alsenor Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I suppose I have to replace this: (HOST, USER, PASS) with (localhost, alsenor, my_p/w)? Then it should work?
     
    alsenor, Aug 16, 2006 IP
  10. ThomasNederman

    ThomasNederman Peon

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Yes, that is correct, sorry, forgot that !

    Correct line is

    $link = mysql_connect($db_host, $db_user, $db_pword) or die('Could not connect: ' . mysql_error());
     
    ThomasNederman, Aug 17, 2006 IP
  11. alsenor

    alsenor Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Like this (plus my password in single quotes)?:
    $link = mysql_connect(localhost, 'alsenor', $db_pword) or die('Could not connect: ' . mysql_error());
     
    alsenor, Aug 17, 2006 IP
  12. alsenor

    alsenor Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I have made connection to the DB, but still keep getting the same "parse error, unexpected T_STRING" for this line:
    INSERT bs_members
    { SET firstname=$firstname, lastname=$lastname, email-$email) }

    This line is taken right out of Kevin Yank's book, where it says:
    INSERT tbl_name
    { SET column_name=expression, column_name=expression ...}

    Why, oh why, does it not work?
     
    alsenor, Aug 17, 2006 IP