Jump to content

Recommended Posts

here is my script

 

My error

Parse error: syntax error, unexpected $end in C:\WAMP\www\Tutorials\PHP_MYSQL\Simple_MySQL\MYSQL_Insert\process.php on line 14

 

<?php
mysql_connect("localhost","root" , "password") or die (mysql_error());
echo "Connected To MySQL Successfully";
mysql_select_db("tutorial1") or die (mysql_error());
echo "<br>Connected To Database Successfully";

$personaldata = array("name" => $_POST['name'], "age" => $_POST['age'], "sex" => $_POST['sex']);

mysql_query("INSERT INTO personal information (name, age, sex) 
VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]')") or die(mysql_error());

echo "You've submited this information. <br> name:" .$personaldata[name]. "<br> Age:" .$personaldata[age]. "<br> Sex:" .$personaldata[sex].";

?>

 

What is weird is that the error is on the  last line which is

?>

 

What could be the problem?

 

Thanks a lot!

 

 

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/
Share on other sites

echo "You've submited this information. <br> name:" .$personaldata[name]. "<br> Age:" .$personaldata[age]. "<br> Sex:" .$personaldata[sex].";

 

to

echo "You've submited this information. <br> name:" .$personaldata['name']. "<br> Age:" .$personaldata['age']. "<br> Sex:" .$personaldata['sex'];

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-259834
Share on other sites

echo "You've submited this information. <br> name:" .$personaldata[name]. "<br> Age:" .$personaldata[age]. "<br> Sex:" .$personaldata[sex].";

 

to

echo "You've submited this information. <br> name:" .$personaldata['name']. "<br> Age:" .$personaldata['age']. "<br> Sex:" .$personaldata['sex'];

 

this worked better

 

but the ; thing did not because it just created a new error.

 

But now my error is:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\WAMP\www\Tutorials\PHP_MYSQL\Simple_MySQL\MYSQL_Insert\process.php on line 10

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-259884
Share on other sites

VALUES('$personaldata['name']','$personaldata['age']','$personaldata['sex']')"); or die(mysql_error());

 

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\WAMP\www\Tutorials\PHP_MYSQL\Simple_MySQL\MYSQL_Insert\process.php on line 10

 

I dont see anything wrong :S but then again im not a pro in php

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-259906
Share on other sites


VALUES('$personaldata['name']','$personaldata['age']','$personaldata['sex']')"); or die(mysql_error());

TO

VALUES('".$personaldata['name']."','".$personaldata['age']."','".$personaldata['sex']."')"); or die(mysql_error());

 

i've done what you've said but apparenthly there is a new bug,

 

Parse error: syntax error, unexpected T_VARIABLE in C:\WAMP\www\Tutorials\PHP_MYSQL\Simple_MySQL\MYSQL_Insert\process.php on line 10

 

thanks for the help.

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-259973
Share on other sites

You have an extra ";" in this line:

<?php
VALUES('".$personaldata['name']."','".$personaldata['age']."','".$personaldata['sex']."')"); or die(mysql_error());
?>

it should written as

<?php
VALUES('".$personaldata['name']."','".$personaldata['age']."','".$personaldata['sex']."')") or die(mysql_error());
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-259975
Share on other sites

You have an extra ";" in this line:

<?php
VALUES('".$personaldata['name']."','".$personaldata['age']."','".$personaldata['sex']."')"); or die(mysql_error());
?>

it should written as

<?php
VALUES('".$personaldata['name']."','".$personaldata['age']."','".$personaldata['sex']."')") or die(mysql_error());
?>

 

Ken

 

if i dont put ; i get a seperate error

 

also  new error ater some tweaking

Parse error: syntax error, unexpected $end in C:\WAMP\www\Tutorials\PHP_MYSQL\Simple_MySQL\MYSQL_Insert\process.php on line 14

vtahst the value line

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-260060
Share on other sites

Should it not be like this? Surely the double use of 's will cause problems.

 

<?php

mysql_query("INSERT INTO personal information (name, age, sex) 
VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]');") or die(mysql_error());

?>

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-260069
Share on other sites

<?php

mysql_connect("localhost","root" , "password") or die (mysql_error());
echo "Connected To MySQL Successfully";
mysql_select_db("tutorial1") or die (mysql_error());
echo "<br>Connected To Database Successfully";

$personaldata = array("name" => $_POST['name'], "age" => $_POST['age'], "sex" => $_POST['sex']);

mysql_query("INSERT INTO personal information (name, age, sex)VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]')") or die(mysql_error());

echo "You've submited this information. <br> name:". $personaldata[name]. "<br> Age:" .$personaldata[age]. "<br> Sex:" .$personaldata[sex];

?>

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-260071
Share on other sites

Dude, I would seriously read through this http://us2.php.net/manual/en/language.basic-syntax.php

 

Learn the basic of the syntax's. Anytime you get a syntax error you are asking for help, really syntax errors should be the least of your worries and the easiest to correct. Do some reading and learn that you cannot use a single quote inside a string surrounded by single quotes you have to escape it. Same with double quotes and that every statement should have a semi-colon after it. and that anytime and if statement is made it should have a starting { and an ending }.

 

