 |
| PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 31st, 2003, 03:04 PM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Unexpected : t_string, t_variable, t_num_string
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...
|
|

July 31st, 2003, 03:21 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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/
|
|

August 14th, 2003, 01:47 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

October 8th, 2003, 03:02 AM
|
|
Registered User
|
|
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Question
|
|

October 8th, 2003, 03:09 AM
|
|
Registered User
|
|
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

October 12th, 2003, 04:46 PM
|
|
Authorized User
|
|
Join Date: Aug 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 11th, 2004, 09:19 PM
|
|
Registered User
|
|
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

November 11th, 2004, 09:54 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
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!
|
|

November 11th, 2004, 09:59 PM
|
|
Registered User
|
|
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i DID read the reply...i read all the replies...and i tried everything...nothing worked. see?
|
|

November 12th, 2004, 07:01 AM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |