0

I'm trying to insert registration data into a database but my php code isn't inserting the values into the DB although I'm not getting any errors either, can someone help me? this is the code i'm currently using:

$connect = mysql_connect("localhost","myusername","mypassword");
mysql_select_db("application");

$queryreg = mysql_query('INSERT INTO users("username","password","email","date") VALUES("$username","$password","$email","$date")');

die ("You Have Been Registered.");

I just need to add the username password email and date into the fields i have specified but it won't work, please someone help!

1
  • In PHP, variables don't get resolved in single quote strings. They do in double quote strings. So as noted below, you can do it with single quotes and . operators, or do it with double quotes and escape all quotes within your code. Commented Feb 9, 2011 at 15:24

2 Answers 2

1

change this line

 $queryreg = mysql_query("INSERT INTO users(username,password,email,date)
 VALUES('".$username."','".$password."','".$email."','".$date."')");

check error

if (mysql_errno()) { 
    die('Invalid query: ' . mysql_error());
}
Sign up to request clarification or add additional context in comments.

9 Comments

I've done that but it still isn't inserting the data into the DB ):
Yeah ;o "Column count doesn't match value count at row 1"
The fields in my database are "id username password email joined admin vip" if that helped
in the table users, do you have more fields , mandatory (could not be null)
can you publish the create table
|
0

Here is a good reference for connecting and doing an insert into a database using PHP and MySQL W3Schools PHP MySQL Insert. From the looks of it you need to remove the "s around username, password, email and date like Haim Evgi mentioned. Also I would try closing the connection if you are finished with it. Here is a code sample from the site:

$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin', '35')");

mysql_query("INSERT INTO Persons (FirstName, LastName, Age) 
VALUES ('Glenn', 'Quagmire', '33')");

mysql_close($con);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.