Jump to content

change from submit to image type stops post working.


Lawlssbatmbl
Go to solution Solved by AbraCadaver,

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. 

Edited by Lawlssbatmbl
Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

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.

Edited by AbraCadaver
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.