i'm currently creating a page in which a user could store values(10+ fields) on his recently created table(user defined). I had set the table on a session handler so that i could retrieve it on the next couple of pages. If he proceed to a next page, that page will show his previously added values using mysql_fetch_array() and give him an option to edit values one by one. My problem is that, when i retrieve the values and put in on a textbox's value, the page will return an error. Anyway, here's my codes:
This is the 2nd page, assuming we've been through posting values
Code: Select all
if ([color=#400000]$_REQUEST[/color][[color=#408000]'FirstYear'[/color]] = [color=#408000]"done"[/color]) {
include [color=#408000]'conn.php'[/color];
[color=#400000]$sessionNewCurrName[/color] = [color=#400000]$_SESSION['newcurrname'][/color];
[color=#400000]$retFirstSem[/color] = mysql_query([color=#408000]"SELECT * FROM $sessionNewCurrName WHERE subj_sem = 1 AND subj_level = 1 AND subj_desc != ''"[/color]);
while ([color=#400000]$FirstSem[/color] = mysql_fetch_array([color=#400000]$retFirstSem[/color])) {
echo "<tr>";
echo " <td width='8%' style=\"background:#ffffff; color:#333333; padding-left: 5px;\"> [color=#400000]$FirstSem[subj_code][/color] </td>";
echo " <td width='20%' style=\"background:#ffffff; color:#333333; padding-left: 5px;\"> [color=#400000]$FirstSem[subj_desc][/color] </td>";
echo " <td width='8%' style=\"background:#ffffff; color:#333333; padding-left: 5px;\"> [color=#400000]$FirstSem[lec_hrs][/color] </td>";
echo " <td width='8%' style=\"background:#ffffff; color:#333333; padding-left: 5px;\"> [color=#400000]$FirstSem[lab_hrs][/color] </td>";
echo " <td width='8%' style=\"background:#ffffff; color:#333333; padding-left: 5px;\"> [color=#400000]$FirstSem[subj_units][/color] </td>";
echo " <td width='8%' style=\"background:#ffffff; color:#333333; padding-left: 5px;\"> [color=#400000]$FirstSem[subj_preq][/color] </td>";
echo " <td><form action='".[color=#400000]$_SERVER[/color]['PHP_SELF']."?FirstYear=done&mode=makeEdit&id=[color=#400000]$FirstSem[/color][id]"."' method='post'>";
echo "<input type=submit value='Edit' class='actionNews' name='makeEdit'>";
echo "</form>";
echo "</tr>";
}
if (isset([color=#400000]$_POST[/color][[color=#408000]'makeEdit'[/color]])) {
echo "<br><br>";
//function to edit the submitted subject...located on validateAction.php
editsubj();
if(isset([color=#400000]$_POST[/color][[color=#408000]'SaveEdit'[/color]])){
[color=#400000]$editted_SubjDesc[/color] = mysql_real_escape_string([color=#400000]$_POST[/color][[color=#408000]'edittedSubjDesc'[/color]]);
[color=#400000]$editted_SubjCode[/color] = mysql_real_escape_string([color=#400000]$_POST[/color][[color=#408000]'edittedSubjCode'[/color]]);
[color=#400000]$editted_LecHrs[/color] = mysql_real_escape_string([color=#400000]$_POST[/color][[color=#408000]'edittedLecHrs'[/color]]);
[color=#400000]$editted_LabHrs[/color] = mysql_real_escape_string([color=#400000]$_POST[/color][[color=#408000]'edittedLabHrs'[/color]]);
[color=#400000]$editted_SubjUnits[/color] = mysql_real_escape_string([color=#400000]$_POST[/color][[color=#408000]'edittedSubjUnits'[/color]]);
[color=#400000]$editted_SubjPreq[/color] = mysql_real_escape_string([color=#400000]$_POST[/color][[color=#408000]'edittedSubjPreq'[/color]]);
$sql1 = "UPDATE $sessionNewCurrName SET subj_code = '$editted_SubjCode' WHERE id = '$id'";
$sql2 = "UPDATE $sessionNewCurrName SET subj_desc = '$editted_SubjDesc' WHERE id = '$id'";
$sql3 = "UPDATE $sessionNewCurrName SET lec_hrs = '$editted_LecHrs' WHERE id = '$id'";
$sql4 = "UPDATE $sessionNewCurrName SET lec_hrs = '$editted_LabHrs' WHERE id = '$id'";
$sql5 = "UPDATE $sessionNewCurrName SET subj_units = '$editted_SubjUnits' WHERE id = '$id'";
$sql6 = "UPDATE $sessionNewCurrName SET subj_preq = '$editted_SubjPreq' WHERE id = '$id'";
mysql_query($sql1);
mysql_query($sql2);
mysql_query($sql3);
mysql_query($sql4);
mysql_query($sql5);
mysql_query($sql6);
echo "<br /><br />Done Editing! Please refresh your browser to reload the page. Thank you!";
}
}
}
Code: Select all
if (!isset($_SESSION)) {
session_start();
}
//set the session handler of curriculum name
$sessionNewCurrName = $_SESSION['newcurrname'];
switch ($_REQUEST['mode']) {
case "makeEdit":
if ($_GET['id']) {
include_once '../admin_/conn.php';
[color=#FF0000]//
// THIS SECTION WHERE THE ERROR APPEARS, LINE 16
//[/color]
$id = (int)$_GET['id'];
$queryToEdit = mysql_query("SELECT * FROM $sessionNewCurrName WHERE id = '$id'");
$rowToEdit = mysql_fetch_array($queryToEdit);
function editsubj(){
print <<<HERE
<form name='EditsubjNow' action='$self?mode=makeEdit&id=$rowToEdit[id]' method='post' class='makeEditNow'>
<table>
You may now edit the selected subject below. Currently editing subject: <br /><b><i><font color='#800A0A'>$rowToEdit[subj_desc]</font></i></b>
<tr>
<td width="126" style="background:#CCCCCC; color:#333333; padding-left: 5px;"> Subj Code </td>
<td width="360" style="background:#CCCCCC; color:#333333; padding-left: 5px;"> Subj Description </td>
<td width="64" style="background:#CCCCCC; color:#333333; padding-left: 5px;"> Lec Hrs </td>
<td width="60" style="background:#CCCCCC; color:#333333; padding-left: 5px;"> Lab Hrs </td>
<td width="62" style="background:#CCCCCC; color:#333333; padding-left: 5px;"> Units </td>
<td width="106" style="background:#CCCCCC; color:#333333; padding-left: 5px;"> Pre Req </td>
</tr>
<tr>
<td width='8%' style="background:#ffffff; color:#333333; padding-left: 5px;"> <input type=text name='edittedSubjCode' size="8" value='$rowToEdit[subj_code]'> </td>
<td width='20%' style="background:#ffffff; color:#333333; padding-left: 5px;"> <input type=text name='edittedSubjDesc' size="50" value='$rowToEdit[subj_desc]'> </td>
<td width='8%' style="background:#ffffff; color:#333333; padding-left: 5px;"> <input type=text name='edittedLecHrs' size="8" value='$rowToEdit[lec_hrs]'> </td>
<td width='8%' style="background:#ffffff; color:#333333; padding-left: 5px;"> <input type=text name='edittedLabHrs' size="8" value='$rowToEdit[lab_hrs]'> </td>
<td width='8%' style="background:#ffffff; color:#333333; padding-left: 5px;"> <input type=text name='edittedSubjUnits' size="8" value='$rowToEdit[subj_units]'> </td>
<td width='8%' style="background:#ffffff; color:#333333; padding-left: 5px;"> <input type=text name='edittedSubjPreq' size="8" value='$rowToEdit[subj_preq]'> </td>
</tr>
</table>
<input type='reset' value='Clear Edits' name='clearEdit'class='qpost_button'>
<input type='submit' value='Save' name='SaveEdit' class='qpost_button' onsubmit='return EditIsEmpty(this);'>
</form>
HERE;
if ($_POST['clearEdit']) {
$rowToEdit[subj_code] = $_POST[subj_code];
$rowToEdit[subj_desc] = $_POST[subj_desc];
$rowToEdit[lec_hrs] = $_POST[lec_hrs];
$rowToEdit[lab_hrs] = $_POST[lab_hrs];
$rowToEdit[subj_units] = $_POST[subj_units];
$rowToEdit[subj_sem] = $_POST[subj_sem];
$rowToEdit[subj_preq] = $_POST[subj_preq];
}
}
}
}
and when i run it i got this error:
Code: Select all
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in Z:\xampp\site\includes\validateAction.php on [color=#FF0000]line 16[/color]
God bless us