Syntax error in PHP

I have a form and PHP code on one page. It shows the form, submits the data and the DB opens. At that point it tries to send the data to the table, and I get a syntax error.

The error is:

Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\SCW_Files\formnewbowl.php on line 15

The code:
It includes the menu that called the form, the error is in red:
[php]<?php include("newmenu.php"); ?>

<?php $con = mysql_connect(“localhost”,”ididid”,”pwpwpwpw”); if (!$con) { echo '
'; echo 'Could not connect!'; } mysql_select_db("scw-db", $con); if(isset($_POST['submit'])){ $sql=INSERT INTO tblsplintersbowlinventory (txtProductBowlCode, txtSpeciesSeq) VALUES('$_POST[bowlcode]‘,‘$_POST[species]‘); if (!mysql_query($sql,$con)) { echo ‘
’; echo $_POST['bowlcode']; echo ” record failed!”; echo ‘Error: ‘ . mysql_error(); } else { echo ‘
’; echo $_POST['bowlcode']; echo ” record added”; } } mysql_close($con); ?>[/php]

Here is the form:

[code]





<div style=”color:blue; serif; text-decoration:underline;”>

Add bowl to database






BowlCode:


SpeciesYear:




[/code]

I am totally lost on why this is happening, any help would be appreciated.
I do see that the PHP above shows everything after line 15 in red, which does confirm it is syntax, but I can’t see what is wrong with it…pollen and new bifocals, not a good combination! ::slight_smile:

[php]VALUES(’$_POST[bowlcode]‘,‘$_POST[species]‘);[/php]

