Re: Another dynamic sql.
| From: | Richard Crawford | Date: | Fri, 25 Jan 2002 19:38:21 +0000 |
| Subject: | Re: Another dynamic sql. | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-16180@lists.php.net to get a copy of this message | ||
Raymond,
What sort of error are you getting?
One of the most useful tools in your toolbox is the print() function. Try doing something like this:
$sSQL = "SELECT '$car' FROM varetabell WHERE carid='$carid'";
print ($sSQL);
$sql = mysql_query($sSQL);
$myrow = mysql_fetch_array($sql);
$x = $myrow["$car"];
This will let you see exactly what query is being passed to the database, and that alone will frequently tell you where the problem lies. That is probably the best place to start.
FWIW, in almost all of my database interactions, I set the query as a separate string variable, just so that I can use this sort of debugging technique.
Raymond Lilleodegard wrote:
Hi all! I have this form with some choices: <form> Enter how many cars you want:<input type="text" name="number" > <select size="1" name="car"> <option selected>ford</option> <option>bmw</option> <option>mercedes</option> </select> And then I am trying to get the price out of a table in my database with this code: $sql = mysql_query("SELECT '$car' FROM varetabell where carid='$carid' "); $myrow= mysql_fetch_array($sql); $x = $myrow["$car"]; $price = $x * $number; Shouldn't this work? Or am I missing something here? Best regards Raymond-- Sliante, Richard S. Crawford mailto:rscrawford@mossroot.com http://www.mossroot.com AIM: Buffalo2K ICQ: 11646404 Yahoo!: rscrawford MSN: underpope@hotmail.com "It is only with the heart that we see rightly; what is essential is invisible to the eye." --Antoine de Saint Exupery "Push the button, Max!"