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
Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.