beginnerprogrammer Posted December 22, 2011 Share Posted December 22, 2011 I need to complete a nonline system.. The problem is I can't insert the module value into the database.. can someone help me?? The module will appear based on the system selected. Both module and system are from the database. This is the coding at the main page. <td>Sistem</td> <td>:</td> <td> <select name="system_name" size="1" id="system_name" onChange="showCustomer(this.value)"> <option>- select -</option> <option value = "asis ">ASIS</option> <option value = "gais ">GAIS</option> <option value = "ifas ">IFAS</option> <option value = "sais ">SAIS</option> <option value = "persis ">PERSIS</option> </select> </td> </tr> <tr> <td>Modul</td> <td>:</td> <td> <?php //$sql="SELECT module_name FROM system WHERE system_name='".$q."'"; //$result1= mysql_query($sql); echo"<select name=\"module_name\" id=\"module_name\">\n"; echo "<option value= \"none\"> - select - </option>\n"; /*do{ echo "<option value=\""; echo $row_systemname['module_name']; echo "\">"; echo $row_systemname['module_name']; echo "</option>\n"; }while ($row_systemname= mysql_fetch_assoc($result1));*/ echo "</select>"; $_SESSION['module_name'] = $_POST['module_name']; ?> * The AJAX used to connect to a page (out.php) to output the module menu. <script type="text/javascript"> function showCustomer(str) { var xmlhttp; if (str=="") { document.getElementById("module_name").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("module_name").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","out.php?q="+str,true); xmlhttp.send(); } </script> The coding to output the module (out.php) <?php session_start(); include('db_connect.php'); //echo "<form action=\"borang0.php\" method=\"post\">"; $q=$_GET["q"]; //$system_name=$_POST['system_name']; $sql="SELECT module_name FROM system WHERE system_name='".$q."'"; $result1= mysql_query($sql); //$option=""; //echo"<select name=\"module_name\" id=\"module_name\">\n"; echo "<option value= \"none\"> - select -</option>\n"; do{ echo "<option value=\""; echo $row_systemname['module_name']; echo "\">"; echo $row_systemname['module_name']; echo "</option>\n"; }while ($row_systemname= mysql_fetch_assoc($result1)); echo "</select>"; //$modul = $_POST['modul_name']; //$_SESSION['modul']=$modul; //echo "</form>"; ?> and here is the code to link to database <?php session_start(); include ('db_connect.php'); if(isset($_POST['submit'])) { //$id=($_POST['id']); $choice=($_POST['choice']); $staff_no= $_SESSION['user_login']['staff_no']; $tel=($_POST['tel']); $date= ($_POST['date']);; $time= ($_POST['time']); $system=($_POST['system_name']); $modul=$_SESSION['module_name']; $description=($_POST['description']); //$status=($_POST['status']); if ($choice == 0){ $query="INSERT INTO aduan (staff_no,tel,date,time,system,modul,description) VALUES ('$staff_no','$tel','$date','$time','$system','$modul','$description')"; $result=mysql_query($query); if($result){ echo 'Registration success.'; ?><script>window.location ='thanks.php'</script> <?php } else echo 'Registration failed';} else { $query="INSERT INTO permohonan (staff_no,tel,date,time,system,modul,description) VALUES ('$staff_no','$tel','$date','$time','$system','$modul','$description')"; $result=mysql_query($query); if($result){ echo 'Registration success.'; ?><script>window.location ='thanks.php'</script> <?php } else echo 'Registration failed';} } ?> really hope for someone's help.. Quote Link to comment https://forums.phpfreaks.com/topic/253661-cant-insert-into-the-database/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.