Mutley Posted September 19, 2006 Share Posted September 19, 2006 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 Link to comment https://forums.phpfreaks.com/topic/21303-parse-error-syntax-error-unexpected-t_lnumber-expecting-t_variable-or/ Share on other sites More sharing options...
Daniel0 Posted September 19, 2006 Share Posted September 19, 2006 I do not think you can start a variable with a number. Quote Link to comment https://forums.phpfreaks.com/topic/21303-parse-error-syntax-error-unexpected-t_lnumber-expecting-t_variable-or/#findComment-94791 Share on other sites More sharing options...
wildteen88 Posted September 19, 2006 Share Posted September 19, 2006 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'; Quote Link to comment https://forums.phpfreaks.com/topic/21303-parse-error-syntax-error-unexpected-t_lnumber-expecting-t_variable-or/#findComment-94795 Share on other sites More sharing options...
zq29 Posted September 19, 2006 Share Posted September 19, 2006 [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 Quote Link to comment https://forums.phpfreaks.com/topic/21303-parse-error-syntax-error-unexpected-t_lnumber-expecting-t_variable-or/#findComment-94796 Share on other sites More sharing options...
Mutley Posted September 19, 2006 Author Share Posted September 19, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/21303-parse-error-syntax-error-unexpected-t_lnumber-expecting-t_variable-or/#findComment-94806 Share on other sites More sharing options...
wildteen88 Posted September 19, 2006 Share Posted September 19, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/21303-parse-error-syntax-error-unexpected-t_lnumber-expecting-t_variable-or/#findComment-94807 Share on other sites More sharing options...
.josh Posted September 19, 2006 Share Posted September 19, 2006 you also might wanna check and see if $id really is set. try echo $id; before your if statement Quote Link to comment https://forums.phpfreaks.com/topic/21303-parse-error-syntax-error-unexpected-t_lnumber-expecting-t_variable-or/#findComment-94817 Share on other sites More sharing options...
Mutley Posted September 19, 2006 Author Share Posted September 19, 2006 ID is fine (first line which is "18" below), I got an error though:[code]18Unable to perform queryYou 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! Quote Link to comment https://forums.phpfreaks.com/topic/21303-parse-error-syntax-error-unexpected-t_lnumber-expecting-t_variable-or/#findComment-94829 Share on other sites More sharing options...
.josh Posted September 19, 2006 Share Posted September 19, 2006 try putting backticks around your field names. `1` = '$_1', `2` = '$_2", etc... Quote Link to comment https://forums.phpfreaks.com/topic/21303-parse-error-syntax-error-unexpected-t_lnumber-expecting-t_variable-or/#findComment-94833 Share on other sites More sharing options...
Mutley Posted September 19, 2006 Author Share Posted September 19, 2006 Cool, it worked, thanks.What do backticks` do? Quote Link to comment https://forums.phpfreaks.com/topic/21303-parse-error-syntax-error-unexpected-t_lnumber-expecting-t_variable-or/#findComment-94850 Share on other sites More sharing options...
zq29 Posted September 19, 2006 Share Posted September 19, 2006 Backticks generally allow you to use reserved words, par example:[code]SELECT * FROM `table` WHERE `where`='England' ORDER BY `id` ASC LIMIT 10[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21303-parse-error-syntax-error-unexpected-t_lnumber-expecting-t_variable-or/#findComment-94876 Share on other sites More sharing options...
.josh Posted September 20, 2006 Share Posted September 20, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/21303-parse-error-syntax-error-unexpected-t_lnumber-expecting-t_variable-or/#findComment-95072 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.