Jump to content

Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$'


Mutley

Recommended Posts

New error for me, line 9 which is:

[code]7.          {
8.          if(isset($id)){
9.          $1 = $_POST['1'];
10.        $2 = $_POST['2'];
11.        $3 = $_POST['3'];[/code]

Error:
Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' on line 9.
[quote author=Daniel0 link=topic=108663.msg437383#msg437383 date=1158687465]
I do not think you can start a variable with a number.
[/quote]
Correct, variable names can only start with a letter or an underscore.

[b]EDIT:[/b] Beaten to it :P
Thanks.

My script seems to not be updating my content, does this look right now I've changed it?

[code]if(isset($id)){
$_1 = $_POST['1'];
$_2 = $_POST['2'];
$_3 = $_POST['3'];
$_4 = $_POST['4'];
$_5 = $_POST['5'];
$_6 = $_POST['6'];
$_7 = $_POST['7'];
$_8 = $_POST['8'];
$_9 = $_POST['9'];
$_10 = $_POST['10'];
$_11 = $_POST['11'];
$_12 = $_POST['12'];
$_13 = $_POST['13'];
$_14 = $_POST['14'];
$_15 = $_POST['15'];
$_16 = $_POST['16'];
$_17 = $_POST['17'];
$_18 = $_POST['18'];
$_19 = $_POST['19'];

mysql_select_db("rufc");

$sql = "UPDATE scores SET 1='$_1', 2='$_2', 3='$_3', 4='$_4', 5='$_5', 6='$_6', 7='$_7', 8='$_8', 9='$_9', 10='$_10', 11='$_11', 12='$_12', 13='$_13', 14='$_14', 15='$_15', 16='$_16', 17='$_17', 18='$_18', 19='$_19' WHERE score_id = '".$id."'";
mysql_query($sql);[/code]

The SQL echos on the page and looks fine but makes no change to the database. It has other fields in rows not just 1, 2, 3, 4 etc, would that be the problem? Because I'm not updating them with anything? I just want the fields listed above (the numbers) to be updated.
Do you have fields named 1 throught to 19 in your scores table? Also prehaps see if there is an error with your query too, by adding or die(mysql_errro()) after mysql_query($sql) so it becomes:
[code=php:0]mysql_query($sql) or die('Unable to perform query<br />' . mysql_error());[/code]
ID is fine (first line which is "18" below), I got an error though:
[code]
18
Unable to perform query
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1='', 2='', 3='', 4='', 5='', 6='', 7='', 8='', 9='', 10='', 11='', 12='', 13=''' at line 1[/code]

I deliberatly put no data in by the way, so don't worry that nothing = anything. Thanks for the help guys!
since you are using numbers for fields, sql gets confused when you try to use them in your query. it sees 1='$_1' and tries to look at it like a condition/comparison, rather than an assignment.  therefore you use the backticks to tell sql that the number is really a field name and that you want to assign a value to it.

backticks are also used for what SA mentioned: if you use a reserved word for a table or field name, sql will get confused and try to parse the string under the function of the reserved word. So if you wish to use a reserved word as a table or field name, you need to use backticks so sql knows to treat it as a table/field name and not a reserved word. 

You should know that it is not good practice to use reserved words or even numbers as table and field names.  It's lazy and non-intuitive and begs for trouble to happen down the road...just like right now.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.