Jump to content
xisto Community
test

Php Error

Recommended Posts

Hey guys im new. anyways i get this error. <!--quoteo--><div class='quotetop'>QUOTE </div><div class='quotemain'><!--quotec-->Parse error: syntax error, unexpected T_LNUMBER in (website roothtdocs\insert.php) on line 18<!--QuoteEnd--></div><!--QuoteEEnd--><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php$con = mysql_connect("localhost","user","password");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("Accounts", $con);$sql="INSERT INTO account (Accounts, Password)VALUES('$entry', '$password');if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "1 record added";mysql_close($con)?><!--c2--></div><!--ec2-->Thanks for any help<link rel="stylesheet" type="text/css" href="http://forums.xisto.com/topic/125-user-contributions/; /><div class="notice"> <div class="header"> <div class="middlebar">Notice from rvalkass: </div> </div> <div class="messagebody" style="display:block;">Code and quote tags added where necessary. Please take a look at the <a href="http://forums.xisto.com/index.php?app=core&module=help; target="_blank">Readme</a>.</div></div>

Edited by rvalkass (see edit history)

Share this post


Link to post
Share on other sites

most of this error happened when you forget adding ( , ) between values. check your code carefully, also don't check only where the line error but the line above it and under it. your code isn't very clear because you should add it in code tags.

 

and another thing, here why you added (Accounts, Password) you should only add your table name

$sql="INSERT INTO account (Accounts, Password)VALUES ('$entry', '$password');

if you want to insert a records to your table, you should do it like this:

INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

 

it will be something like this

mysql_query("INSERT INTO Persons (FirstName, LastName, Age)VALUES ('Peter', 'Griffin', '35')");

check this link

http://www.w3schools.com/php/php_mysql_insert.asp

Share this post


Link to post
Share on other sites

There is a difference between double and single quotes in PHP. Using double quotes means that you want PHP to evaluate the expression inside them, so you can include variables and such. Using single quotes means you want PHP to treat it as a string and print out literally what is there. In your case, switching to single quotes around the echo should solve the problem. Change line 18 to read:

echo '1 record added';

Share this post


Link to post
Share on other sites

I don't see much wrong in what you did but I picked on something minor...

$sql="INSERT INTO account (Accounts, Password)VALUES('$entry', '$password')
this is supposed to be
$sql="INSERT INTO account (Accounts, Password)VALUES('$entry', '$password')";

See if it runs and let us know here.

All the best man

Share this post


Link to post
Share on other sites

roger112 pointed out the first problem (you forgot to close the $sql variable). Since you forgot to close it, the closing part was all the way down to the echo statement where PHP encountered the number 1. But there is a second problem here:

mysql_close($con)
You're missing a semicolon at the end.

Share this post


Link to post
Share on other sites

Hi!@testJust out of curiosity, what editor are you using for editing the PHP source code?You ought to try a better editor or an integrated development environment that can provide syntax highlighting and syntax checks so you can find errors more easily. Syntax highlighting helps you find strings that have not been terminated, which is one of the problems in this case. You would also need the development environment to find missing semicolons and indicate them to you with a squiggly like Microsoft Word does for mis-spelled words.Have a look at the NuSphere PhpEd editor and the Zend Studio, both of which have quite a reputation among the PHP development community. They offer a pretty rich feature set and are commercially supported.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.