Welcome to WebmasterWorld Guest from 23.20.75.214

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)

Junior Member

10+ Year Member

joined:Sept 23, 2004
posts:83
votes: 0


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 Sept 23, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 23, 2004
posts:83
votes: 0


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 Sept 23, 2004 (gmt 0)

Administrator

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

joined:July 24, 2001
posts:15755
votes: 0


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 Sept 24, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 23, 2004
posts:83
votes: 0


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 Sept 24, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 23, 2004
posts:83
votes: 0


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 Sept 24, 2004 (gmt 0)

Administrator

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

joined:July 31, 2003
posts:12541
votes: 1


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 Sept 24, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 23, 2004
posts:83
votes: 0


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 Sept 24, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 17, 2002
posts:601
votes: 0


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 Sept 30, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 23, 2004
posts:83
votes: 0


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.