Jump to content

Database only accepts numbers, why?


flashx

Recommended Posts

hi there,

 

im new to all this stuff, so im guessing this is quite easy to fix.

 

i trying to get php to create a new user in a form in myphpadmin, however it seems to only accept numbers, does anyone know why?

 

here is my code for php:

<?php //begin

$host = localhost;
$dbuser = user;
$dbpass = pw;
$dbname = dbname;

$connection = mysql_connect($host, $dbuser, $dbpass);
$db = mysql_select_db($dbname, $connection);

//grab data from form
$name = $_POST[username];
$pass = $_POST[password];
$pass_conf = $_POST[pass_conf];
$email = $_POST[email];


if($name == false || $pass == false || $pass_conf == false || $email == false){
echo "Please fill in all required fields.";
};

if($pass != $pass_conf){
echo "Passwords do not match";
}else{
$connection = mysql_connect($host, $dbuser, $dbpass);
$db = mysql_select_db($dbname, $connection);
$sql = "INSERT INTO user (username,password,email) VALUES ($name, $pass, $email)";
$result = mysql_query($sql);
echo "Thank you for your registration to YOURSITENAME.com";
};

?>

 

 

and here is my form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>


<form name=reg action=do_reg.php method=post>
    Username: <input name=username type=text /><br />
    Password: <input type=password name=password /><br />
    Confirm: <input type=password name=pass_conf /><br />
    Email: <input type="text" name=email /><br />

  <input type="submit" value='Register' />
</form>


</body>
</html>


 

 

any help would be great!

Link to comment
https://forums.phpfreaks.com/topic/218090-database-only-accepts-numbers-why/
Share on other sites

The type of data you're inserting needs to match the datatypes of the columns in your table definition. 

 

With that said:

 

"INSERT INTO user (username,password,email) VALUES ($name, $pass, $email)";

 

Is clearly wrong, assuming that username, password and email are char or varchar columns.  You need quotes around these in the VALUES statement.

 

"INSERT INTO user (username,password,email) VALUES ('$name', '$pass', '$email')";

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.