edit: nvm i solved it. instead i have a different problem. here is my code:
<?php
$newuser = $_get['$newuser'];
$con = mysql_connect("","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("shalev", $con);
mysql_query("INSERT INTO userinfo (name)
VALUES ($newuser)");
mysql_close($con);
echo "Success"
?>
what i want to accomplish is to insert into blabla the value recalled from the previous page, $newuser. but when i check my database it doesnt insert.
Parse error: syntax error, unexpected $end
Moderator: General Moderators
Re: Parse error: syntax error, unexpected $end
$_get['$newuser'];
What is this supposed to do?
What is this supposed to do?
Re: Parse error: syntax error, unexpected $end
Use mysql_error().
-
cpetercarter
- Forum Contributor
- Posts: 474
- Joined: Sat Jul 25, 2009 2:00 am
Re: Parse error: syntax error, unexpected $end
php will generate error messages which will probably explain the problem to you. But you have to set up your script properly to generate and read them. There is no point in putting " echo 'Success'" at the end if you don't first check that the operation has in fact been successful. You can do this by amending the mysql_query line to :
This works because mysql_query returns a value of "false" if the operation fails.
A possible reason why the script is not working is that you are trying to enter an inadmissable string into the database. It is always a good idea to escape the string first, like this :
Commas in strings also cause problems, as MySQL is likely to treat them as marking the end of the query.
Code: Select all
$result = mysql_query("INSERT INTO userinfo (name) VALUES ($newuser)");
if (!$result) echo "Arrgh! Something's wrong : ".mysql_error();
A possible reason why the script is not working is that you are trying to enter an inadmissable string into the database. It is always a good idea to escape the string first, like this :
Code: Select all
$newuser = mysql_real_escape_string($newuser);
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: Parse error: syntax error, unexpected $end
As koen.h has already pointed out:
should probably beVariables, including superglobals like $_GET, are case-sensitive
Code: Select all
$newuser = $_get['$newuser'];Code: Select all
$newuser = $_GET['$newuser'];Re: Parse error: syntax error, unexpected $end
thanks for your replies.
cpetercarter, i have inserted the code you suggested to find out what the problem is and it gives my this: Column count doesn't match value count at row 1
i am not sure what it means, especially that my code doesnt include rows and columns. any help will be appreciated
cpetercarter, i have inserted the code you suggested to find out what the problem is and it gives my this: Column count doesn't match value count at row 1
i am not sure what it means, especially that my code doesnt include rows and columns. any help will be appreciated
-
cpetercarter
- Forum Contributor
- Posts: 474
- Joined: Sat Jul 25, 2009 2:00 am
Re: Parse error: syntax error, unexpected $end
The first thing to do when you get an error message that you don't understand is to google it.
You do have rows and columns, even if you don't realise it.The "columns" in your table are the names of the various fields - things like "id", "name", "phone_number", "favourite_sport" etc. The "rows" are the individual records - things like "2", "Fred", "123 45 67 89", "table tennis". The error is telling you that the number of values in your INSERT query do not match the number of columns which you have specified.
This is on the face of it odd, because you have specified one column ('name') and one value ('$username'), so the numbers do match. My guess is that the error message is telling you either :
that the value is null or invalid. Follow Mark Baker's suggestion and replace $_get['username'] with $_GET['username'].
that you do not have any columns in the table. If you run the "SHOW TABLE" sql query, it should output the necessary info about the table
You do have rows and columns, even if you don't realise it.The "columns" in your table are the names of the various fields - things like "id", "name", "phone_number", "favourite_sport" etc. The "rows" are the individual records - things like "2", "Fred", "123 45 67 89", "table tennis". The error is telling you that the number of values in your INSERT query do not match the number of columns which you have specified.
This is on the face of it odd, because you have specified one column ('name') and one value ('$username'), so the numbers do match. My guess is that the error message is telling you either :
that the value is null or invalid. Follow Mark Baker's suggestion and replace $_get['username'] with $_GET['username'].
that you do not have any columns in the table. If you run the "SHOW TABLE" sql query, it should output the necessary info about the table