I have a slight problem, I am trying to capture the input of two buttons, one yes, one no, into a database but for some reason the database doesn’t always show the value of the button clicked, it just shows up blank.
<form action="refer.php" method="post" id="formID" >
<div class="prompt_container" style="float: left;">
<span class="prompt_item"><input type="image" src="images/yes.jpg"
alt="submit" value="yes" onclick="this.disabled=true,this.form.submit();"
/></span>
<input type="hidden" name="refer" value="yes">
</div>
</form>
<form action="thank_you.php" method="post" id="formID" >
<div class="prompt_container" style="float: right;">
<span class="prompt_item"><input type="image" src="images/no.jpg"
alt="submit" value="no" onclick="this.disabled=true,this.form.submit();"
/></span>
<input type="hidden" name="refer" value="no" >
</div>
</form>
Here is the code that writes it all to the database
session_start();
$name = $_SESSION['name'];
$tel = $_SESSION['tel'];
$email = $_SESSION['email'];
$refer = $_POST['refer'];
$curDate = date("Y-m-d");
mysql_connect ("host", "user", "pass") or die ('Error: ' . mysql_error());
mysql_select_db ("database");
$query = "INSERT INTO Table (id, name, tel, email, refered, date)
VALUES('NULL', '".$name."', '".$tel."', '".$email."', '".$refer."', '".$curDate."')";
mysql_query($query) or die (mysql_error());
Apparently anything lower than IE8 will ignore the value attribute of all <input type="image"> form inputs.
How could I get this to work properly in all browsers? jQuery or Javascript maybe?
The problem is presumably that given a click at co-ordinates (1,2) on:
IE will pass:
where other browsers will pass:
So to make image inputs work cross-browser you need to be sniffing for the existence of the
name.xparameter and not merelyname.If you need to have two different image buttons, that means they will need to have two separate names instead of relying on different
values that might not get parsed:And then at the server side check for the existence of parameters
foo.bar.xandfoo.bof.x.[edit re: edit]
This won’t work. Without a
nameattribute, theimageinput isn’t a successful control, so thevaluewon’t be passed, and co-ordinate data may not be passed either.Both hidden inputs will be submitted, regardless of which
imageis clicked. The successfulness of theimageinput doesn’t affect the successfulness of any otherhiddenelement.That’s some pretty dangerous SQL injection there. You should make friends with
mysql_real_escape_stringor parameterised queries.