I have a php form that is adding information to my sql database, i need it to only accept numbers in the text box.
This is my php form
<form id="MakeBid" action="MakeBid.php" method="POST">
<input type="hidden" name="propertyID" value="1" />
<div>Bid Now
<input type="text" name="pricesoldfor" />
</div>
<input id="submit" input type="submit" value="Submit" />
</form>
Client-side for feedback without loading, you can do something like
(I’ve written this example inline – as your form will probably be larger, I would advise you not to use the attribute onsubmit and instead attach a proper event handler. Have a look at preventDefault() as well as this is usually a better alternative to
return false.)What you will really need to do is validate in your PHP (server-side) that it is only numbers before you save it to the database. For example like this:
Bear in mind both of these will only allow full numbers (integers), so no “35.43” or similar. Have a look at is_numeric()