+ 9

How to submit html form answer to database?.......

I had maded a HTML form on my website with radio buttons where user have to submit the form by choosing anyone answer yes or no ........ BUT after this I don't know to submit the answer to database I WANT THE TO BE SUBMITTED IN NUMBERS AS IF ONE USER SUBMIT YES THEN IN DATABASE THE YES SHOULD GET THE VALUE 1 OR IF TWO USER CLICKED ON NO AND SUBMIT THEN THE NO SHOULD GET THE VALUE 2

21st Apr 2017, 10:32 AM
Rohit
Rohit - avatar
6 Réponses
+ 7
hey Guys can u give me the codes for my action.php
21st Apr 2017, 1:40 PM
Rohit
Rohit - avatar
+ 7
I had written this code can you tell what is wrong in it index.html ______________________________________________ <!DOCTYPE html> <html> <head> </head> <body> <form action="db.php" method="post"> YES:<input type="text" name="first_name" value="first_name" > NO:<input type="text" name="last_name" value="last_name" > <input type="submit" name="submit value="submit"> </form> </body> <html> __________________________:-___________________ ********************************************** db.php <?php $con = mysqli_connect('localhost','MY user id','MYpassword'); if(!con) { echo 'not connected to server';} if(!mysqli_select_db($con,'my database name') { echo 'Database error selection';} $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $sql = INSERT INTO users (first_name,last_name) VALUES ('$first_name','$last_name'); if(!mysqli_query($con,$sql)) { echo 'Answer not submitted please try again!!!!!!!!';} else{ echo 'Your answer successfully submitted \n Thanks for participating';} header(" refresh:2; url=index.html"); ?>
21st Apr 2017, 2:28 PM
Rohit
Rohit - avatar
+ 4
both of them are right. You must know the algorithms for doing these things against a database for you page to work properly.
21st Apr 2017, 1:37 PM
Siddharth Saraf
+ 1
you can assigh the value submittet by the form to the radio button as 1/ true or 0/false Gender: <input type="radio" name="answer" value="1">YES <input type="radio" name="answer" value="0">NO with php you can send sql queries to store the submitted values (1 or 0) to a database. In the database you can define the input type for every column (text, char, date, int ecc....)
21st Apr 2017, 12:03 PM
seamiki
seamiki - avatar
+ 1
you can also post your data to index ... like this : <html> <body> <?php if(isset($_REQUEST['name'])) { echo $_REQUEST['name']; } ?> <form action='' method='post'> <input type="text" name"name"> <input type="submit"> </form> </body> </html> this is sample code of my mean. the word "$_REQUEST" used for get data from POST & GET method.
29th Aug 2017, 4:58 PM
Mohammad Zarchi
Mohammad Zarchi - avatar
0
I think you've to do some php in action attribute <form action="action.php"></form>, now you gotta put mysql and submit script into action.php, did web work long back.
21st Apr 2017, 10:47 AM
John Watson
John Watson - avatar