pyke96 Posted February 6, 2008 Share Posted February 6, 2008 if ($connection) $query = "INSERT INTO patients (patient_first_name, patient_last_name, patient_user_name, patient_pass_word, patient_address, patient_county, patient_country) VALUES ($_SESSION['firstname'], $_SESSION['lastname'], $_SESSION['username'], $_SESSION['password'], $_SESSION['address'], $_SESSION['county'], $_SESSION['country'])"; $result = mysql_query($query); echo "New record added to the database"; else echo "connection failed"; This is the snippit of code I was using to add a record to a mysql database. this is the error i got: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\webs\test\add_pat.php on line 15 Could someone help with this?? Quote Link to comment https://forums.phpfreaks.com/topic/89713-solved-php-and-databases/ Share on other sites More sharing options...
haku Posted February 6, 2008 Share Posted February 6, 2008 Use [code ] tags for your code please. As to your problem, can you post lines 10-15? Rarely is the problem ever on the line it actually says. Quote Link to comment https://forums.phpfreaks.com/topic/89713-solved-php-and-databases/#findComment-459705 Share on other sites More sharing options...
trq Posted February 6, 2008 Share Posted February 6, 2008 As and sql query thats never going to work either (its not the cause of your error, but it will be another). All text values need to be surrounded by quotes within sql. Quote Link to comment https://forums.phpfreaks.com/topic/89713-solved-php-and-databases/#findComment-459708 Share on other sites More sharing options...
pyke96 Posted February 6, 2008 Author Share Posted February 6, 2008 <?php $_SESSION['firstname'] = $_POST['firstname']; $_SESSION['lastname'] = $_POST['lastname']; $_SESSION['username'] = $_POST['user']; $_SESSION['password'] = $_POST['pass']; $_SESSION['address'] = $_POST['address']; $_SESSION['county'] = $_POST['county']; $_SESSION['country'] = $_POST['country']; $connection = mysql_connect('157.190.116.250','sheehanl','R00010258') or die(mysql_error()); if ($connection) $query = "INSERT INTO patients (patient_first_name, patient_last_name, patient_user_name, patient_pass_word, patient_address, patient_county, patient_country) VALUES ($_SESSION['firstname'], $_SESSION['lastname'], $_SESSION['username'], $_SESSION['password'], $_SESSION['address'], $_SESSION['county'], $_SESSION['country'])"; $result = mysql_query($query); echo "New record added to the database"; else echo "connection failed"; $db = mysql_select_db("sheehanldb") or die(mysql_errror()); echo "<p>Database selected</p>"; This is all of the code used. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/89713-solved-php-and-databases/#findComment-459711 Share on other sites More sharing options...
aschk Posted February 6, 2008 Share Posted February 6, 2008 Looks like you've come from a background of programming VB... where are your parenthesis? <?php $_SESSION['firstname'] = $_POST['firstname']; $_SESSION['lastname'] = $_POST['lastname']; $_SESSION['username'] = $_POST['user']; $_SESSION['password'] = $_POST['pass']; $_SESSION['address'] = $_POST['address']; $_SESSION['county'] = $_POST['county']; $_SESSION['country'] = $_POST['country']; $connection = mysql_connect('157.190.116.250','sheehanl','R00010258') or die(mysql_error()); if ($connection) [color=red]{[/color] $query = "INSERT INTO patients (patient_first_name, patient_last_name, patient_user_name, patient_pass_word, patient_address, patient_county, patient_country) VALUES ($_SESSION['firstname'], $_SESSION['lastname'], $_SESSION['username'], $_SESSION['password'], $_SESSION['address'], $_SESSION['county'], $_SESSION['country'])"; $result = mysql_query($query); echo "New record added to the database"; [color=red]}[/color] else [color=yellow]{[/color] echo "connection failed"; [color=red]}[/color] $db = mysql_select_db("sheehanldb") or die(mysql_errror()); echo "<p>Database selected</p>"; Quote Link to comment https://forums.phpfreaks.com/topic/89713-solved-php-and-databases/#findComment-459715 Share on other sites More sharing options...
haku Posted February 6, 2008 Share Posted February 6, 2008 Did you miss the part where I asked you to put your code in tags? there is no way to count the lines if you don't because of autowrap. Quote Link to comment https://forums.phpfreaks.com/topic/89713-solved-php-and-databases/#findComment-459716 Share on other sites More sharing options...
sasa Posted February 6, 2008 Share Posted February 6, 2008 try <?php $_SESSION['firstname'] = $_POST['firstname']; $_SESSION['lastname'] = $_POST['lastname']; $_SESSION['username'] = $_POST['user']; $_SESSION['password'] = $_POST['pass']; $_SESSION['address'] = $_POST['address']; $_SESSION['county'] = $_POST['county']; $_SESSION['country'] = $_POST['country']; $connection = mysql_connect('157.190.116.250','sheehanl','R00010258') or die(mysql_error()); if ($connection){ $query = "INSERT INTO patients (patient_first_name, patient_last_name, patient_user_name, patient_pass_word, patient_address, patient_county, patient_country) VALUES ('".$_SESSION['firstname']."', '".$_SESSION['lastname']."', '".$_SESSION['username']."', '".$_SESSION['password']."', '".$_SESSION['address']."', '".$_SESSION['county']."', '".$_SESSION['country']."'"; $result = mysql_query($query); echo "New record added to the database";} else echo "connection failed"; $db = mysql_select_db("sheehanldb") or die(mysql_errror()); echo "<p>Database selected</p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/89713-solved-php-and-databases/#findComment-459719 Share on other sites More sharing options...
pyke96 Posted February 6, 2008 Author Share Posted February 6, 2008 try <?php $_SESSION['firstname'] = $_POST['firstname']; $_SESSION['lastname'] = $_POST['lastname']; $_SESSION['username'] = $_POST['user']; $_SESSION['password'] = $_POST['pass']; $_SESSION['address'] = $_POST['address']; $_SESSION['county'] = $_POST['county']; $_SESSION['country'] = $_POST['country']; $connection = mysql_connect('157.190.116.250','sheehanl','R00010258') or die(mysql_error()); if ($connection){ $query = "INSERT INTO patients (patient_first_name, patient_last_name, patient_user_name, patient_pass_word, patient_address, patient_county, patient_country) VALUES ('".$_SESSION['firstname']."', '".$_SESSION['lastname']."', '".$_SESSION['username']."', '".$_SESSION['password']."', '".$_SESSION['address']."', '".$_SESSION['county']."', '".$_SESSION['country']."'"; $result = mysql_query($query); echo "New record added to the database";} else echo "connection failed"; $db = mysql_select_db("sheehanldb") or die(mysql_errror()); echo "<p>Database selected</p>"; ?> Thats after working for us except this is the page returned: Notice: Undefined index: address in c:\webs\test\add_pat1.php on line 9 New record added to the database Database selected Quote Link to comment https://forums.phpfreaks.com/topic/89713-solved-php-and-databases/#findComment-459722 Share on other sites More sharing options...
craygo Posted February 6, 2008 Share Posted February 6, 2008 You forgot a ")" at the end of your values and you should put in some error checking until your code is at least debugged. <?php $_SESSION['firstname'] = $_POST['firstname']; $_SESSION['lastname'] = $_POST['lastname']; $_SESSION['username'] = $_POST['user']; $_SESSION['password'] = $_POST['pass']; $_SESSION['address'] = $_POST['address']; $_SESSION['county'] = $_POST['county']; $_SESSION['country'] = $_POST['country']; $connection = mysql_connect('157.190.116.250','sheehanl','R00010258') or die(mysql_error()); if ($connection){ $query = "INSERT INTO patients (patient_first_name, patient_last_name, patient_user_name, patient_pass_word, patient_address, patient_county, patient_country) VALUES ('".$_SESSION['firstname']."', '".$_SESSION['lastname']."', '".$_SESSION['username']."', '".$_SESSION['password']."', '".$_SESSION['address']."', '".$_SESSION['county']."', '".$_SESSION['country']."')"; $result = mysql_query($query); if($result){ echo "New record added to the database"; } else { echo "Could not Insert record: Sql error ".mysql_error(); } } else { echo "connection failed"; } $db = mysql_select_db("sheehanldb") or die(mysql_errror()); echo "<p>Database selected</p>"; ?> Ray Quote Link to comment https://forums.phpfreaks.com/topic/89713-solved-php-and-databases/#findComment-459737 Share on other sites More sharing options...
aschk Posted February 6, 2008 Share Posted February 6, 2008 LOL, i see what's going on. You need to do things in the following order: 1) Connect to mysql 2) Select database 3) Insert record Currently you're doing 3 before 2... Quote Link to comment https://forums.phpfreaks.com/topic/89713-solved-php-and-databases/#findComment-459740 Share on other sites More sharing options...
eamonn.walsh Posted February 6, 2008 Share Posted February 6, 2008 Stephen, I hardly feel using these types of methods is in keeping with the spirit of the project. Please remember that part of this task is the signing of an anti-plagiarism document. -Eamonn. Quote Link to comment https://forums.phpfreaks.com/topic/89713-solved-php-and-databases/#findComment-459780 Share on other sites More sharing options...
haku Posted February 6, 2008 Share Posted February 6, 2008 I have no idea who you are, or what the reference you make is to, but getting assistance from someone can hardly be considered plagiarism. Quote Link to comment https://forums.phpfreaks.com/topic/89713-solved-php-and-databases/#findComment-459785 Share on other sites More sharing options...
Aureole Posted February 6, 2008 Share Posted February 6, 2008 Stephen, I hardly feel using these types of methods is in keeping with the spirit of the project. Please remember that part of this task is the signing of an anti-plagiarism document. -Eamonn. Wait, what the? Did you reply to the wrong topic or something. ??? Who are you talking to? Quote Link to comment https://forums.phpfreaks.com/topic/89713-solved-php-and-databases/#findComment-459802 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.