Markus1954 Posted December 17, 2021 Share Posted December 17, 2021 Hi All; I am stuck. I am getting an error in some code. First this is the error I am getting: Parse error: syntax error, unexpected token "echo" in C:\Apache24\htdocs\createdb.php on line 19 The code below is line 18 and 19. In the past I found that sometimes the line above the error is the problem. I don't see the problem and hope that someone can shed some light on where this problem is. If you want to see more code I will provide it. if($mysqli->query("CREATE DATABASE Cars")=== TRUE{ echo ("<p>DATABASE Cars created</p>"); Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/314326-reading-and-copying-from-the-book-the-joy-of-php/ Share on other sites More sharing options...
ginerjm Posted December 17, 2021 Share Posted December 17, 2021 (edited) Look at the parens. They are not matched. Also your Brace doesn't show and ending brace and you don't need parens for an echo statement. Does your host not offer you an administration tool such as cPanel to do this kind of work? Much easier than writing queries to do it. Edited December 17, 2021 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/314326-reading-and-copying-from-the-book-the-joy-of-php/#findComment-1592792 Share on other sites More sharing options...
Markus1954 Posted December 17, 2021 Author Share Posted December 17, 2021 The ending curly brace exists, I just didn't swipe it. In the book there are echo statements with both parentheses and no parentheses. I put the parentheses in this particular statement to see if it would work. In the book there are none.. I am learning from the book using apache, mysql and php 8 on my computer. I am not ready for hosting right now. When the time comes and I have a website ready I have an approach to do it on this computer. Quote Link to comment https://forums.phpfreaks.com/topic/314326-reading-and-copying-from-the-book-the-joy-of-php/#findComment-1592799 Share on other sites More sharing options...
gizmola Posted December 17, 2021 Share Posted December 17, 2021 Please use the code tag button in the future. I edited your post to add it for for your code snippet. It's the <> button. The condition in PHP must be inside parens. This is what ginerjm was telling you. Yours: if($mysqli->query("CREATE DATABASE Cars")=== TRUE{ echo ("<p>DATABASE Cars created</p>"); The logical operator '===' has the 2 things you are comparing. These must be enclosed in parens. if (logical evaluation) { //true code } ...etc. Should be: if ($mysqli->query("CREATE DATABASE Cars") === TRUE) { echo ("<p>DATABASE Cars created</p>"); Putting a space before/after logical evaluation constructs like if while etc., will help you see these types of mistakes easier. PHP removes the whitespace, so anything you do to make your code more readable is fine. Quote Link to comment https://forums.phpfreaks.com/topic/314326-reading-and-copying-from-the-book-the-joy-of-php/#findComment-1592820 Share on other sites More sharing options...
ginerjm Posted December 18, 2021 Share Posted December 18, 2021 I think OP was distracted by my pointing at the braces and neglected the other half of my post... Quote Link to comment https://forums.phpfreaks.com/topic/314326-reading-and-copying-from-the-book-the-joy-of-php/#findComment-1592829 Share on other sites More sharing options...
Markus1954 Posted December 18, 2021 Author Share Posted December 18, 2021 (edited) OK I put parentheses around the echo and it still did not work. Like I said above there are echo statements in the book that have () and some that are just echo "this is going to be printed"; Edited December 18, 2021 by Markus1954 forgot something Quote Link to comment https://forums.phpfreaks.com/topic/314326-reading-and-copying-from-the-book-the-joy-of-php/#findComment-1592831 Share on other sites More sharing options...
Markus1954 Posted December 18, 2021 Author Share Posted December 18, 2021 Will this work better ? $query = "INSERT NTO `Cars`.`inventory` (`VIN`, `YEAR`, `Make`, Model`, `TRIM`, `EXT_COLOR`, `INT_COLOR`, `ASKING_PRICE`, `SALE_PRICE`, `PURCHASE_PRICE`, `MILEAGE`, `TRANSMISSION`, `PURCHASE_DATE`, `SALE_DATE`) VALUES (`5FNYF4H91CB054036`, `2012`, `Honda`, `Pilot`, `Touring`, `White Diamond Pearl`, `Leather`, `37807`, NULL, `34250`, `7076`, `Automatic`, `2012-11-08`, NULL)"; if($mysqli->query($query) === TRUE { echo ("<p>Honda Pilot inserted</p>"); } else { echo "<p>Error inserting Honda Pilot:</p>".$mysqli->error; echo"<p>*********</p>"; echo $query; echo "<p>**********</p>"; } This is the complete section of code where the problem exists. Quote Link to comment https://forums.phpfreaks.com/topic/314326-reading-and-copying-from-the-book-the-joy-of-php/#findComment-1592832 Share on other sites More sharing options...
ginerjm Posted December 18, 2021 Share Posted December 18, 2021 (edited) I pointed this out earlier and it was mentioned by another poster here. The IF statement needs to be in parens and you are not doing that!!! If (something == something) { handle the true conditon } else { handle the false condition } That is how it is written. Edited December 18, 2021 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/314326-reading-and-copying-from-the-book-the-joy-of-php/#findComment-1592833 Share on other sites More sharing options...
gizmola Posted December 20, 2021 Share Posted December 20, 2021 On 12/18/2021 at 9:42 AM, Markus1954 said: OK I put parentheses around the echo and it still did not work. Like I said above there are echo statements in the book that have () and some that are just echo "this is going to be printed"; It could not have been made any clearer than it was in my reply to you. Take time to carefully read and study the replies, especially when people spend the time to give you code snippets and corrections. Quote Link to comment https://forums.phpfreaks.com/topic/314326-reading-and-copying-from-the-book-the-joy-of-php/#findComment-1592854 Share on other sites More sharing options...
Markus1954 Posted December 21, 2021 Author Share Posted December 21, 2021 I fixed the ) problem and it works 1 Quote Link to comment https://forums.phpfreaks.com/topic/314326-reading-and-copying-from-the-book-the-joy-of-php/#findComment-1592891 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.