Hi All,
I am struggling to get the correct information from mysql db to my php page.
My page has an Index page:
Like this: index.php:
[php]<?php
require “dbinfo.php”;
$sql=“SELECT * FROM stats”;
$result = mysql_query($sql, $db) or die (mysql_error());
$pageTitle = “My Stats Database”;
include “header.php”;
print <<<HERE
My Contacts
Select a Record to update add new stat.<input type="submit" name="update" value=" Edit " |
Description: $descr, Type: $type Department Head: $depthead Test Analyst: $person |
HERE;
}
print "
?>
[/php]
Then it has the actual adding of the stats:
Here: addstats.php:
[php]<?php
if($_POST[‘submit’]=“Submit”)
//if(isset($_POST[‘submit’]))
{
$type = cleanData($_POST[‘type’]);
$depthead = cleanData($_POST['depthead']);
$person = cleanData($_POST['person']);
$descr = cleanData($_POST['descr']);
$recdate = cleanData($_POST['recdate']);
$tolog = cleanData($_POST['tolog']);
$senttorev = cleanData($_POST['senttorev']);
$recfromrev = cleanData($_POST['recfromrev']);
//print "Data Cleaned";
addData($type, $depthead, $person, $descr, $recdate, $tolog, $senttorev, $recfromrev);
}
else
{
printForm();
}
function cleanData($data){
$data = trim($data);
$data = stripcslashes($data);
$data = htmlspecialchars($data);
$data = strip_tags($data);
return $data;
}
function addData ($type, $depthead, $person, $descr, $recdate, $tolog, $senttorev, $recfromrev)
{
//print “ready to add data”;
include(“dbinfo.php”);
include(“header.php”);
$sql=“INSERT INTO stats VALUES (null, ‘$type’, ‘$depthead’, ‘$person’, ‘$descr’, ‘$recdate’,
‘$tolog’, ‘$senttorev’, ‘$recfromrev’)”;
$result=mysql_query($sql) or die(mysql_error());
print <<<HERE
You have added the following
- Type: $type
- Deptartment Head: $depthead
- Test Analyst: $person
- Description: $descr
- Received Date: $recdate
- Date to log: $tolog
- Sent to Rev: $senttorev
- Received from Revision : $recfromrev
function printform(){
$pagetitle = “Add Stats”;
include(“header.php”);
print <<<HERE
Add Stats Here
?>
[/php]
Then it has the updating of the stats: updateform.php this is where I am stuck beyond belief:
[php]<?php
require"dbinfo.php";
$sel_record = $_POST[‘sel_record’];
//$sel_record = (isset($_POST[‘sel_record’])) ? $_POST[‘sel_record’] : ‘’;
$sql = “SELECT * FROM stats WHERE id = ‘$sel_record’”;
//execute sql query and get result
$result = mysql_query($sql, $db) or die (mysql_error());
if (!$result) {
print "
Something went wrong!
";} else
{ //begin while loop
while ($record = mysql_fetch_array($result, MYSQL_ASSOC)){
$id = $record['id'];
$type = $record['type'];
$depthead = $record['depthead'];
$person = $record["person"];
$descr = $record["descr"];
$recdate = $record["recdate"];
$tolog = $record["tolog"];
$senttorev = $record["senttorev"];
$recfromrev = $record["recfromrev"];
}
}
//end while loop
$pagetitle = “Edit Stat”;
include “header.php”;
print <<<HERE
<h2> Modify this Stat</h2>
<p> Change the values in the boxes and click "Modify Record" button </p>
<form id="myform" method="POST" action="update.php">
<input type="hidden" name="id" value="$id">
?>
[/php]
and the then update portion istself:
[php]<?php
include “dbinfo.php”;
$id = $_POST['id'];
$type = $_POST['type'];
$depthead = $_POST['depthead'];
$person = $_POST['person'];
$descr=$_POST['descr'];
$recdate=$_POST['recdate'];
$tolog=$_POST['tolog'];
$senttorev=$_POST['senttorev'];
$recfromrev=$_POST['recfromrev'];
$sql="UPDATE stats SET
type='$type',
depthead='$depthead',
person='$person',
descr='$descr',
recdate='$recdate',
tolog='$tolog',
senttorev='$senttorev',
recfromrev='$recfromrev'
WHERE id='$id' ";
$result=mysql_query($sql) or die (mysql_error());
print "<html><head><title>Update Results</titlel></head><body>";
include "header.php";
print <<<HERE
<h1>The new Record looks like this: </h1>
<td>
<p><strong>Type: </strong>$type</p>
<p><strong>Department Head: </strong>$depthead</p>
<p><strong>Test Analyst: </strong> $person</p>
<p><strong>Description: </strong>$descr</p>
<p><strong>Received Date:</strong>$recdate</p>
<p><strong>Date to Log:</strong>$tolog</p>
<p><strong>Sent to rev:</strong>$senttorev</p>
<p><strong>Received from Rev:</strong>$recfromrev</p>
<br/>
HERE;
[/php]
My problem is when I select the “edit” record on the index.php page I get the wrong information to my updateform.php screen. I don’t know why, I have tried everything that I know of. Does not matter which record I select I keep on getting the same numbered one.
Please see fi you can help me with this?
Thanking you in advance.