That is just basics to programming, learn them first if you do not it will take you 20 years to program 10 lines of code because you always have to ask for help on any type of syntax error that is thrown.

 

Reading is key.

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-260073
Share on other sites

<?php

mysql_connect("localhost","root" , "password") or die (mysql_error());
echo "Connected To MySQL Successfully";
mysql_select_db("tutorial1") or die (mysql_error());
echo "<br>Connected To Database Successfully";

$personaldata = array("name" => $_POST['name'], "age" => $_POST['age'], "sex" => $_POST['sex']);

mysql_query("INSERT INTO personal information (name, age, sex)VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]')") or die(mysql_error());

echo "You've submited this information. <br> name:". $personaldata[name]. "<br> Age:" .$personaldata[age]. "<br> Sex:" .$personaldata[sex];

?>

 

That's what I had in the beguining, it's not working.  :'(

 

 

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-260589
Share on other sites

That's what I had in the beguining, it's not working.

 

"Not working" covers a multitude of sins, so you really should be much more specific about the problem than that.

 

Looking at the code you have, it appears that you have a database table named personal space information.

 

INSERT INTO personal information ... 

 

That isn't going to work as it will be interpreted as a database table named personal and the random 'information' will be meaningless in the query string.

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-260631
Share on other sites

i changed it to personalinfo.

 

<?php
mysql_connect("localhost","root" , "password") or die (mysql_error());
echo "Connected To MySQL Successfully";
mysql_select_db("tutorial1") or die (mysql_error());
echo "<br>Connected To Database Successfully";

$personaldata = array("name" => $_POST['name'], "age" => $_POST['age'], "sex" => $_POST['sex']);

mysql_query("INSERT INTO personalinformation (name, age, sex) VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]')") or die(mysql_error());

echo "You've submited this information. <br> name:" .$personaldata['name']. "<br> Age:" .$personaldata['age']. "<br> Sex:" .$personaldata['sex'].";

?>

 

I still get a $end error. I was thinking because in my html. becuase for the sex option i did a slide select menu.

 

    <select name="select">
      <option value="M">Male</option>
      <option value="F">Female</option>
    </select>

 

will crachar suport this?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-261446
Share on other sites

if you have a look at your last echo statement in your above post and count the number of double quotes you have, they work in pairs, an opening one and closing one , enclosing a string object. You have 7 in that statement which is why if you look at your code block the closing php tag is red and not blue because you string object is still open, simple syntax problems such as that should be found straight away

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-261470
Share on other sites

i changed it to personalinfo.

 

<?php
mysql_connect("localhost","root" , "password") or die (mysql_error());
echo "Connected To MySQL Successfully";
mysql_select_db("tutorial1") or die (mysql_error());
echo "<br>Connected To Database Successfully";

$personaldata = array("name" => $_POST['name'], "age" => $_POST['age'], "sex" => $_POST['sex']);

mysql_query("INSERT INTO personalinformation (name, age, sex) VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]')") or die(mysql_error());

echo "You've submited this information. <br> name:" .$personaldata['name']. "<br> Age:" .$personaldata['age']. "<br> Sex:" .$personaldata['sex'].";

?>

 

I still get a $end error. I was thinking because in my html. becuase for the sex option i did a slide select menu.

 

    <select name="select">
      <option value="M">Male</option>
      <option value="F">Female</option>
    </select>

 

will crachar suport this?

 

thanks

 

If i was you I wouldn't echo the "Connected To MySQL Successfully" & "Connected To Database Successfully"

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-261486
Share on other sites

I've listened to what you guys told me, But i really don't think the 2 first echos would have created an issue, but I have taken it off and also fixed the problem with my " stupid mistake.

 

But I get an unexpected ";" command on my line 13.

 

<?php
mysql_connect("localhost","root" , "password") or die (mysql_error());

mysql_select_db("tutorial1") or die (mysql_error());


$personaldata = array("name" => $_POST['name'], "age" => $_POST['age'], "sex" => $_POST['sex']);

mysql_query("INSERT INTO personalinformation (name, age, sex) VALUES('$personaldata[name]', '$personaldata[age]', '$personaldata[sex]')") or die(mysql_error());

[color=red]echo "You've submited this information. <br> name:" .$personaldata['name']. "<br> Age:" .$personaldata['age']. "<br> Sex:" .$personaldata['sex'].;
[/color]
?>

 

the red echo is my line 13

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-261570
Share on other sites

You have an extra "." before the ";". Remove the "."

<?php
echo "You've submited this information. <br> name:" .$personaldata['name']. "<br> Age:" .$personaldata['age']. "<br> Sex:" .$personaldata['sex'];
?>

 

BTW, using [tags] in a


doesn't work. You should indicate the line that you're referring to by adding a comment to the line.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/52643-unexpected-end-error/#findComment-261576
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.