I am trying to store '$phone' as in my SQL database however if i set the COLUMN type as 'INT' in phpmyadmin, no data is entered. as soon as i change the COULMN type to 'VARCHAR' the data can then be pushed
in form.php:
<fieldset>
<input placeholder="Your Phone Number" type="text" name="phone" value="<?= $phone ?>" tabindex="4">
<span class="error"><?= $phone_error ?></span>
</fieldset>
$phone is declared in formprocess.php :
$fname_error = $lname_error = $email_error = $phone_error = $job_error = $nameauth_error = $privacy_error = $decline_error = "";
$fname = $lname = $email = $phone = $message = $jobtitle = $nameauth = $success = $privacy = "";
if (empty($_POST["phone"])) {
$phone_error = "Phone is required";
} else {
$phone = test_input($_POST["phone"]);
// check if e-mail address is well-formed
if (!preg_match("/^(\d[\s-]?)?[\(\[\s-]{0,2}?\d{3}[\)\]\s-]{0,2}?\d{3}
[\s-]?\d{4}$/i",$phone)) {
$phone_error = "Invalid phone number";
}
}`
if ($privacy == 'agree') {
if ($fname_error == '' and $lname_error == '' and $email_error == '' and $phone_error == '' and $privacy_error == '' and $nameauth_error == '' and $job_error == '')
{
$sql = "INSERT INTO data (phoneNo) VALUES ('$phone');";
mysqli_query($con, $sql);
$success = "Enjoy your game!!";
$fname = $lname = $email = $phone = $message = $jobtitle = $nameauth = "";
}
} else if ($privacy == '') {
$privacy_error = "Please Accept or Decline Our Policy";
} else if ($privacy == 'disagree') {
$decline_error = "Please Accept Our Privacy Policy to Continue";
}
}
this code works perfect if the column datatype in phpmyadmin is varchar but breaks if i use INT
Does it have to do with the fact that i initialise the variable as ="" which makes it a varchar?
Do i have to initialize my INT values as =0; ?