Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Data Integration / June 2007



Tip: Looking for answers? Try searching our database.

php variables are killing me

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sean McMurtrey - 22 Jun 2007 06:12 GMT
I'm using a WHERE condition in a SELECT clause of my query thats looking for 3
parameters. When I plug the WHERE condition with strings it works:

[i]
mysql_connect(localhost, $username, $password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());

// Get a specific result from the "example" table
$result = mysql_query("SELECT * FROM allMeetings WHERE [b]city = 'Boise,
Idaho' AND day = 'Monday' AND time = '7:00a[/b]'")
or die(mysql_error());  

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row
    //echo $row['city']." - ".$row['group']. "<br />";
     echo $row['city']." - ".$row['day']." - ".$row['time']." -
".$row['group']." - ".$row['address']." - ".$row['flag1']." - ".$row['flag2'].
" - ".$row['flag3'].'<br />';
}[/i]

Now the fun part. If I replace the strings with variables it errors out:
[i]
[b]$fcity = "Boise, Idaho";
$fday = "Monday";
$ftime = "7:00a";[/b]

mysql_connect(localhost, $username, $password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());

// Get a specific result from the "example" table  
$result = mysql_query("SELECT * FROM allMeetings WHERE [b]day=$fday AND
city=$fcity AND time=$ftime [/b]") or die(mysql_error());  

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row
    //echo $row['city']." - ".$row['group']. "<br />";
     echo $row['city']." - ".$row['day']." - ".$row['time']." -
".$row['group']." - ".$row['address']." - ".$row['flag1']." - ".$row['flag2'].
" - ".$row['flag3'].'<br />';
}[/i]

The above returns the following:
[b]You have an error in your SQL syntax near ' Idaho AND time=7:00a ' at line
1[/b]

I'm sure its something simple and stupid so if anyone can enlighten me I would
be much obliged.
Gorka Ludlow - 22 Jun 2007 15:07 GMT
Why are you asking this in a flash forum?

"You have an error in your SQL syntax"

Anyways, your variables need quotes for the query, try this instead ( var = "
\ ' value ' \ " ; variable =  double quote, slash, single quote, value, single
quote, slash, double quote):

$fcity = "\'Boise, Idaho\'";
$fday = "\'Monday\'";
$ftime = "\'7:00a\'";

Cheers
Gorka
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.