flashx Posted November 8, 2010 Share Posted November 8, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/218090-database-only-accepts-numbers-why/ Share on other sites More sharing options...
gizmola Posted November 8, 2010 Share Posted November 8, 2010 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')"; Quote Link to comment https://forums.phpfreaks.com/topic/218090-database-only-accepts-numbers-why/#findComment-1131704 Share on other sites More sharing options...
flashx Posted November 8, 2010 Author Share Posted November 8, 2010 gizmola you rock my world!! thanks for pointing that out! its all working now, much appreciated!! Quote Link to comment https://forums.phpfreaks.com/topic/218090-database-only-accepts-numbers-why/#findComment-1131705 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.