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?
It would if you showed us line 43 of your script (and surrounding). Your INSERT query looks wrong as well though.
We still need to see full and surrounding code. Would also be handy to know which language you are coding in.
$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
Sorry, I wasn't sure about how much I should put in here! The language is supposed to be SQL I thought. <?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);} ?>
<?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());
$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.
I suppose I have to replace this: (HOST, USER, PASS) with (localhost, alsenor, my_p/w)? Then it should work?
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());
Like this (plus my password in single quotes)?: $link = mysql_connect(localhost, 'alsenor', $db_pword) or die('Could not connect: ' . mysql_error());
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?