I have a course table in the database which stores course information (i.e. code, name, date and description). Admin is allowed to update the course information. Let's assume that a course information is already in my database and the admin intends to update the course info.
When he heads to the Update page (pls see managemodule.php), my page will show him a dropdown options with a list of courses that are in the database. He will then choose a particular course from the dropdown list and then the course information will be shown (achieved thru' ajax) in different HTML input fields (info is output thru. the placeholder attr.).
What I want to achieve here is that, admin can update whatever info they want in the input fields directly, and when he presses 'update', these data will be sent over and update in my database.
However I failed to do so. I know it's the problem of the ajax code in managemodule.js. The course table in the database has 4 columns which is code, name, date and description
managemodule.php:
<form id="moduleform" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<h2 class="fs-title">Module Info Update</h2>
<p>Please select a module for more information:</p><br />
<select id="modulelist" name="module" onchange="showModuleInfo(this.value)">
<option>-- Select a module --</option>
<option value="CS2102">Database Systems</option> ***hard coded here for simplicity*****
</select>
<?php ****This php part is not updating my course table********
if(isset($_POST['update']))
{
mysql_query("UPDATE module SET code = '".$_POST['update_moduleCode']."' ");
}
?>
<div id="moduleinfo"><b><-- Module info will be listed here --></b></div>
</form>
managemodule.js:
function showModuleInfo(str)
{
if (str == "")
{
document.getElementById("moduleinfo").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("moduleinfo").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","moduleinfo.php?q="+str,true);
xmlhttp.send();
}
moduleinfo.php
session_start();
$q = $_GET['q'];
$result = mysql_query("SELECT * FROM module WHERE code = '".$q."'");
while($row = mysql_fetch_array($result))
{
echo '<input type="text" name="update_moduleCode" placeholder="Module Code" value="'.$row['code'].'" required />';
echo '<input type="text" name="update_moduleTitle" placeholder="Module Name" value="'.$row['name'].'" required />';
echo '<textarea name="update_moduleDescription" rows="14" placeholder="Module Description" required></textarea><br />';
echo '<input type="submit" name="update" class="next action-button" value="Update" />';
*****I guess this 'Update' button is not passing the user input to my managemodule.php
}
The php part in managemodule.php above is not working (means it doesnt update my course table). I guess it is because the 'Update' button is not passing user input to managemodule.php. I used $_POST['update_moduleCode'] wanted to get the value from moduleinfo.php but I didnt manage to get.
So how am I supposed to pass the input from moduleinfo.php to managemodule.php
index.htmlor somethingaction="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"from your<form>and see what happens when you change the module again."?q="+strand don't need it. You putstrinside ofsend()if you're usingPOST- so your new code will bexmlhttp.open("POST", "moduleinfo.php", true); xmlhttp.send(str);