Forum Moderators: coopster

Message Too Old, No Replies

Code Help: What am I doing wrong with Syntax?

         

andybr22

11:16 pm on Apr 7, 2005 (gmt 0)

10+ Year Member



<?php

$dbh=mysql_connect ("localhost", "webist2_guest", "guest") or die
('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("webist2_testdatatxt");

$model = $_POST['myear'];

$query2 = mysql_query("SELECT FROM table WHERE 'From' <= . '$model' . AND 'To' >= . '$model' . LIMIT 1") or die(mysql_error());

//display data

?>

I think the field names of To and From may be a problem here please help me out though I think I got confused on the quotes and stuff.

ironik

11:52 pm on Apr 7, 2005 (gmt 0)

10+ Year Member



I've removed the quotes from the field names and adjusted the way you've put the variables in there. You don't need the period . character when placing variables directly in a double quoted string, PHP will find them. So the query would look like this:

$query2 = mysql_query("SELECT FROM table WHERE From <='" . $model . "' AND To >='" . $model . "' LIMIT 1") or die(mysql_error());

or:

$query2 = mysql_query("SELECT FROM table WHERE From <='$model' AND To >='$model' LIMIT 1") or die(mysql_error());

andybr22

12:11 am on Apr 8, 2005 (gmt 0)

10+ Year Member



Brilliant! Where would us newbs be without you guys!