Welcome to WebmasterWorld Guest from 107.22.87.205

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

parse error, unexpected T_STRING

Common problems with single-double quotes

     
8:14 am on Sep 23, 2004 (gmt 0)

10+ Year Member



Hello!
I am a newbie in PHP and I am getting this parse error ,unexpected t-string error in the following query
$result=@mysql_query("select idTest_Equipment,
name,
equipment_Type,
Site_idSite,
Owner_idOwner,
capability,
ownership,
asset_Rental_Number,
location,
next_Calibration_Date
from Test_Equipment
where
Site_idSite =
("select idSite from Site where name=('".$_POST['site']."')
")
");

The error is in the following part of the query: Site_idSite = ("select idSite from Site where name=('".$_POST['site']."')
")

I get that there is a problem in the brackets n quotes, but i have tried all combinations , nothing works
Someone please help!

9:24 am on Sep 23, 2004 (gmt 0)

10+ Year Member



Ok i have made a small change to simplify the query.

The full thing is as follows

$site = $_POST['site'];
$sql = ("select idSite from Site where name='$site'");

$result = @mysql_query("select idTest_Equipment,
name,
equipment_Type,
Site_idSite,
Owner_idOwner,
capability,
ownership,
asset_Rental_Number,
location,
next_Calibration_Date
from Test_Equipment
where Site_idSite=$sql ");

However now there is a problem in the
$sql = ("select idSite from Site where name='$site'"); statement

$site is a string so i have put it in single quotes.

please help! i m stuck on this problem since 2 days n have a deadline ahead!

Any help is appreciated.

4:37 pm on Sep 23, 2004 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Welcome to WebmasterWorld swati,

drop the parentheses, I also often cat them together like so

$sql = "select idSite from Site where name='" . $site . "'",

9:23 am on Sep 24, 2004 (gmt 0)

10+ Year Member



I tried it but it gives me the following message

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 'select idSite from Site where name =''' at line 11

Also before this it gives me a :
Notice: Undefined index: site in c:\program files\easyphp1-7\www\mysite\css_test\testequipment_manage1.php on line 96

My line 96 is: $site = $_POST['site'];

In this line i want to obtain the value selected by a user in a dropdown list named 'site' and put it in a variable named site. However when i try to print $site i realise that it contains nothing!
heres the dropdown thing:

<select name="site[]" onChange="MM_jumpMenu('parent',this,0)">
<option>dog</option>
<option>cat</option>
<option>ALL</option>
</select>

I am accessing it within the form itself so it shouldnt be out of scope too!

Could you explain to me in what condition we get the 'undefined index' message?

10:01 am on Sep 24, 2004 (gmt 0)

10+ Year Member



Here is how the whole thing looks like after the correction u suggested

$site = $_POST['site'];
$sql = "select idSite from Site where name ='".$site."'";
$result = @mysql_query("select idTest_Equipment,
name,
equipment_Type,
Site_idSite,
Owner_idOwner,
capability,
ownership,
asset_Rental_Number,
location,
next_Calibration_Date
from Test_Equipment
where Site_idSite = $sql ");

12:54 pm on Sep 24, 2004 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You may want to try returning the mysql_error() to get more information. What version of MySQL are you running? Subqueries are only supported at MySQL >= 4.1.
1:25 pm on Sep 24, 2004 (gmt 0)

10+ Year Member



I am using mySQL 4.0.15
you are right.......

but the following statement generates error n it has nothing to do with subqueries!
$sql = "select idSite from Site where name ='".$site."'";

What is wrong with the above statement?

I am just trying to put a string into a variable.
Thanks

2:23 pm on Sep 24, 2004 (gmt 0)

10+ Year Member



Coopster was saying add this:
$result = @mysql_query("select idTest_Equipment,
name,
equipment_Type,
Site_idSite,
Owner_idOwner,
capability,
ownership,
asset_Rental_Number,
location,
next_Calibration_Date
from Test_Equipment
where Site_idSite=$sql ") or die(mysql_error());

This will give you alot more detail on what is actually wrong with your query.

4:31 pm on Sep 30, 2004 (gmt 0)

10+ Year Member



when do we get the "undefined index" message?

I get a message like this..
Notice: Undefined index: type in line102

the line is:
$site = $_POST['site'];

Please help the whole page gets filled with messages like this initially. Site happens to be the name of a drop down list. But when i select a value from the list and click submit, the message disappears.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month