Matthew Herren Posted October 9, 2009 Share Posted October 9, 2009 Ok as some of you may know I'm new to php and might be anoying some of you. I'm not trying to, but here's my new problem. After my form is submitted and all the values are posted with $_POST, I'm trying to print out what the user had just submitted with the form, but whe i use: $sql = "SELECT `ID`,`name`,`last`,`mi`,`hp`,`cp`,`work`,`email`,`add`,`add2`,`city`,`state`,`zip`,`password` FROM `dtherren`.`auto`"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf("Last inserted record has id %d\n", mysql_insert_id('last')); } mysql_free_result($result); $res=mysql_query($sql)or die(mysql_error()); ?> I get the error : Parse error: syntax error, unexpected T_STRING in /scripts/submit.php on line 58 This is my submit.php coding: <?php include '/home/content/d/h/e/dherren/html/scripts/config.php'; include '/home/content/d/h/e/dherren/html/scripts/opendb.php'; include '/home/content/d/h/e/dherren/html/scripts/values.php'; $sql="INSERT INTO`dtherren`.`auto`( `name`, `last`, `mi`, `add`, `add2`, `city`, `state`, `zip`, `email`, `hp`, `cp`, `work`, `password`, `make`, `model`, `color`, `plate`, `make2`, `model2`, `color2`, `plate2`, `make3`, `model3`, `color3`, `plate3` ) VALUES ( '{$name}' '{$last}' '{$mi}' '{$add}' '{$add2}' '{$city}' '{$state}' '{$zip}' '{$email}' '{$hp}' '{$cp}' '{$work}' '{$password}' '{$make}' '{$model}' '{$color}' '($plate)' '{$make2}' '{$model2}' '{$color2}' '($plate2)' '{$make3}' '{$model3}' '{$color3}' '($plate3)' ); $sql = "SELECT `ID`,`name`,`last`,`mi`,`hp`,`cp`,`work`,`email`,`add`,`add2`,`city`,`state`,`zip`,`password` FROM `dtherren`.`auto`"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf("Last inserted record has id %d\n", mysql_insert_id('last')); } mysql_free_result($result); $res=mysql_query($sql)or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/ Share on other sites More sharing options...
johnsmith153 Posted October 9, 2009 Share Posted October 9, 2009 What is the line of code at line 58? Just show me this. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933455 Share on other sites More sharing options...
Matthew Herren Posted October 9, 2009 Author Share Posted October 9, 2009 Ok it's line 59 now but it's still the same line. while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf("Last inserted record has id %d\n", mysql_insert_id('last')); } Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933457 Share on other sites More sharing options...
johnsmith153 Posted October 9, 2009 Share Posted October 9, 2009 mysql_insert_id('last') is wrong it should either be: (1) mysql_insert_id() which will use your latest active mysql connection, or (2) mysql_insert_id($connection) to use $connection as your connection Try mysql_insert_id() - just remove the 'last' bit. Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933462 Share on other sites More sharing options...
Matthew Herren Posted October 9, 2009 Author Share Posted October 9, 2009 LINE 59 ==>$sql = "SELECT ID,name,last,mi,add,add2,city,state,zip,email,hp,cp,work,password,make,model,color,plate,make2,model2,color2,plate2,make3,model3,color3,plate3 FROM `dtherren`.`auto`"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf("Last inserted record has id %d\n", mysql_insert_id()); } mysql_free_result($result); $res=mysql_query($sql)or die(mysql_error()); ?> Ok well i counted and thats line 59 Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933475 Share on other sites More sharing options...
Philip Posted October 9, 2009 Share Posted October 9, 2009 You're missing a closing " on your sql statement: $sql="INSERT INTO`dtherren`.`auto`( `name`, `last`, `mi`, `add`, `add2`, `city`, `state`, `zip`, `email`, `hp`, `cp`, `work`, `password`, `make`, `model`, `color`, `plate`, `make2`, `model2`, `color2`, `plate2`, `make3`, `model3`, `color3`, `plate3` ) VALUES ( '{$name}' '{$last}' '{$mi}' '{$add}' '{$add2}' '{$city}' '{$state}' '{$zip}' '{$email}' '{$hp}' '{$cp}' '{$work}' '{$password}' '{$make}' '{$model}' '{$color}' '($plate)' '{$make2}' '{$model2}' '{$color2}' '($plate2)' '{$make3}' '{$model3}' '{$color3}' '($plate3)' ); // The line above $sql = "SELECT `ID`,`name`,`last`,`mi`,`hp`,`cp`,`work`,`email`,`add`,`add2`,`city`,`state`,`zip`,`password`... Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933477 Share on other sites More sharing options...
johnsmith153 Posted October 9, 2009 Share Posted October 9, 2009 LINE 59 ==>$sql = "SELECT ID,name,last,mi,add,add2,city,state,zip,email,hp,cp,work,password,make,model,color,plate,make2,model2,color2,plate2,make3,model3,color3,plate3 FROM `dtherren`.`auto`"; Also, use ` characters around some field names as mySQL doesn't like it. `name` especially will need it. To be safe wrap it around all of them (e.g. `fieldname` ) I noticed your first code did have these ` characters on, but not in your last post. Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933486 Share on other sites More sharing options...
Matthew Herren Posted October 9, 2009 Author Share Posted October 9, 2009 Well now I'm getting this error on my values.php page. Parse error: syntax error, unexpected ';' in /html/scripts/values.php on line 28 <?php $name = mysql_real_escape_string($_POST['name']); $last = mysql_real_escape_string($_POST['last']); $mi = mysql_real_escape_string($_POST['mi']); $add = mysql_real_escape_string($_POST['add']); $add2 = mysql_real_escape_string($_POST['add2']); $city = mysql_real_escape_string($_POST['city']); $state = mysql_real_escape_string($_POST['state']); $zip = mysql_real_escape_string($_POST['zip']); $email = mysql_real_escape_string($_POST['email']); $hp = mysql_real_escape_string($_POST['hp']); $cp = mysql_real_escape_string($_POST['cp']); $work = mysql_real_escape_string($_POST['work']); $make = mysql_real_escape_string($_POST['make']); $model = mysql_real_escape_string($_POST['model']); $color = mysql_real_escape_string($_POST['color']); $plate = mysql_real_escape_string($_POST['plate']); $make2 = mysql_real_escape_string($_POST['make2']); $model2 = mysql_real_escape_string($_POST['model2']); $color2 = mysql_real_escape_string($_POST['color2']); $plate2 = mysql_real_escape_string($_POST['plate2']); $make3 = mysql_real_escape_string($_POST['make3']); $model3 = mysql_real_escape_string($_POST['model3']); $color3 = mysql_real_escape_string($_POST['color3']); $plate3 = mysql_real_escape_string($_POST['plate3']); $password = msql_real_escape_string($_POST['password'] ?><== Line 28 Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933492 Share on other sites More sharing options...
whaleyb Posted October 9, 2009 Share Posted October 9, 2009 Change this line: $password = msql_real_escape_string($_POST['password'] to this: $password = msql_real_escape_string($_POST['password']); Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933494 Share on other sites More sharing options...
johnsmith153 Posted October 9, 2009 Share Posted October 9, 2009 and after that, in the same line: $password = msql_real_escape_string($_POST['password']); change it to: $password = mysql_real_escape_string($_POST['password']); (missing y in mysql) Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933495 Share on other sites More sharing options...
whaleyb Posted October 9, 2009 Share Posted October 9, 2009 I didnt even see that, nice catch John. Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933498 Share on other sites More sharing options...
Matthew Herren Posted October 9, 2009 Author Share Posted October 9, 2009 Thanks Guys. Now I'm Getting a new error. Fatal error: SQL in /scripts/submit.php on line 61 <?php include '/home/content/d/h/e/dherren/html/scripts/config.php'; include '/home/content/d/h/e/dherren/html/scripts/opendb.php'; include '/home/content/d/h/e/dherren/html/scripts/values.php'; $sql="INSERT INTO`dtherren`.`auto`( `name`, `last`, `mi`, `add`, `add2`, `city`, `state`, `zip`, `email`, `hp`, `cp`, `work`, `password`, `make`, `model`, `color`, `plate`, `make2`, `model2`, `color2`, `plate2`, `make3`, `model3`, `color3`, `plate3` ) VALUES ( '{$name}' '{$last}' '{$mi}' '{$add}' '{$add2}' '{$city}' '{$state}' '{$zip}' '{$email}' '{$hp}' '{$cp}' '{$work}' '{$password}' '{$make}' '{$model}' '{$color}' '($plate)' '{$make2}' '{$model2}' '{$color2}' '($plate2)' '{$make3}' '{$model3}' '{$color3}' '($plate3)' )"; $sql = "SELECT `ID`,`name`,`last`,`mi`,`add`,`add2`,`city`,`state`,`zip`,`email`,`hp`,`cp`,`work`,`password`,`make`,`model`,`color`,``plate`,`make2`,`model2`,`color2`,`plate2`,`make3`,`model3`,`color3`,`plate3` FROM `dtherren`.`auto`"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf( mysql_insert_id()); } mysql_free_result($result); $res=mysql_query($sql)or die(mysql_error()); ?> Line 61: `plate`,`make2`,`model2`,`color2`,`plate2`,`make3`,`model3`,`color3`,`plate3` if i add " after `plate3`" i get a new error Parse error: syntax error, unexpected T_STRING in /scripts/submit.php on line 60 `ID`,`name`,`last`,`mi`,`add`,`add2`,`city`,`state`,`zip`,`email`,`hp`,`cp`,`work`,`password`,`make`,`model`,`color`,` Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933501 Share on other sites More sharing options...
Philip Posted October 9, 2009 Share Posted October 9, 2009 ...`color`,``plate`,`make2`,... Notice something wrong with the backticks? Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933504 Share on other sites More sharing options...
Matthew Herren Posted October 9, 2009 Author Share Posted October 9, 2009 now i'm getting Parse error: syntax error, unexpected T_STRING on line 60. Once again thanks to everyone who has helped me. Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933809 Share on other sites More sharing options...
Philip Posted October 9, 2009 Share Posted October 9, 2009 Okay, removing one of the ` from the SQL query would not have caused a PHP error. When you have an unexpected string, it almost always means you're missing a " or a '. Now, if you would have posted the MySQL error instead of just "SQL" in your trigger error, you'd have seen the problem. <?php include '/home/content/d/h/e/dherren/html/scripts/config.php'; include '/home/content/d/h/e/dherren/html/scripts/opendb.php'; include '/home/content/d/h/e/dherren/html/scripts/values.php'; $sql="INSERT INTO`dtherren`.`auto`( `name`, `last`, `mi`, `add`, `add2`, `city`, `state`, `zip`, `email`, `hp`, `cp`, `work`, `password`, `make`, `model`, `color`, `plate`, `make2`, `model2`, `color2`, `plate2`, `make3`, `model3`, `color3`, `plate3` ) VALUES ( '{$name}' '{$last}' '{$mi}' '{$add}' '{$add2}' '{$city}' '{$state}' '{$zip}' '{$email}' '{$hp}' '{$cp}' '{$work}' '{$password}' '{$make}' '{$model}' '{$color}' '($plate)' '{$make2}' '{$model2}' '{$color2}' '($plate2)' '{$make3}' '{$model3}' '{$color3}' '($plate3)' )"; $sql = "SELECT `ID`,`name`,`last`,`mi`,`add`,`add2`,`city`,`state`,`zip`,`email`,`hp`,`cp`,`work`,`password`,`make`,`model`,`color`,`plate`,`make2`,`model2`,`color2`,`plate2`,`make3`,`model3`,`color3`,`plate3` FROM `dtherren`.`auto`"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf( mysql_insert_id()); } mysql_free_result($result); $res=mysql_query($sql)or die(mysql_error()); ?> Also, I will note that using ` around the column names will tie your code to mysql. It is best to not use them, and name your columns words that are not reserved keywords. Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933839 Share on other sites More sharing options...
Matthew Herren Posted October 9, 2009 Author Share Posted October 9, 2009 Maybe I'm tired and i'm over looking something but i'm getting fatal erro SQL on line 61 now. Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-933957 Share on other sites More sharing options...
Matthew Herren Posted October 9, 2009 Author Share Posted October 9, 2009 $sql = "SELECT `ID`,`name`,`last`,`mi`,`add`,`add2`,`city`,`state`,`zip`,`email`,`hp`,`cp`,`work`,`password`,`make`,`model`,`color`, `plate`,`make2`,`model2`,`color2`,`plate2`,`make3`,`model3`,`color3`,`plate3` <--- line 61 $sql = "SELECT `ID`,`name`,`last`,`mi`,`add`,`add2`,`city`,`state`,`zip`,`email`,`hp`,`cp`,`work`,`password`,`make`,`model`,`color`,`plate`,`make2`,`model2`,`color2`,`plate2`,`make3`,`model3`,`color3`,`plate3` FROM `dtherren`.`auto`"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf( mysql_insert_id()); } mysql_free_result($result); $res=mysql_query($sql)or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-934003 Share on other sites More sharing options...
MadTechie Posted October 9, 2009 Share Posted October 9, 2009 can you post the full code Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-934021 Share on other sites More sharing options...
waynew Posted October 9, 2009 Share Posted October 9, 2009 Post the entire file. Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-934023 Share on other sites More sharing options...
Matthew Herren Posted October 9, 2009 Author Share Posted October 9, 2009 <?php include '/home/content/d/h/e/dherren/html/scripts/config.php'; include '/home/content/d/h/e/dherren/html/scripts/opendb.php'; include '/home/content/d/h/e/dherren/html/scripts/values.php'; $sql="INSERT INTO`dtherren`.`auto`( `name`, `last`, `mi`, `add`, `add2`, `city`, `state`, `zip`, `email`, `hp`, `cp`, `work`, `password`, `make`, `model`, `color`, `plate`, `make2`, `model2`, `color2`, `plate2`, `make3`, `model3`, `color3`, `plate3` ) VALUES ( '{$name}' '{$last}' '{$mi}' '{$add}' '{$add2}' '{$city}' '{$state}' '{$zip}' '{$email}' '{$hp}' '{$cp}' '{$work}' '{$password}' '{$make}' '{$model}' '{$color}' '($plate)' '{$make2}' '{$model2}' '{$color2}' '($plate2)' '{$make3}' '{$model3}' '{$color3}' '($plate3)' )"; $sql = "SELECT `ID`,`name`,`last`,`mi`,`add`,`add2`,`city`,`state`,`zip`,`email`,`hp`,`cp`,`work`,`password`,`make`,`model`,`color`,`plate`,`make2`,`model2`,`color2`,`plate2`,`make3`,`model3`,`color3`,`plate3` FROM `dtherren`.`auto`"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf( mysql_insert_id()); } mysql_free_result($result); $res=mysql_query($sql)or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-934038 Share on other sites More sharing options...
MadTechie Posted October 9, 2009 Share Posted October 9, 2009 add some , in your values ie $sql="INSERT INTO`dtherren`.`auto`(`name`,`last`,`mi`,`add`,`add2`,`city`,`state`,`zip`,`email`,`hp`,`cp`,`work`,`password`,`make`,`model`,`color`,`plate`,`make2`,`model2`,`color2`,`plate2`,`make3`,`model3`,`color3`,`plate3`) VALUES ('{$name}','{$last}','{$mi}','{$add}','{$add2}','{$city}','{$state}','{$zip}','{$email}','{$hp}','{$cp}','{$work}','{$password}','{$make}','{$model}','{$color}','($plate)','{$make2}','{$model2}','{$color2}','($plate2)','{$make3}','{$model3}','{$color3}','($plate3)')"; EDIT: infact your overwriting that $sql.. so it will have no effect! Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-934040 Share on other sites More sharing options...
Matthew Herren Posted October 9, 2009 Author Share Posted October 9, 2009 I'm still getting errors so I removed the $sql = "SELECT `ID`,`name`,`last`,`mi`,`add`,`add2`,`city`,`state`,`zip`,`email`,`hp`,`cp`,`work`,`password`,`make`,`model`,`color`,`plate`,`make2`,`model2`,`color2`,`plate2`,`make3`,`model3`,`color3`,`plate3` FROM `dtherren`.`auto`"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf( mysql_insert_id()); } mysql_free_result($result); It's posting now. I'm giving up on printf it on the screen the the user can see it and edit it for now. Thanks for all you're help. Quote Link to comment https://forums.phpfreaks.com/topic/177042-solved-unexpected-t_string/#findComment-934057 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.