Thanks Celauran,
I get the following error: Duplicate entry '2147483647' for key 'PRIMARY'
FYI - my primary key is cmn (mobile number) and '2147483647' is the mobile number in the first row.
i get this error even if i enter any other mobile number (say 5555555555) in the mobile number field
if i remove mobile number as the primary key, the table updates with new data but replaces my any other number with '2147483647'
this has helped me get a bit closer at identifying the problem, but am clueless about the reason why this is happening.
Any ideas ?
my form code looks somewhat like this:
Code: Select all
<form name="cform" class='form' action='' method='POST' accept-charset='UTF-8' onsubmit="return rvalidateForm()">
<label>Your Name </label> <input type='text' name='cname' maxlength="20" /> <br/>
<label> Location</label> <?php include('statedropdown.php'); ?> <br/><div id="txtHint"><select name='clocation'><option value="">Select your City</option></select> </div> <br/>
<label>Does your Location have our branch </label>
<select name='cbranch'> <br/><option value="">Select</option><option value="Yes">Yes</option> <option value="No">No</option><option value="dont know">Don't Know</option> </select>
<label>Your Email</label> <input type='text' name='cemail' maxlength="40" /><br/>
<label>10 digit Mobile Number</label> <input type='int' name='cmn' maxlength="10"/><br/>
<input class='button' type='submit' name='submit' value='SUBMIT'/>
</form> <!-- Form Code Ends -->
<!-- Form JS Validation Start -->
<script type="text/javascript"> function rvalidateForm() { var x=document.forms["cform"]["cname"].value; if (x==null || x=="") { alert("Name must be filled out"); return false; }var x=document.forms["cform"]["rstate"].value; if (x==null || x=="" ) { alert("Select your state"); return false; } var x=document.forms["cform"]["cbranch"].value; if (x==null || x=="") { alert("Please Answer if your location has a blood bank"); return false; } var x=document.forms["cform"]["cemail"].value; var atpos=x.indexOf("@"); var dotpos=x.lastIndexOf("."); if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {alert("Not a valid e-mail address"); return false; } var x=document.forms["cform"]["cmn"].value; if (x==null || x=="" || x.length>10 || x.length<10 || !x.toString().match(/^[-]?\d*\.?\d*$/)) {alert("Mobile number must be valid"); return false; } var y=document.forms["cform"]["cmn"].value; if (y.toString().match(/^0+[^0]+/)) { alert("Please do not enter 0 in the beginning of your mobile number"); return false; } } </script>
<!-- Form JS Validation Ends -->
<?php if (isset($_POST['submit']))
{
$cname= $_POST['cname']; $clocation= $_POST['clocation']; $cbranch = $_POST['cbranch']; $cemail= $_POST['cemail']; $cmn= $_POST['cmn'];
// php side form validation begins
function check_input($data)
{ $data = trim($data); $data = strip_tags($data); $data = stripslashes($data); $data = htmlspecialchars($data); $data = mysql_real_escape_string($data);
return $data; } //custom function to trim, stripslash and remove html chars
$cname= check_input($_POST['cname']); $cbranch = check_input($_POST['cbranch']); $cemail= check_input($_POST['cemail']); $cmn= check_input($_POST['cmn']); $clocation= check_input($_POST['clocation']); $problem="";
$br="<br/>"; //line break uh !
if(empty($cname)||empty($cbranch) || empty($cmn) || empty($clocation) || empty($cemail)) $problem ="All fields must be filled"; echo "$problem". "$br";
if (!preg_match('/^[a-zA-Z]/', $cname) ) $problem ="Please fill valid name" ; echo "$problem". "$br";
if (!preg_match('/([\w\-]+\@[\w\-]+\.[\w\-]+)/', $cemail)) $problem ="Please fill a valid email address"; echo "$problem". "$br";
if (!preg_match('/^[0-9]{10}$/', $cmn)) $problem ="Please fill a valid Mobile number"; echo "$problem". "$br";
if (empty($problem)) //if no problems insert into db and redirect to thankyou page
{ require_once ('connect.php');
//php final filters sanitization format is filter_var(variable, filter, options) -NOT WORKING AS IT SHOULD
filter_var("$cname", FILTER_SANITIZE_STRIPPED);
filter_var("$cemail", FILTER_VALIDATE_EMAIL);
filter_var("$cmn", FILTER_SANITIZE_NUMBER_INT);
//working out the current date time
date_default_timezone_set('Asia/Calcutta');
$cdt=date("y.m.d , h:i:s");
// Insert into DB after sanitization
mysql_query("INSERT INTO chapters VALUES ('$cname', '$clocation','$cbranch','$cemail','$cmn','$cdt')") or die(mysql_error());
?><script type="text/javascript"> <!--
window.location = "cthankyou.php"//–></script><?php
}}?>