Reputation: 522
i am trying to store user records into my table user , there is a strange problem happening right now which all data is stored but not the address
record.
here is my form code
function RegisterUser($firstName,$LastName,$Gender,$Address,$phoneNumber,$mobileNumber,$facebookAccount,$userName,$password,$emailAddress) {
$dob = $_POST['Year'] . '-' . $_POST['Month'] . '-' .$_POST['Day'];
$insertVisitor = "INSERT INTO user (userFirstName,userLastName,userDateOfBirth,userGender,userAddress,userPhoneNumber,userMobileNumber,userFacebookAccount,userUserName,userPassword,userEmailAddress) VALUES ('$FirstName','$LastName','$dob','$Gender','$Address','$phoneNumber','$mobileNumber','$facebookAccount','$userName','$password','$emailAddress')";
mysql_query("$insertVisitor") or die (mysql_error());
}
i made sure of the following
the form field address
is textarea
and the same name is variable $Address
on my action file.
in mysql database , the record userAdddress is text type and has default 0 length.
what is it i did wrong ?
Upvotes: 0
Views: 59
Reputation: 2986
The function gets $Address
and in your query you try to get $address
which are 2 different variables since the PHP variables are case sensitive.
Upvotes: 1
Reputation: 349062
You are referring to $address
in the SQL, while the parameter says $Address
.
Variables are case-sensitive.
function RegisterUser($firstName,$LastName,$Gender,$Address, ...
^
$insertVisitor = "INSERT INTO user .... ,'$address','$phoneNumber', .. )"
^
Quick note (possible mysql-injection aside): $insertVisitor
is already a string, so you don't have to quote it again:
mysql_query("$insertVisitor") or die(mysql_error());
mysql_query($insertVisitor) or die(mysql_error()); //<--
Upvotes: 2
Reputation: 360742
First thing you did wrong was open yourself to a gaping SQL injection hole.
Second thing is that PHP variables are case sensitive. Your function's argument list has $Address
(capital A), and you're using $address
(small A) in the query string. So you're using a completely different variable, which doesn't exist, causing PHP to auto-instantiate it as a blank value.
Upvotes: 2
Reputation: 55
Your text field for userAddress should have a length greater than 0 - try setting it to what you would expect for an address such as 100 characters.
Upvotes: 1