Mike, send to me the whole file to ezzat @ safe-mail.net and mention your table field names in database, i 'll get working onto this.
Ok received.. and err..it was a bit complicated, do not worry I tested everything on localhost.
Well, basically, what you want it one file , edit.php which called the tutorial ID as i understand, and allow doing changes. It can submit info to itself, and if no form is submitted at first glance, it will just show the form.
Lets get this clear, you should have a file called
config.php contains database variables as regular;
you should also have a file called
form.html contains your html form as below exactly:
<form method="post" action="edit.php?tut=<?php echo $tut; ?>">
Title: <input name="title" value="<?php echo $title; ?>"><br>
Preview: <input name="preview" value="<?php echo $preview; ?>"><br>
Description: <textarea name="description"><?php echo
$description; ?></textarea><br />
Tutorial: <textarea name="tutorial"><?php echo $tutorial;
?></textarea><br />
Author: <input name="author" value="<?php echo $author; ?>"><BR />
<input type="submit" value="Save" name="submit">
</form>
at last you should have this only in your edit.php file:
<?php
if (isset($_REQUEST['tut'])) {
$tut = $_REQUEST['tut'];
}
// set your database infomation
include 'config.php';
// connect to the mysql database server
$connect = mysql_connect($dbhost, $dbusername, $dbuserpass);
// select the database
mysql_select_db($dbname, $connect) or die(mysql_error());
// sql query
$result = mysql_query("SELECT * FROM tutorials WHERE id='$tut'");
$row = mysql_fetch_array($result);
extract($row);
// define POST
$title = $_POST['title'];
$preview = $_POST['preview'];
$description = $_POST['description'];
$tutorial = $_POST['tutorial'];
$author = $_POST['author'];
if (isset($title) && isset($preview) && isset($description) && isset($tutorial) && isset($author)) {
$update_data = mysql_query("UPDATE tutorials SET title='$title',
preview='$preview', description='$description', tutorial='$tutorial',
author='$author' WHERE id='$tut'");
echo "Updated record!";
include 'form.html';
} else {
include 'form.html';
}
?>
Set these up together in one directory and test. But wait,
I recognized a new field ID in table tutorials, it should get the id number from url and get the info according to ID not tutorial, and that was a little mistake.
Just go to your table structure make sure you have the following structure
field 1 - id int(25) PRIMARY KEY--important--
field 2 - title Whatever varchar or text you like, this is your choice
field 3 - preview
field 4 - description
field 5 - tutorial
field 6 - author
Remember id is a new field. ID is primary key, ID is integer. id is assigned $_GET['tut'] meaning If you called edit.php?tut=12 it would find that
$tut = $_REQUEST['tut'] // value in this case 12;
Then run the statement where tutorial ID is 12
Hope that cleared it up :tu: