homepage Welcome to WebmasterWorld Guest from 54.198.140.182
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
parse error, unexpected T_STRING
Common problems with single-double quotes
swati




msg:1300482
 8:14 am on Sep 23, 2004 (gmt 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!

 

swati




msg:1300483
 9:24 am on Sep 23, 2004 (gmt 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.

jatar_k




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

Welcome to WebmasterWorld swati,

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

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

swati




msg:1300485
 9:23 am on Sep 24, 2004 (gmt 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?

swati




msg:1300486
 10:01 am on Sep 24, 2004 (gmt 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 ");

coopster




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

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.

swati




msg:1300488
 1:25 pm on Sep 24, 2004 (gmt 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

Knowles




msg:1300489
 2:23 pm on Sep 24, 2004 (gmt 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.

swati




msg:1300490
 4:31 pm on Sep 30, 2004 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved