ma5ect Posted October 9, 2008 Share Posted October 9, 2008 Hi ppl, I am trying to insert records into my database using a form. this works. but after this i would like the records to be displayed onto another page.. the database gets updated but the webpage i want the data to be displayed remains empty....any suggestions.. code so far. <?php require_once('Connections/mysql_connect.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) { $insertSQL = sprintf("INSERT INTO `assignment submission sheet` (`Student number`, `Pathway / Course`, `Essay only`, `Marking tutor name`, `Module unit title`, `Module number`, `Assignment title`) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['Student_number'], "int"), GetSQLValueString($_POST['Pathway__Course'], "text"), GetSQLValueString($_POST['Essay_only'], "int"), GetSQLValueString($_POST['Marking_tutor_name'], "text"), GetSQLValueString($_POST['Module_unit_title'], "text"), GetSQLValueString($_POST['Module_number'], "text"), GetSQLValueString($_POST['Assignment_title'], "text")); mysql_select_db($database_mysql_connect, $mysql_connect); $Result1 = mysql_query($insertSQL, $mysql_connect) or die(mysql_error()); $insertGoTo = "gygyui.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO `assignment submission sheet` (`Student number`, `Pathway / Course`, `Essay only`, `Marking tutor name`, `Module unit title`, `Module number`, `Assignment title`) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['Student_number'], "int"), GetSQLValueString($_POST['Pathway__Course'], "text"), GetSQLValueString($_POST['Essay_only'], "int"), GetSQLValueString($_POST['Marking_tutor_name'], "text"), GetSQLValueString($_POST['Module_unit_title'], "text"), GetSQLValueString($_POST['Module_number'], "text"), GetSQLValueString($_POST['Assignment_title'], "text")); mysql_select_db($database_mysql_connect, $mysql_connect); $Result1 = mysql_query($insertSQL, $mysql_connect) or die(mysql_error()); $insertGoTo = "gygyui.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_mysql_connect, $mysql_connect); $query_Recordset2 = "SELECT * FROM `assignment submission sheet`"; $Recordset2 = mysql_query($query_Recordset2, $mysql_connect) or die(mysql_error()); $row_Recordset2 = mysql_fetch_assoc($Recordset2); $totalRows_Recordset2 = mysql_num_rows($Recordset2); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right">Student number:</td> <td><input name="Student_number" type="text" value="" size="32" maxlength="7" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Pathway / Course:</td> <td><input name="Pathway__Course" type="text" value="" size="32" maxlength="30" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Essay only:</td> <td><input name="Essay_only" type="text" value="" size="32" maxlength="7" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Marking tutor name:</td> <td><input name="Marking_tutor_name" type="text" value="" size="32" maxlength="25" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Module unit title:</td> <td><input name="Module_unit_title" type="text" value="" size="32" maxlength="30" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Module number:</td> <td><input name="Module_number" type="text" value="" size="32" maxlength="10" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Assignment title:</td> <td><input name="Assignment_title" type="text" value="" size="32" maxlength="30" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input type="submit" value="Insert record" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> <p> </p> </body> </html> <?php mysql_free_result($Recordset2); ?> Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted October 9, 2008 Share Posted October 9, 2008 You should post the code for the page that is displaying the results... Quote Link to comment Share on other sites More sharing options...
ma5ect Posted October 9, 2008 Author Share Posted October 9, 2008 <?php require_once('Connections/mysql_connect.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) { $insertSQL = sprintf("INSERT INTO `assignment submission sheet` (`Student number`, `Pathway / Course`, `Essay only`, `Marking tutor name`, `Module unit title`, `Module number`, `Assignment title`) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['Student_number'], "int"), GetSQLValueString($_POST['Pathway__Course'], "text"), GetSQLValueString($_POST['Essay_only'], "int"), GetSQLValueString($_POST['Marking_tutor_name'], "text"), GetSQLValueString($_POST['Module_unit_title'], "text"), GetSQLValueString($_POST['Module_number'], "text"), GetSQLValueString($_POST['Assignment_title'], "text")); mysql_select_db($database_mysql_connect, $mysql_connect); $Result1 = mysql_query($insertSQL, $mysql_connect) or die(mysql_error()); $insertGoTo = "gygyui.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO `assignment submission sheet` (`Student number`, `Pathway / Course`, `Essay only`, `Marking tutor name`, `Module unit title`, `Module number`, `Assignment title`) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['Student_number'], "int"), GetSQLValueString($_POST['Pathway__Course'], "text"), GetSQLValueString($_POST['Essay_only'], "int"), GetSQLValueString($_POST['Marking_tutor_name'], "text"), GetSQLValueString($_POST['Module_unit_title'], "text"), GetSQLValueString($_POST['Module_number'], "text"), GetSQLValueString($_POST['Assignment_title'], "text")); mysql_select_db($database_mysql_connect, $mysql_connect); $Result1 = mysql_query($insertSQL, $mysql_connect) or die(mysql_error()); $insertGoTo = "gygyui.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_mysql_connect, $mysql_connect); $query_Recordset2 = "SELECT * FROM `assignment submission sheet`"; $Recordset2 = mysql_query($query_Recordset2, $mysql_connect) or die(mysql_error()); $row_Recordset2 = mysql_fetch_assoc($Recordset2); $totalRows_Recordset2 = mysql_num_rows($Recordset2); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right">Student number:</td> <td><input name="Student_number" type="text" value="" size="32" maxlength="7" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Pathway / Course:</td> <td><input name="Pathway__Course" type="text" value="" size="32" maxlength="30" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Essay only:</td> <td><input name="Essay_only" type="text" value="" size="32" maxlength="7" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Marking tutor name:</td> <td><input name="Marking_tutor_name" type="text" value="" size="32" maxlength="25" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Module unit title:</td> <td><input name="Module_unit_title" type="text" value="" size="32" maxlength="30" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Module number:</td> <td><input name="Module_number" type="text" value="" size="32" maxlength="10" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Assignment title:</td> <td><input name="Assignment_title" type="text" value="" size="32" maxlength="30" /></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input type="submit" value="Insert record" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> <p> </p> </body> </html> <?php mysql_free_result($Recordset2); ?> Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted October 9, 2008 Share Posted October 9, 2008 All I see there is the form to insert the data... I also see the SELECT from the db, but you are not displaying them anywhere... Am I missing something? Quote Link to comment Share on other sites More sharing options...
ma5ect Posted October 9, 2008 Author Share Posted October 9, 2008 oops dat was same code as above... correct code:: <?php require_once('Connections/mysql_connect.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_mysql_connect, $mysql_connect); $query_Recordset2 = "SELECT * FROM `assignment submission sheet`"; $Recordset2 = mysql_query($query_Recordset2, $mysql_connect) or die(mysql_error()); $row_Recordset2 = mysql_fetch_assoc($Recordset2); $totalRows_Recordset2 = mysql_num_rows($Recordset2); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> </body> </html> <?php mysql_free_result($Recordset2); ?> Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted October 9, 2008 Share Posted October 9, 2008 <?php require_once('Connections/mysql_connect.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_mysql_connect, $mysql_connect); $query_Recordset2 = "SELECT * FROM `assignment submission sheet`"; $Recordset2 = mysql_query($query_Recordset2, $mysql_connect) or die(mysql_error()); $row_Recordset2 = mysql_fetch_assoc($Recordset2); $totalRows_Recordset2 = mysql_num_rows($Recordset2); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <table> <tr><td>Field 1</td><td>Field 2</td><td>Field 3</td><td>Field 4</td><td>Field 5</td><td>Field 6</td></tr> <?php do { ?> <tr><td><?php $row_Recordset2['Student number']; ?></td><td><?php $row_Recordset2['Pathway / Course']; ?></td><td><?php $row_Recordset2['Essay only']; ?></td><td><?php $row_Recordset2['Marking tutor name']; ?></td><td><?php $row_Recordset2['Module unit title']; ?></td></tr> <?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?> </table> </body> </html> <?php mysql_free_result($Recordset2); ?> That should get you started... I only did the first 5 fields, and just slammed them into a table. Hope that helps Quote Link to comment Share on other sites More sharing options...
ma5ect Posted October 9, 2008 Author Share Posted October 9, 2008 still doesnt display any results...just blank Quote Link to comment Share on other sites More sharing options...
F1Fan Posted October 9, 2008 Share Posted October 9, 2008 You're calling mysql_fetch_assoc() before your while statement. That is essentially strip the first row. Quote Link to comment Share on other sites More sharing options...
ma5ect Posted October 9, 2008 Author Share Posted October 9, 2008 still no luck... Quote Link to comment Share on other sites More sharing options...
F1Fan Posted October 9, 2008 Share Posted October 9, 2008 Ah, sorry. I didn't look at your code closely enough. You're not echoing your data. Replace: <?php $row_Recordset2['Student number']; ?> with: <?php echo $row_Recordset2['Student number']; ?> Quote Link to comment Share on other sites More sharing options...
ma5ect Posted October 9, 2008 Author Share Posted October 9, 2008 genius Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted October 9, 2008 Share Posted October 9, 2008 Yeah, I think the while is fine... I just forgot the echo because I'm a dunce Good catch! Quote Link to comment 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.