954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how can i get the value of listbox?to store data in database?

here the code,

<?php

$a = $_GET['Cors'];
$b = $_GET['sem'];
$c = $_GET['yrlvl'];

mysql_connect("localhost", "root", "") or die ('Error'.mysqlerror());
mysql_select_db("sched");

$query="INSERT INTO sked (crs,sm,yrlvl) values ('".$a."','".$b."','".$c."')";

mysql_query($query) or die ('Error Cannnot Insert Records!');

?>  

<?php

the listbox is "sem", tnx
jober
Newbie Poster
5 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

You don't seem to mention the nature of the problem.

It may be that your options in the select widget (listbox) do not have a value. It is the value of the option tag that will be passed to the $_POST['sem'] variable not the text displayed in the widget.

<select id="sem">
  <option value = "Wales">Cymru</option>
  <option value = "Scotland">Alba</option>
  <option value = "Brittany">Breizh</option>
</select>


If the 'Cymru' option was selected in the listbox, then the $_POST['sem'] value will be 'Wales'.

If you are able to set the value attribute to the same as the text, this should sort it out.
If you can't do this for some reason, you could use javascript to programmatically set the value of the selected option to the displayed text prior to submission with an 'onsubmit' attribute.BTW
Your line:

$query="INSERT INTO sked (crs,sm,yrlvl) values ('".$a."','".$b."','".$c."')";


Seems a little clunky and possibly dangerous. Clean your variables before passing it to the sql query:

$a = addslashes(htmlentities($_POST[...]));
 [etc.]

$query="INSERT INTO sked SET crs = '{$a}', sm = '{$b}',yrlvl ='{$c}';


If this is not the case, come back and explain your problem.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You