Jump to content

Recommended Posts

Ok I am using a book called The Joy of Php, but it the sample code is missing from its website, so I am rewriting it.

 

Anyway I have run into a parsing error, but my code is a spot match for the book code. Can someone help me?

 

the error is :

Parse error: syntax error, unexpected 'Error' (T_STRING), expecting ',' or ';' in C:\wamp\www\submitcar.php on line 46

 

 

The code snippet is:

/*try to insert the new car into the db */
if ($result=$mysqli->query($query)) {
echo "<p> you have successfully entered $Make $model into the db.</P>
}
else
{
echo "Error entering $VIN into db:" . mysql_error()."<br>";
}
$mysqli->close();

Please help...I have no idea where my error is. I have the gosh darn semicolon after <br>!

 

Link to comment
https://forums.phpfreaks.com/topic/288617-newbie-parsing-error/
Share on other sites

Take a look at the code in your post. See all that green? Green stuff is supposed to be a string but it's clearly showing some stuff as strings when it shouldn't (and vice versa). Find the place where it starts coloring incorrectly and you'll find where the problem is.

 

Oh, and get yourself an IDE. Like Netbeans or PhpStorm. They can tell you exactly where and what problems are in your code, and offer many other features beyond that.

Edited by requinix

Hey all - 

 

I can't edit the original OM, but I managed to fix that error. I was missing a "  and a ; in line 44. 

 

But now I get more error messages that are clearly above my pay grade. So I am making the entire code I have available.  Please help me.

<html>
<head>
<title>Car Saved</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">

<?php
//capture  values posted to this php program from the text fields in teh form

$VIN=mysql_real_escape_string($_POST['VIN']);
$Make=mysql_real_escape_string($_POST['Make']);
$Model=mysql_real_escape_string($_POST['Model']);

//Build a SQL Query using the values from above

$query ="INSERT INTO Inventory
(VIN, Make, Model)
VALUES(
'$VIN',
'$Make',
'$Model'
)";

//Print the queryto the browser so you can see it
echo ($query. "<br>");

$mysqli = new mysqli('localhost', 'root', NULL, 'db_name');
/*check connection*/
if (mysqli_connect_error()) {
printf("Connect falied: %s\n", mysqli_connect_error());
exit();
}

echo 'Connected successfully to mySQL <BR>';

//select db to work with
$mysqli->select_db("cars");
echo ("Selected the cars database. <br>");

/*try to insert the new car into the db */
if ($result=$mysqli->query($query)) {
echo "<p> you have successfully entered $Make $model into the db.</P>";
}
else
{
echo "Error entering $VIN into db:" . mysql_error()."<br>";
}
$mysqli->close();
?>

</body>
</html>

I follow the code. I still can't get it to run. Very frustrating...!!!

 

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.