Need help could anyone know how to make an image in a form act as a submit button? Would anyone know where I can get information on how to fill a drop down box with data in a mysql database? Please help please please :-/

Dani AI

Generated

As asked: you can do both — make an image submit the form and populate a drop-down from MySQL — but there are a few practical details and modern best practices worth adding to 's working example.

An image as submit

  • Easiest and most reliable: wrap an <img> in a <button type="submit"> so the server receives a normal named submit value and screen readers see a label. The older <input type="image"> works but sends click coordinates (name_x/name_y) instead of a simple value, which is awkward to handle.
  • Always include an alt or aria-label for accessibility.

Example (HTML):

<form method="post">
  <button type="submit" name="action" value="save" style="background:none;border:0;padding:0;">
    <img src="submit.png" alt="Save">
  </button>
</form>

Populating and keeping the selected value

  • 's approach of looping DB rows to emit <option> elements is fine. Make sure the value contains the ID you need and the visible text is user-friendly (for example a name instead of an ID).
  • On submit the selected option is available as $_POST['studid'] (or via filter_input). To preserve the selection when redisplaying the form, compare the current row id to the posted value and add the selected attribute.

Example (retrieval + simple validation):

$selected = filter_input(INPUT_POST, 'studid', FILTER_VALIDATE_INT);
if ($selected === false) { $selected = null; }

Security and compatibility notes

  • Do not use legacy mysql_* functions; use PDO or mysqli with prepared statements to avoid injection.
  • Escape option text with htmlspecialchars() before echoing to prevent XSS.
  • Validate numeric IDs with FILTER_VALIDATE_INT or filter_var().

For HTML input-image details see MDN: input type="image". For output escaping and PHP functions see the PHP manual: htmlspecialchars.

<select name="studid" id="jumpMenu" >
        <option value="Select">Select</option>
<?php
while($rows = mysql_fetch_array($result))
{

?>
          <option value="<?php echo $rows['userid']; ?>"><?php echo $rows['userid']; ?></option> 
 <?php
}
?>         
        </select>

i hope this cud help in filling mysql data in the drop down box..

it works for me.. try it out..

Thanks i will give it a try will this code be able to show the value if selected

ya it did show for me...

i used this for querying the database..

Thanks will give it a shot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.