Need Your Help with PHP Callout in HTML

revit

BANNED
Joined
Apr 24, 2009
Messages
266
Reaction score
372
Sorry, I wasn't quite sure where to post this to request everyones help.

I am trying to insert a sql callout in an html form.

This is the script:

HTML:
<select name="carrier">
<option value="" selected>-- Carriers --</option>
<?
$sql = "SELECT * FROM carriers";
$result = mysql_query($sql); 
while($row = mysql_fetch_array($result)) {
?>
<option value="<? echo $row["id"]; ?>">
<? echo $row["name"]; ?></option>
                              <?
}
?>
                            </select>



It's intended to go inside a dropdown box but I'm having trouble getting it to grab the MySQl information.

Anyone have any suggestions?
 
Code:
<option value="<? echo $row["id"]; ?>">

check the quotes on this line, one of them appears off by your code tags above - the one after id, just delete and replace them all.

Otherwise, are you getting any errors? Trying just outputing the output without putting it into a dropdown first. ie

Code:
while($row = mysql_fetch_array($result)) {
echo $row["id"].' '; 
echo $row["name"].'<br>'; 
}

check your error.log file in your home directory and the directory where the php file is, any errors there?

Finally, this has to be in a file with an extension of php like something.php (not .htm or .html).
 
Last edited:
Also check that you're actually connecting to a database! If you haven't done that, you can't call the script - and as the thedorf said, it needs to be on a PHP page (unless you have some tricky mod_rewrite going to make .html parse as .php).

Cheers,
Niggles
 
If you are doing mysql querys and would like to debug, try this
Code:
mysql_query($sql) or die(mysql_error());
if there was any error (db not connected etc) it ends scripts work and shows you a error message :)
 
Back
Top