clarkson Posted April 29, 2013 Share Posted April 29, 2013 This is my php page where form data is sent to and data is added to database.With this I radio button data doesn't get inserted.Also I tried to modify this using mysqli_real escape(). with the function <?phpfunction safe($value){ return mysql_real_escape_string($value);}?> and in code as$username = safe($_POST["username"]); $password = safe($_POST["password"]); But then no data gets inserted to database and errors occur.I am completely new to this so any help please? This is my code.Why doesn't radio button data get inserted? <?phpsession_start();// If user is logged in, header them awayif(isset($_SESSION["username"])){exit();}$connect=mysqli_connect("localhost","root","","cs1");//check cnnectionif (mysqli_connect_errno($connect)){echo "Failed to connect database".mysqli_connect_error();exit();}$username=$_POST["username"];$password1=$_POST["password1"];$password2=$_POST["password2"];$gender=$_POST["gender"];$sql="INSERT INTO users (username,email,password1,password2,gender) VALUES ('$username','$_POST[email]','$password1','$password2','$gender' )";$query = mysqli_query($connect, $sql); Link to comment Share on other sites More sharing options...
jeffman Posted April 29, 2013 Share Posted April 29, 2013 (edited) Have you tried var_dump($_POST) to see if your script even receives the button data? Have you checked for mysqli errors following the query? Edited April 29, 2013 by Deirdre's Dad Link to comment Share on other sites More sharing options...
clarkson Posted April 29, 2013 Author Share Posted April 29, 2013 Yes I tried var_dump($_POST);Then I get this printedarray(5) { ["username"]=> string(3) "der" ["email"]=> string(15) "dfg@hotmail.com" ["password1"]=> string(3) "dse" ["password2"]=> string(3) "dse" ["gender"]=> string(4) "male" }That means my script receives button data right? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 29, 2013 Share Posted April 29, 2013 How do you know the data is not getting saved in the database? You should check for errors after you do the insert to see if MySQL returned an error. Link to comment Share on other sites More sharing options...
clarkson Posted April 29, 2013 Author Share Posted April 29, 2013 In the localhost database when I check my users table no data for gender field(which is the radio button) doesn't get inserted Link to comment Share on other sites More sharing options...
justsomeguy Posted April 29, 2013 Share Posted April 29, 2013 And that is a field that can hold a string of text? Have you checked for MySQL errors? Link to comment Share on other sites More sharing options...
clarkson Posted April 29, 2013 Author Share Posted April 29, 2013 (edited) Sorry what's MYSQL errors?When I try to use my safe function with mysql_real_escape_string() I get error as Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\new\root\functions\safe.phpon line 3.But that's not elated to the radio button problem Edited April 29, 2013 by clarkson Link to comment Share on other sites More sharing options...
justsomeguy Posted April 29, 2013 Share Posted April 29, 2013 Errors that happen with MySQL. Error messages do not automatically get printed, you need to check if an error happened and print the message. mysqli_query returns false if an error happened. http://www.php.net/manual/en/mysqli.error.php Link to comment Share on other sites More sharing options...
clarkson Posted April 29, 2013 Author Share Posted April 29, 2013 I typed if (!mysqli_query($connect,$sql )) { printf("Errormessage: %s\n", mysqli_error($connect));} and entered dummy values for mu form.then It gets printed this thing,Errormessage: Duplicate entry 'pgh-fth@gmail.com' for key 2 Link to comment Share on other sites More sharing options...
justsomeguy Posted April 29, 2013 Share Posted April 29, 2013 That means you have a primary or unique index on your table and you're trying to add duplicate data. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now