Jump to content

Issue in adding radio button data to database


clarkson

Recommended Posts

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

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 by Deirdre's Dad
Link to comment
Share on other sites

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

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 by clarkson
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...