Jump to content

change from submit to image type stops post working.


Lawlssbatmbl

Recommended Posts

Ive been working on a simple web form

I wanted to replace the basic submit button with icon images , but for some reason my posts dont seem to work now.

Can you offer some solutions.

  echo "<table align=\"center\" width=\"500\" border=\"0\" background=\"images/FormBG.png\">";
  echo "<tr><td colspan=\"5\" height=\"50\"><font size=\"5\">Excision Type</font><td></tr>";
  echo "<tr><th>ID</th><th>Type</th><th>Name</th></tr>";
  
  while ($stmt->fetch())
  { 
     echo "<form method=\"post\" action=\"excision.php\"> ";
     echo "<tr><td><input name=\"excision_id\" type=\"hidden\" value=" . $excision_id . ">" . $excision_id . "</td>" ;
	 echo     "<td><input name=\"excision_type\" type=\"text\" value=" . $excision_type . "></td>";
	 echo     "<td><input name=\"excision_name\" type=\"text\" value=" . $excision_name . "></td>";
	 echo     "<td><input name=\"edit\" src=\"/IC/images/Clipboard 3.png\" type=\"image\" style=\"height:24px; width:24px \" value=\"Edit\"></td>";
	 echo     "<td><input name=\"delete\" src=\"/IC/images/Close - Cancel 1.png\" type=\"image\" style=\"height:24px; width:24px \" value=\"Delete\"></td></tr>";
	 echo "</form>";
  }
  echo "<form method=\"post\" action=\"excision.php\"> ";
  echo "<tr><td> </td>" ;
  echo "    <td><input name=\"a_excision_type\" type=\"text\"></td>";
  echo "    <td><input name=\"a_excision_name\" type=\"text\"></td>"; 
  echo "    <td><input name=\"add\" src=\"/IC/images/Add Green.png\" type=\"image\" style=\"height:24px; width:24px \" value=\"Add\"></td>";
  echo "    <td></td></tr>";
  echo "</form>" ;
  echo "</table>" ;

Heres the example of the post code higher up in the same php script.

  if (ISSET($_POST['add']))
  {
     $exc_type = mysqli_real_escape_string($db,$_POST['a_excision_type']);
	 $exc_name = mysqli_real_escape_string($db,$_POST['a_excision_name']);
     
	
	 if (strlen($exc_type) > 20)
		 fail('Excision Type too long (MAX : 20 characters)');
	 if (strlen($exc_name) > 45)
		 fail('Excision Name too long (MAX : 45 characters)');

	    ($astmt = $db->prepare('insert into excision_type (excision_type, excision_name) values (?,?)'))
		    || fail('MySQL prepare', $db->error);
	     $astmt->bind_param('ss', $exc_type, $exc_name)
		    || fail('MySQL bind_param', $db->error);
	     if (!$astmt->execute()) 
		 {
            /* Figure out why this failed - maybe the username is already taken?
             * It could be more reliable/portable to issue a SELECT query here.  We would
             * definitely need to do that (or at least include code to do it) if we were
             * supporting multiple kinds of database backends, not just MySQL.  However,
             * the prepared statements interface we're using is MySQL-specific anyway. */
		    if ($db->errno === 1062 /* ER_DUP_ENTRY */)
		   	   fail('This Excision Type is already taken.');
		    else
			   fail('MySQL execute', $db->error);
		 }	   
  }

I know the code works when I use the type="submit" so its not a syntax issue , I suspect that changing type from "submit" to "image" has some suttle differences. 

On excision.php you need to do a print_r($_POST) to see what the buttons are named.  Instead of "add"  you'll have two like "add_x" and "add_y" and the values will be the coordinates of the image that were clicked.  Most likely in excision.php you're checking for $_POST['add'] or something similar.

On the add form you could set a hidden input named "add" since that's the only possibility for that form, but that won't help you on the edit/delete form because that hidden input won't let you know which button was clicked.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.