| | |
How to insert a value from radio button in mysql
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 25
Reputation:
Solved Threads: 0
Hello everyone,
I've searched a lot of time today for a solution, but not succeed!
I want to insert value from the radio button and checkbox into mysql database.
Here is my code:
insert.php
process.php
Error:
Does anyone can give me the guidance. Thanks very much!!!
I've searched a lot of time today for a solution, but not succeed!
I want to insert value from the radio button and checkbox into mysql database.
Here is my code:
insert.php
PHP Syntax (Toggle Plain Text)
<div id="form"> <form method="post" action="process.php"> <h1>BESOIN </h1> <br><br> <label>Sujet:</label><input type="text" name="sujet" /> <label>Date: </label><input type="text" name="bdate" class="datepicker" id="datepicker1"> <label>Nature:</label> <input type="radio" name="nature" id="nature" value="exprime" >Exprime</input> <input type="radio" name="nature" id="nature" value="non"/>Non Exprime<br><br> <h4>Action:</h4> <br> <label>Date de l'action: </label> <input type="text" name="adate" class="datepicker" id="datepicker2"> <label>Date de l'alerte: </label> <input type="text" name="aldate" class="datepicker" id="datepicker3"><br><br> <label>Etat: </label> <select> <option name="etat" value="ready">Ready</option> <option name="etat" value="transacting">Transacting</option> <option name="etat" value="finished"/>Finished</option> </select><br><br> <label>Detail: </label><br> <textarea rows="5" cols="40" name="adetail"></textarea> <br><br> <h4>Qualification: </h4> <br> <label>Date: </label> <input type="text" name="qdate" class="datepicker" id="datepicker4"><br><br> <label>Detail: </label><br> <textarea rows="5" cols="40" name="qdetail"></textarea> <br><br> <h4>Proposition: </h4> <br> <label>Date: </label> <input type="text" name="pdate" class="datepicker" id="datepicker5" /><br><br> <label>Detail: </label><br> <textarea rows="5" cols="40" name="pdetail"></textarea> <br><br> <label>Nom du decideur: </label> <input type="text" name="decideur" /> <br><br> <input type="submit" name="submit" value="submit"/> </form> </div>
process.php
PHP Syntax (Toggle Plain Text)
<div id="wcontent"> <?php $conne = mysql_connect($server, $user, $password) or die(mysql_error()); mysql_select_db($db); $query = "INSERT INTO besoin (sujet, bdate, nature, adate, aldate, etat, adetail, qdate, qdetail, pdate, pdetail, decideur) VALUES('$_POST[sujet]','$_POST[bdate]','$_POST[nature]','$_POST[adate]','$_POST[aldate]','$_POST[etat]','$_POST[adetail]','$_POST[qdate]','$_POST[qdetail]','$_POST[pdate]','$_POST[pdetail]','$_POST[decideur]')"; $result = mysql_query($query) or die("Query failed: ".mysql_error()); /* if($result){ echo "<p>Input data succeed!</p>"; } else{ echo "<p>Input data failed!</p>"; } */ echo "<p><a href=\"besoinlist.php\" >Back to Besoin list</a></p>"; ?> </div>
Error:
PHP Syntax (Toggle Plain Text)
Notice: Undefined index: bdate in process.php on line 26 Notice: Undefined index: nature in process.php on line 26 Notice: Undefined index: etat in process.php on line 26 Notice: Undefined index: adetail in process.php on line 26 Notice: Undefined index: qdate in process.php on line 26 Notice: Undefined index: qdetail in process.php on line 26 Notice: Undefined index: pdate in process.php on line 26 Notice: Undefined index: pdetail in process.php on line 26 Notice: Undefined index: decideur in process.php on line 26 Input data succeed!
Does anyone can give me the guidance. Thanks very much!!!
Last edited by garcon1986; Oct 26th, 2009 at 11:01 am. Reason: complete the question, add some errors code
•
•
Join Date: Nov 2007
Posts: 12
Reputation:
Solved Threads: 2
0
#3 Oct 26th, 2009
Hi,
Replace the insert query with this one and see if it works.
$query = "INSERT INTO besoin (sujet, bdate, nature, adate, aldate, etat, adetail, qdate, qdetail, pdate, pdetail, decideur) VALUES('".$_POST['sujet']."','".$_POST['bdate']."','".$_POST['nature']."','".$_POST['adate']."','".$_POST['aldate']."','".$_POST['etat']."','".$_POST['adetail']."','".$_POST['qdate']."','".$_POST['qdetail']."','".$_POST['pdate']."','".$_POST['pdetail']."','".$_POST['decideur']."')";
Replace the insert query with this one and see if it works.
$query = "INSERT INTO besoin (sujet, bdate, nature, adate, aldate, etat, adetail, qdate, qdetail, pdate, pdetail, decideur) VALUES('".$_POST['sujet']."','".$_POST['bdate']."','".$_POST['nature']."','".$_POST['adate']."','".$_POST['aldate']."','".$_POST['etat']."','".$_POST['adetail']."','".$_POST['qdate']."','".$_POST['qdetail']."','".$_POST['pdate']."','".$_POST['pdetail']."','".$_POST['decideur']."')";
•
•
Join Date: Nov 2007
Posts: 12
Reputation:
Solved Threads: 2
1
#4 Oct 26th, 2009
PHP Syntax (Toggle Plain Text)
$query = "INSERT INTO besoin (sujet, bdate, nature, adate, aldate, etat, adetail, qdate, qdetail, pdate, pdetail, decideur) VALUES('".$_POST['sujet']."','".$_POST['bdate']."','".$_POST['nature']."','".$_POST['adate']."','".$_POST['aldate']."','".$_POST['etat']."','".$_POST['adetail']."','".$_POST['qdate']."','".$_POST['qdetail']."','".$_POST['pdate']."','".$_POST['pdetail']."','".$_POST['decideur']."')";
•
•
Join Date: Oct 2009
Posts: 25
Reputation:
Solved Threads: 0
0
#5 Oct 26th, 2009
Thanks for paranjyoti's help. But it seems like the former result.
I don't know whether i'm right or not.
And this is my table :
And when the property of column bdate is "tinyint". The value for bdate is always 0.
And now i change it to varchar(255).
And it works.
Thanks a lot for your help, paranjyoti!!!
And I wonder if the type must be varchar()??? Can anyone give me a clue???
I don't know whether i'm right or not.
And this is my table :
PHP Syntax (Toggle Plain Text)
CREATE TABLE IF NOT EXISTS besoin( id int(11) NOT NULL AUTO_INCREMENT, sujet varchar(255), bdate date, nature tinyint, adate date, aldate date, etat varchar(255), adetail varchar(10000), qdate date, qdetail varchar(10000), pdate date, pdetail varchar(10000), dicideur varchar(255), PRIMARY KEY(id) );
And when the property of column bdate is "tinyint". The value for bdate is always 0.
And now i change it to varchar(255).
And it works.
Thanks a lot for your help, paranjyoti!!!
And I wonder if the type must be varchar()??? Can anyone give me a clue???
•
•
Join Date: Sep 2009
Posts: 557
Reputation:
Solved Threads: 64
0
#6 Oct 27th, 2009
If you want to store the date in the db use 'date' as a type;
for 'date and time both' =>'Datetime'
for 'texts and words' =>'Text'
for 'variable strings'=>'Varchar'
for storing integer numbers=>'int'
and so on
for 'date and time both' =>'Datetime'
for 'texts and words' =>'Text'
for 'variable strings'=>'Varchar'
for storing integer numbers=>'int'
and so on
"The discipline of writing something down is the first step towards making it happen."
follow me on twitter
follow me on twitter
•
•
Join Date: Oct 2009
Posts: 25
Reputation:
Solved Threads: 0
0
#7 Oct 27th, 2009
•
•
•
•
If you want to store the date in the db use 'date' as a type;
for 'date and time both' =>'Datetime'
for 'texts and words' =>'Text'
for 'variable strings'=>'Varchar'
for storing integer numbers=>'int'
and so on
because i think text is limited in mysql database.
and my sql code about date, should be something like this? :
PHP Syntax (Toggle Plain Text)
bdate datetime
I don't know if i'm right. Welcome for your correction.
•
•
Join Date: Sep 2009
Posts: 557
Reputation:
Solved Threads: 64
0
#8 Oct 27th, 2009
yes, you can use varchar like varchar(600) but for storing date you are supposed to use date/datetime type only.
"The discipline of writing something down is the first step towards making it happen."
follow me on twitter
follow me on twitter
![]() |
Similar Threads
- Map, Radio Button, and Coordinates (Java)
- Hiding tablerow based on radio button selection (ASP.NET)
- get the value of radio button and save into database (PHP)
- make a radio button checked if it was selected before (PHP)
- sending radio button to database (PHP)
- Radio button insert and retrieve (PHP)
- Dynamically pass column value to database based on radio button selection (ASP.NET)
Other Threads in the PHP Forum
- Previous Thread: (!$var)
- Next Thread: how to have numbering in display
Views: 1241 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for button, mysql, radio
"use" .net access amazon api apple archive array asp autoincrement beginner box button buttons buyouts c# cache cakephp calculator calendar check click cms cookies data database date display download ec2 email embed enter error exists file flash form forms gdi+ glassfish google html ibm if...loop image ingres innerjoins insert intro iphone java javascript jquery jsp keyword keywords links linux list load mail mergers montywidenius msqli_multi_query multiple mysql mysql.data.client mysqlinternalqueries mysqlquery opendatabasealliance oracle order panorama parameter php phpmyadmin pointers programming python query radio ram remote remove results save search select server sp sqlserver startup sun swf threading timespan unicode update view






