Bader H Al Rayyes
Bader H Al Rayyes

Reputation: 522

one record doesn't store into mysql db

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

what is it i did wrong ?

Upvotes: 0

Views: 59

Answers (4)

Kypros
Kypros

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

Rob W
Rob W

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

Marc B
Marc B

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

user1152631
user1152631

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

Related Questions