The quotes are different, meaning you never really end the string started at VALUES(’

The quotes are different, meaning you never really end the string started at VALUES('

Different…how? I see two pairs of single quotes…should I use double quotes?

And I’m not arguing with you, I really do not see what you are trying o tell me.

Can you show me the full correct configuration for the 3 lines?
[php]if(isset($_POST[‘submit’])){
$sql=INSERT INTO tblsplintersbowlinventory (txtProductBowlCode, txtSpeciesSeq)
VALUES(’$_POST[bowlcode]‘,‘$_POST[species]‘);[/php]

I’ve seen some examples that put almost all of this into quotes, without the $__POST…:
[php]$sql = 'INSERT INTO tblsplintersbowlinventory '.
'(txtProductBowlCode,txtSpeciesSeq) '.
‘VALUES ( “bowlcode”, “species” )’;[/php]
But THAT goes to another page with the error

File not found

Firefox can’t find the file at /C:/xampp/htdocs/SCW_FI~1/%E2%80%9D%E2%80%9D?%94bowlcode%94=Maple22-100&%94species%94=Maple22-100&submit=Submit+Query.


Which seems to use the data as part of the file name…

Like I said, I am really confused.

Thanks.

’ and ‘ are not the same quotes :wink:

' and ‘ are not the same quotes ;)

OK, I retyped the entire PHP:
[php]<?php include('bowlmenu.php'); ?>

<?php $con = mysql_connect('localhost'.'ididi','pwpwpw'); if (!$con) { echo '
'; echo 'Could not connect!'; } mysql_select_db('scw-db', $con); if(isset($_POST['submit'])) { $sql=INSERT INTO tblsplintersbowlinventory (txtProductBowlCode, txtSpeciesSeq) VALUES($bowlcode, $species); if (!mysql_query($sql,$con)) { echo '
'; echo $_POST['bowlcode']; echo ' record failed!'; echo 'Error: ' . mysql_error(); } else { echo '
'; echo $_POST['bowlcode']; echo ' record added'; } } [/php] which should eliminate any mis-coded chars introduced by cut & paste.... When I run it now, I get the following BEFORE the form:
'; echo 'Could not connect!'; } mysql_select_db("scw-db", $con); if(isset($_POST['submit'])) { $sql=INSERT INTO tblsplintersbowlinventory (txtProductBowlCode, txtSpeciesSeq) VALUES($bowlcode, $species); if (!mysql_query($sql,$con)) { echo ' '; echo $_POST['bowlcode']; echo ' record failed!'; echo 'Error: ' . mysql_error(); } else { echo ' '; echo $_POST['bowlcode']; echo ' record added'; } } mysql_close($con); ?>

Which suggests the problem is in the
[php]if (!$con)
{
echo ‘
’;
echo ‘Could not connect!’;
}[/php]

code, but I find the ‘;’ at the end of each line, and all of the (,{ or [ show a matching closing char.

I enter data into the form and hit submit, and it goes to a new page:

File not found

Firefox can’t find the file at /C:/xampp/htdocs/SCW_FI~1/%E2%80%9D%E2%80%9D?%94bowlcode%94=Maple22-102&%94species%94=Maple22-102&submit=Submit+Query.

Which seems to be using the data as part of the"filename", which makes no sense…

Sorry if I am being blind here…

The sql insert statement should be a string

On top of that you are using obsolete MySQL calls. You need to use Pdo or mysqli.

Got it!

The form seems to be functional, here’s the current code"

[php]<?php include('bowlmenu.php'); ?>

<?php $con = mysql_connect('localhost'.'idid','pwpwpw'); if (!$con) { die('Could not connect: ' . mysql_error()); } else { echo "connected to MySQL"; } if(isset($_POST['submit'])) { print_r($_POST); if(!mysql_select_db('scw-db', $con) { echo "did not connect"; } else { echo "connected": }; $sql="INSERT INTO tblsplintersbowlinventory (txtProductBowlCode, txtSpeciesSeq) VALUES('$_POST[bowlcode]', '$_POST[species)'"; if (mysql_query($sql,$con)) { echo "data inserted in db"; } else { echo "Error accessing database: "; }; mysql_close($con);} ?>[/php]

And the form:

[code]





<div style=”color:blue; serif; text-decoration:underline;”>

Add bowl to database






BowlCode:


SpeciesYear:




[/code]

This brings up the form. When I enter and then submit, it goes to a new page to load the DB.

And shows this error:

File not found

Firefox can’t find the file at /C:/xampp/htdocs/SCW_FI~1/%E2%80%9D%E2%80%9D?%94bowlcode%94=Maple22-102&%94species%94=Maple22-102&submit=Submit+Query.


I can access the DB through phpMyAdmin, and another form with separate php can access the DB as well.
I thought maybe running this so often had filled up a buffer, so I closed everything down and rebooted - it did the same error message.

[php][/php] where’s your action="" taking you? :o

No offense, if you’re willing to learn PHP why are you insisting in learning obsolete methods (mysql instead of mysqli or PDO)? An I have heard the excuse “I’ll change it over once I get the script working”. 99.9 percent of the time that never happens, for either one you become frustrated and give up or you get it working and move on to something else and make another excuse “I will learn the proper way when I have time”. When down the road you are going to have to change the code anyways. Not only that but the security you issues that you’re going to face when every script kiddie will be having a field day exploiting the security breaches. Not only that, but when the website(s) gets a bad reputation for having security flaws, people tend to stay away and start spreading the word.

No offense taken - i’d never heard of those before I started working on this problem.

And since I am basically familiar with PHP, and will be using this and the other scripts myself only, I’d rather get this working and consider something else only when the need to upgrade becomes clear.

All these are a simple database for my small wood-turning business - I make bowls and other art forms for sale in galleries and art fairs. I have been using the individual scripts over several years, writing the time and other stuff on paper in the shop and then coming up to the office to load the data in the PC. And sometimes I am too tired to record it “now”, so it get’s behind and over a week or so I keep putting it off until I spend a couple of hours trying to read my notes and enter the stuff in the db. Now I want to put them in a package so I can have the iPad in the shop and record my time and the progress of the turnings as I work on them - with the DB on the web so I can use wi-fi. I had hoped it would be a simple task, not quite at that point yet.

I will take a look at mysqi & PDO, see if it might be worth the time to convert. But right now I have 96 pieces of wood sitting on the table needing to become products by the end of May for a show in the middle of June. Then I need to photograph them, catalog and price them, and do the paperwork to add them to the boxes of work ready for sale.

So you can see why I am reluctant to learn another coding skill… ;D

I’m trying to get the result (verification or denial) of the insert to print on the same page as the form, with the entered data still in the form fields, so I can correct any errors right away. I do have a version that prints it on the menu, then I have to go back to the form to either re-enter it or enter a new one - a bit of a waste of time.

I was told the action="" was the way to do that. ::slight_smile:

you can actually leave out action="" as well :slight_smile: if no action is set, or it’s omitted, the form will submit to itself.

Thanks.

Sponsor our Newsletter | Privacy Policy | Terms of Service