...bump...
Ok well I've been working on another way to accomplish this and I came up with this... The only problem is whenever I submit to update the database, it doesn't do anything... Nothing in the error_log to tell me why it's doing this...
view.php (works fine)
<?php
/*
VIEW.PHP
Displays all data from 'namestable' table
*/
// connect to the database
include('../connect-db.php');
// get results from database
$result = mysql_query("SELECT * FROM namestable")
or die(mysql_error());
// display data in table
echo "<p><b>View All</b> | <a href='view-paginated.php?page=1'>View Paginated</a></p>";
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>Date</th> <th>Time</th> <th>Event</th> <th>Officer 1</th> <th>Officer 2</th> <th>Officer 3</th> <th>Officer 4</th> <th>Officer 5</th> <th>Officer 6</th> <th>Officer 7</th> <th>Officer 8</th> <th>Officer 9</th> <th>Officer 10</th> <th></th> <th></th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['date'] . '</td>';
echo '<td>' . $row['time'] . '</td>';
echo '<td>' . $row['event'] . '</td>';
echo '<td>' . $row['name1'] . '</td>';
echo '<td>' . $row['name2'] . '</td>';
echo '<td>' . $row['name3'] . '</td>';
echo '<td>' . $row['name4'] . '</td>';
echo '<td>' . $row['name5'] . '</td>';
echo '<td>' . $row['name6'] . '</td>';
echo '<td>' . $row['name7'] . '</td>';
echo '<td>' . $row['name8'] . '</td>';
echo '<td>' . $row['name9'] . '</td>';
echo '<td>' . $row['name10'] . '</td>';
echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
echo "</tr>";
}
// close table>
echo "</table>";
?>
edit.php
<?php
// creates the edit record form
// since this form is used multiple times in this file, I have made it a function that is easily reusable
function renderForm($id, $date, $time, $event, $name1, $name2, $name3, $name4, $name5, $name6, $name7, $name8, $name9, $name10, $error)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Edit Events</title>
</head>
<body>
<?php
// if there are any errors, display them
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
<div>
<p><strong>ID:</strong> <?php echo $id; ?></p>
<strong>Date: </strong> <input type="text" name="date" value="<?php echo $date; ?>"/><br/>
<strong>Time: </strong> <input type="text" name="time" value="<?php echo $time; ?>"/><br/>
<strong>Event: </strong> <input type="text" name="event" value="<?php echo $event; ?>"/><br/>
<strong>Officer 1: </strong> <input type="text" name="name1" value="<?php echo $name1; ?>"/><br/>
<strong>Officer 2: </strong> <input type="text" name="name2" value="<?php echo $name2; ?>"/><br/>
<strong>Officer 3: </strong> <input type="text" name="name3" value="<?php echo $name3; ?>"/><br/>
<strong>Officer 4: </strong> <input type="text" name="name4" value="<?php echo $name4; ?>"/><br/>
<strong>Officer 5: </strong> <input type="text" name="name5" value="<?php echo $name5; ?>"/><br/>
<strong>Officer 6: </strong> <input type="text" name="name6" value="<?php echo $name6; ?>"/><br/>
<strong>Officer 7: </strong> <input type="text" name="name7" value="<?php echo $name7; ?>"/><br/>
<strong>Officer 8: </strong> <input type="text" name="name8" value="<?php echo $name8; ?>"/><br/>
<strong>Officer 9: </strong> <input type="text" name="name9" value="<?php echo $name9; ?>"/><br/>
<strong>Officer 10: </strong> <input type="text" name="name10" value="<?php echo $name10; ?>"/><br/>
<input type="submit" name="submit" value="Submit">
</div>
</form>
</body>
</html>
<?php
}
// connect to the database
include('../connect-db.php');
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit']))
{
// confirm that the 'id' value is a valid integer before getting the form data
if (is_numeric($_POST['id']))
{
// get form data, making sure it is valid
$id = $_POST['id'];
$date = mysql_real_escape_string(htmlspecialchars($_POST['date']));
$time = mysql_real_escape_string(htmlspecialchars($_POST['time']));
$event = mysql_real_escape_string(htmlspecialchars($_POST['event']));
$name1 = mysql_real_escape_string(htmlspecialchars($_POST['name1']));
$name2 = mysql_real_escape_string(htmlspecialchars($_POST['name2']));
$name3 = mysql_real_escape_string(htmlspecialchars($_POST['name3']));
$name4 = mysql_real_escape_string(htmlspecialchars($_POST['name4']));
$name5 = mysql_real_escape_string(htmlspecialchars($_POST['name5']));
$name6 = mysql_real_escape_string(htmlspecialchars($_POST['name6']));
$name7 = mysql_real_escape_string(htmlspecialchars($_POST['name7']));
$name8 = mysql_real_escape_string(htmlspecialchars($_POST['name8']));
$name9 = mysql_real_escape_string(htmlspecialchars($_POST['name9']));
$name10 = mysql_real_escape_string(htmlspecialchars($_POST['name10']));
renderForm($id, $date, $time, $event, $name1, $name2, $name3, $name4, $name5, $name6, $name7, $name8, $name9, $name10, $error);
}
else
{
// save the data to the database
mysql_query("UPDATE namestable SET date='$date', time='$time', event='$event', name1='$name1', name2='$name2', name3='$name3', name4='$name4', name5='$name5', name6='$name6', name7='$name7', name8='$name8', name9='$name9', name10='$name10' WHERE id='$id'")
or die(mysql_error());
// once saved, redirect back to the view page
header("Location: view.php");
}
}
else
{
// if the 'id' isn't valid, display an error
echo 'Error!';
}
// query db
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM namestable WHERE id=$id")
or die(mysql_error());
$row = mysql_fetch_array($result);
// check that the 'id' matches up with a row in the databse
if($row)
{
// get data from db
$id = $row['id'];
$date = $row['date'];
$time = $row['time'];
$event = $row['event'];
$name1 = $row['name1'];
$name2 = $row['name2'];
$name3 = $row['name3'];
$name4 = $row['name4'];
$name5 = $row['name5'];
$name6 = $row['name6'];
$name7 = $row['name7'];
$name8 = $row['name8'];
$name9 = $row['name9'];
$name10 = $row['name10'];
// show form
renderForm($id, $date, $time, $event, $name1, $name2, $name3, $name4, $name5, $name6, $name7, $name8, $name9, $name10, $error, '');
}
else
// if no match, display result
{
echo "No results!";
}
?>
can't figure it out for the life of me o.O