By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,348 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,348 IT Pros & Developers. It's quick & easy.

display sql data on webpage with php

P: 77
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]
<?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">&nbsp;</td>
<td><input type="submit" value="Insert record" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Recordset2);
?> [/PHP]
Oct 9 '08 #1
Share this Question
Share on Google+
4 Replies


Markus
Expert 5K+
P: 6,050
Isn't the code you provided the code that inserts the data into the database? And didn't you say the database was getting updated? If yes to both of these, we need to see the code that pulls the data from the database and displays it. Otherwise, ... where's the coffee?
Oct 9 '08 #2

P: 77
Isn't the code you provided the code that inserts the data into the database? And didn't you say the database was getting updated? If yes to both of these, we need to see the code that pulls the data from the database and displays it. Otherwise, ... where's the coffee?

lol..
sorry..

code:

[PHP]<?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">&nbsp;</td>
<td><input type="submit" value="Insert record" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Recordset2);
?> [/PHP]
Oct 9 '08 #3

P: 77
wrong one..

correct code

[PHP]<?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);
?>[/PHP]
Oct 9 '08 #4

Markus
Expert 5K+
P: 6,050
Ok, you've kind of selected the data from the database, but how are you displaying it? Or is that the problem you have - displaying the data?

If so, check out this.
Oct 9 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.