How to insert a value from radio button in mysql

Thread Solved

Join Date: Oct 2009
Posts: 25
Reputation: garcon1986 is an unknown quantity at this point 
Solved Threads: 0
garcon1986 garcon1986 is offline Offline
Light Poster

How to insert a value from radio button in mysql

 
0
  #1
Oct 26th, 2009
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
  1. <div id="form">
  2. <form method="post" action="process.php">
  3. <h1>BESOIN </h1>
  4. <br><br>
  5. <label>Sujet:</label><input type="text" name="sujet" />&nbsp;&nbsp;
  6. <label>Date: </label><input type="text" name="bdate" class="datepicker" id="datepicker1">&nbsp;&nbsp;
  7. <label>Nature:</label>
  8. <input type="radio" name="nature" id="nature" value="exprime" >Exprime</input>
  9. <input type="radio" name="nature" id="nature" value="non"/>Non Exprime<br><br>
  10. <h4>Action:</h4>
  11. <br>
  12. <label>Date de l'action: </label>
  13. <input type="text" name="adate" class="datepicker" id="datepicker2">
  14. <label>Date de l'alerte: </label>
  15. <input type="text" name="aldate" class="datepicker" id="datepicker3"><br><br>
  16. <label>Etat: </label>
  17. <select>
  18. <option name="etat" value="ready">Ready</option>
  19. <option name="etat" value="transacting">Transacting</option>
  20. <option name="etat" value="finished"/>Finished</option>
  21. </select><br><br>
  22. <label>Detail: </label><br>
  23. <textarea rows="5" cols="40" name="adetail"></textarea>
  24. <br><br>
  25. <h4>Qualification: </h4>
  26. <br>
  27. <label>Date: </label>
  28. <input type="text" name="qdate" class="datepicker" id="datepicker4"><br><br>
  29. <label>Detail: </label><br>
  30. <textarea rows="5" cols="40" name="qdetail"></textarea>
  31. <br><br>
  32. <h4>Proposition: </h4>
  33. <br>
  34. <label>Date: </label>
  35. <input type="text" name="pdate" class="datepicker" id="datepicker5" /><br><br>
  36. <label>Detail: </label><br>
  37. <textarea rows="5" cols="40" name="pdetail"></textarea>
  38. <br><br>
  39. <label>Nom du decideur: </label>
  40. <input type="text" name="decideur" />
  41. <br><br>
  42. <input type="submit" name="submit" value="submit"/>
  43. </form>
  44. </div>

process.php
  1. <div id="wcontent">
  2. <?php
  3. $conne = mysql_connect($server, $user, $password) or die(mysql_error());
  4. mysql_select_db($db);
  5.  
  6. $query = "INSERT INTO besoin
  7. (sujet, bdate, nature, adate, aldate, etat, adetail, qdate, qdetail, pdate, pdetail, decideur)
  8. 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]')";
  9. $result = mysql_query($query) or die("Query failed: ".mysql_error());
  10. /* if($result){
  11. echo "<p>Input data succeed!</p>";
  12. } else{
  13. echo "<p>Input data failed!</p>";
  14. }
  15. */
  16. echo "<p><a href=\"besoinlist.php\" >Back to Besoin list</a></p>";
  17.  
  18. ?>
  19. </div>

Error:

  1. Notice: Undefined index: bdate in process.php on line 26
  2.  
  3. Notice: Undefined index: nature in process.php on line 26
  4.  
  5. Notice: Undefined index: etat in process.php on line 26
  6.  
  7. Notice: Undefined index: adetail in process.php on line 26
  8.  
  9. Notice: Undefined index: qdate in process.php on line 26
  10.  
  11. Notice: Undefined index: qdetail in process.php on line 26
  12.  
  13. Notice: Undefined index: pdate in process.php on line 26
  14.  
  15. Notice: Undefined index: pdetail in process.php on line 26
  16.  
  17. Notice: Undefined index: decideur in process.php on line 26
  18.  
  19. 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
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 25
Reputation: garcon1986 is an unknown quantity at this point 
Solved Threads: 0
garcon1986 garcon1986 is offline Offline
Light Poster
 
0
  #2
Oct 26th, 2009
I'm sorry, it's not checkbox, it's combobox. Now i fixed it. And i'm also working on "radio button".

Any idea is welcomed.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 12
Reputation: paranjyoti is an unknown quantity at this point 
Solved Threads: 2
paranjyoti paranjyoti is offline Offline
Newbie Poster
 
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']."')";
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 12
Reputation: paranjyoti is an unknown quantity at this point 
Solved Threads: 2
paranjyoti paranjyoti is offline Offline
Newbie Poster
 
1
  #4
Oct 26th, 2009
  1. $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']."')";
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 25
Reputation: garcon1986 is an unknown quantity at this point 
Solved Threads: 0
garcon1986 garcon1986 is offline Offline
Light Poster
 
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 :

  1. CREATE TABLE IF NOT EXISTS besoin(
  2. id int(11) NOT NULL AUTO_INCREMENT,
  3. sujet varchar(255),
  4. bdate date,
  5. nature tinyint,
  6. adate date,
  7. aldate date,
  8. etat varchar(255),
  9. adetail varchar(10000),
  10. qdate date,
  11. qdetail varchar(10000),
  12. pdate date,
  13. pdetail varchar(10000),
  14. dicideur varchar(255),
  15. PRIMARY KEY(id)
  16. );

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???
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 551
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
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
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 25
Reputation: garcon1986 is an unknown quantity at this point 
Solved Threads: 0
garcon1986 garcon1986 is offline Offline
Light Poster
 
0
  #7
Oct 27th, 2009
Originally Posted by network18 View Post
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
yes, but why not use varchar for text that is less than 65535 bytes.
because i think text is limited in mysql database.

and my sql code about date, should be something like this? :
  1. bdate datetime

I don't know if i'm right. Welcome for your correction.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 551
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 25
Reputation: garcon1986 is an unknown quantity at this point 
Solved Threads: 0
garcon1986 garcon1986 is offline Offline
Light Poster
 
0
  #9
Oct 27th, 2009
Originally Posted by network18 View Post
yes, you can use varchar like varchar(600) but for storing date you are supposed to use date/datetime type only.
Ok. Thanks a lot dude.
Reply With Quote Quick reply to this message  
Reply

Tags
button, mysql, radio

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC