Jump to content

display sql data on webpage with php


ma5ect

Recommended Posts

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);
?>

Link to comment
Share on other sites

<?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);
?> 

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

<?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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.