|
Subject:
|
Unexpected : t_string, t_variable, t_num_string
|
|
Posted By:
|
scifo
|
Post Date:
|
7/31/2003 3:04:38 PM
|
Hi I have been trying to sort this out but i could not. It gives this error every time: Parse error, expecting 't_string' or 't_variable' or 't_num_string' in ........ on line 21 The related line is like this: $Query = "INSERT INTO $TableName VALUES ($HTTP_POST_VARS['mytextbox'])"; The variable $HTTP_POST_VARS['mytextbox'] works when I use it in an echo statement but it does not work here. I am going to be mad. Pls help me...
|
|
Reply By:
|
nikolai
|
Reply Date:
|
7/31/2003 3:21:56 PM
|
You should remove the single-quotes from your array index. When parsing double-quoted strings, if PHP finds an array variable, it can only parse a single level of nesting. It assumes that whatever is in the square brackets is either the numerical, string, or variable index. If you attempt to echo nested arrays, the first level of nesting will evaluate to the string "Array", and the additional array indexes will be echoed as literal strings.
You can also use curly-brace syntax for all variable substitutions, including nested arrays.
Here are some examples:
$me['name']['first'] = 'nikolai'; $me['age'] = 27; $stat = "age"
echo "My name is {$me['name']['first']}."; // "My name is nikolai." echo "My name is $me['name']['first']."; // Parse error echo "My name is $me[name][first]."; // "My name is Array[first]." echo "I am $me[age]."; // I am 27. echo "I am {$me['age']}."; // I am 27. echo "I am $me['age']}." // Parse error. echo "I am $me[$stat]." // I am 27.
As always, read the manual! http://www.php.net/types.string
Take care,
Nik http://www.bigaction.org/
|
|
Reply By:
|
bruce.benamran
|
Reply Date:
|
8/14/2003 1:47:16 AM
|
although php is able to process it, removing quotes from index is in my opinion a mistake... you should rather take all your variables out of the string :
$Query = "INSERT INTO $TableName VALUES (".$HTTP_POST_VARS['mytextbox'].")";
php/java developer NTIC engineer
|
|
Reply By:
|
ante
|
Reply Date:
|
10/8/2003 3:02:42 AM
|
Question
|
|
Reply By:
|
ante
|
Reply Date:
|
10/8/2003 3:09:47 AM
|
Plz forget my last post.. :) Now to the problem...i got this code on a PHP-Nuke site..
<?php if (!isset($mainfile)) { include("mainfile.php"); } $index = 1; include("header.php"); include("functions.php"); OpenTable();
// Make sure a valid sort was given if (!preg_match('/^(name|totalkills|totaldeaths|kpm|kdr|skill)$/i',$sort)) $sort = 'skill'; $sort = strtolower($sort);
// Total names to list on a single page. Change this to whatever you want. if (!preg_match('/^\d+$/', $limit)) $limit = 100;
// Nothing else below this line needs to be changed unless you want to customize the layout // ----------------------------------------------------------------------------------------
if (!preg_match('/^\d+$/', $start)) $start = 0;
$cell1 = 'plrrow1'; $cell2 = 'plrrow2'; $cell = '';
global $prefix;
$playerlist = array(); $playerlist[] = array( "plrname" => stripslashes("\[TEST\]Test"), "plrhtml" => stripslashes("player_W01LQkldU2Fkbw\.php"), "plrrank" => "4", "plrskill" => "1345", "plrtotalkills" => "433", "plrtotaldeaths" => "293", "plrkdr" => "1.48", "plrkpm" => "0.69", "plrwonids" => "", "plraliases" => stripslashes("\[TEST\]Test"), "plricon" => stripslashes("player\.gif"), "plrclanicon" => stripslashes("\<a\ href\=\'clanpage__test_\.php\'\>\<img\ src\=\'clan\.gif\'\ width\=\"18\"\ height\=\"14\"\ border\=\"0\"\ alt\=\"\[TEST\]\"\>\<\/a\>"), ); // [TEST]Test
sql_query("INSERT INTO ".$prefix."psychostats (rankid, pname, kills, deaths, kd, kpm, skill) VALUES (".$playerlist['plrrank'].",".$playerlist['plrname'].",".$playerlist['plrtotalkills'].",".$playerlist['plrtotaldeaths'].",".$playerlist['plrkpr'].",".$playerlist['plrkpm'].",".$playerlist['plrskill']."),");
The table is created..but it wont update the tables with new data, and no errors are issued?
Plz, could someone help me to sort this out.. Thanks, Ante
|
|
Reply By:
|
bruce.benamran
|
Reply Date:
|
10/12/2003 4:46:06 PM
|
For what I can see, some of your data like 'plrname' are strings (Varchar). Thus, the value you want to insert should be single-quoted :
sql_query("INSERT INTO ".$prefix."psychostats (rankid, pname, kills, deaths, kd, kpm, skill) VALUES (".$playerlist['plrrank'].",'".$playerlist['plrname']."',".$playerlist['plrtotalkills'].",".$playerlist['plrtotaldeaths'].",".$playerlist['plrkpr'].",".$playerlist['plrkpm'].",".$playerlist['plrskill']."),");
Of Course, every varchar should appear single-quoted. My advice is to always single-quote when it's not an expressions e.g: insert into myTable values ( mytable_seq.nextval, 'toto', 233 ); should become : insert into myTable values (mytable_seq.nextval , 'toto', '233');
php/java developer NTIC engineer
|
|
Reply By:
|
mp213
|
Reply Date:
|
11/11/2004 8:19:30 PM
|
i am getting the same message: Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in d:\inetpub\wwwroot\LT\savecand1.php on line 10 the code on line 10 is the following:
"INSERT into Candidate (Tel_No, Name, Fax_No, Email)VALUES($telno,'$cname',$faxno,'$email') where Email=(SELECT Email FROM User where Email='$_SESSION["USER"]')";
im receiving $telno, $cname etc into $_POST like $telno=$_POST["telno"]; etc.
i can't understand what's wrong - can someone please help using simple language, you're dealing with a novice here - im learning php basically, and this is my term assignment...and im stuck :$ please help.
|
|
Reply By:
|
Snib
|
Reply Date:
|
11/11/2004 8:54:03 PM
|
If you had read the thread (specifically Nik's reply) you would've seen the correct way to do it.
I suggest you re-read Nik's reply to the original question.
-Snib Where will you be in 100 years? Try new FreshView 0.2!
|
|
Reply By:
|
mp213
|
Reply Date:
|
11/11/2004 8:59:41 PM
|
i DID read the reply...i read all the replies...and i tried everything...nothing worked. see?
|
|
Reply By:
|
SiliconFuRy
|
Reply Date:
|
11/12/2004 6:01:38 AM
|
Seperate variables from strings, concatenate them. Tis what I always do, and I believe its good programming practise. stuff like:
$string = "Hello, " . $name . ", PHP is fun! Better than that . $microsoft_produced_language_like_ASP . " poo!";
Many shoes,
James/SiliconFuRy
|
|
Reply By:
|
Snib
|
Reply Date:
|
11/12/2004 3:24:01 PM
|
Yes, you can do it like this:
echo "hey there $_SESSION[username]";
or this:
echo 'hey there '.$_SESSION['username'];
The first way is generally easier, but the second way uses less resources.
As Nik said in the reply I gave you....
"As always, read the manual!
http://www.php.net/types.string "
HTH!
-Snib Where will you be in 100 years? Try new FreshView 0.2!
|
|
Reply By:
|
mp213
|
Reply Date:
|
11/12/2004 10:11:38 PM
|
just to be more specific the following script is working:
$email=$HTTP_POST_VARS["email"]; $pass=$HTTP_POST_VARS["passw"]; $type1=$HTTP_POST_VARS["type"]; $l="user.htm"; $l2="templogin.htm";
$Connection=odbc_connect("mp","mp","mp"); $in="insert into User values('$email','$pass','$type1')"; $run=odbc_do($Connection,$in);
but this one below, isn't...can someone tell me why cause i dont get it:
$cname =$_POST["name"]; $telno=$_POST["telno"]; $faxno=$_POST["fax"]; $email=$_POST["email"]; $Connection = odbc_connect("mp","mp","mp"); $r="INSERT into Candidate (Tel_No, Name, Fax_No, Email)VALUES($telno,'$cname',$faxno,'$email') where Email=(SELECT Email FROM User where Email='$_SESSION["USER"]')"; $query=odbc_do($Connection, $r);
here telno and faxno are numbers and not strings...as for the echo '$_SESSION["USERNAME"], that too isnt a problem - thats displaying...i really need this to work since my other pages are tied to this...so with this new info, can someone help me out now? mp
|
|
Reply By:
|
Snib
|
Reply Date:
|
11/13/2004 3:15:05 PM
|
It s this part right here: br / br / FROM User where Email= $_SESSION[ USER')";
You see, you used the double quotes to enclose USER. But the string it's in is contained within double quotes. So when you use double quotes PHP thinks you're trying to end the string, but then there's just this USER thing right after the string, and it throws a parse error.
So do like this:
FROM User where Email='$_SESSION[USER]')";
Just get rid of the double quotes (only when inside a string; otherwise keep them).
-Snib Where will you be in 100 years? Try new FreshView 0.2!
|
|
Reply By:
|
mp213
|
Reply Date:
|
11/15/2004 4:08:10 AM
|
okay, thanks that problem has been solved - now another problem has arisen...nothing to do with this thread tho...its an odbc_do probelm:
Warning: odbc_do(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Operation must use an updateable query., SQL state S1000 in SQLExecDirect in d:\inetpub\wwwroot\LT\saveclient.php on line 15
the code is the same as above, although ive taken out the quotes as snib suggested.
|