Reputation: 1395
am trying to fetch some data from a form, but i cant for some reason. here are some lines of my code.
cellphone: <input type = "text" name = "cellphone"><br />
username : <input type = "text" name = "username"><br />
$cellphone = $_GET["cellphone"]; //$cellphone = int() $cellphone; $username= $_GET["username"]; $link = mysql_connect('myhost', 'myuser', 'mypass') or die("could not connect to database"); mysql_select_db ('hunter',$link) or die ("could not find database"); echo "fetced database"; //injecting user info into database mysql_query("INSERT INTO player values ('','$firstname','$lastname','$location','$cellphone','$username','$email','$password')")or die("could not inject into database.");
but i can not get the cell number to get into my database for some reason. please help me :D
Upvotes: 0
Views: 5224
Reputation: 157828
Upvotes: 2
Reputation: 23749
FIRST:
you should must sanitize all incoming variables!
then, to cast to an integer, you can use:
$cellphone = (int) $_GET["cellphone"];
A better solution is to use filter_var();
$cellphone = filter_var( $_GET["cellphone"], FILTER_VALIDATE_INT);
You should read about input validation/sanitazion and filter_var before writing any further code.
now, before people start to advice mysql_real_escape_string()
(which does the job, but is not the best solution), take a look at prepared statements through either PDO or MySQLi
Upvotes: 3
Reputation: 8091
this may be that your mysql column only accepts INT but input is alphanumeric. in this case, you may use $cellphone = filter_var($_GET['cellphone'], FILTER_SANITIZE_NUMBER_INT);
if you are expecting an integer-only input
Upvotes: 1
Reputation: 23208
By the way, if you store a phone number as an integer you cant handle very well the international prefix (+39 or 0039 for Italy for example), as "+" is not a number, and "00" would be lost in the cast to integer ....
Upvotes: 1