Jump to content

[SOLVED] unexpected T_STRING


Matthew Herren

Recommended Posts

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());
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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`... 

Link to comment
Share on other sites

 

 

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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`,`

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

$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());
?>

Link to comment
Share on other sites

<?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());
?>

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.