Jump to content


Photo

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


  • Please log in to reply
11 replies to this topic

#1 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 19 September 2006 - 05:21 PM

New error for me, line 9 which is:

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

Error:
Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' on line 9.
~ Mutley.

#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 19 September 2006 - 05:37 PM

I do not think you can start a variable with a number.

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 September 2006 - 05:40 PM

That is correct you cannot use a number as the variable name. Use a non numeric character first if want to use a number as a variable eg:
$_1 = 'blah';
$_2 = 'blah';

#4 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 19 September 2006 - 05:41 PM

I do not think you can start a variable with a number.

Correct, variable names can only start with a letter or an underscore.

EDIT: Beaten to it :P

#5 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 19 September 2006 - 05:58 PM

Thanks.

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

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);

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.
~ Mutley.

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 19 September 2006 - 06:02 PM

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:
mysql_query($sql) or die('Unable to perform query<br />' . mysql_error());


#7 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 19 September 2006 - 06:13 PM

you also might wanna check and see if $id really is set.  try

echo $id;

before your if statement

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#8 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 19 September 2006 - 06:29 PM

ID is fine (first line which is "18" below), I got an error though:
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

I deliberatly put no data in by the way, so don't worry that nothing = anything. Thanks for the help guys!
~ Mutley.

#9 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 19 September 2006 - 06:33 PM

try putting backticks around your field names.  `1` = '$_1', `2` = '$_2", etc...

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#10 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 19 September 2006 - 06:56 PM

Cool, it worked, thanks.

What do backticks` do?
~ Mutley.

#11 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 19 September 2006 - 07:33 PM

Backticks generally allow you to use reserved words, par example:
SELECT * FROM `table` WHERE `where`='England' ORDER BY `id` ASC LIMIT 10


#12 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 20 September 2006 - 03:52 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users