Hi All,

the following code will allow you to type content, and saves it fine, but it just wont populate that paticular area with the current database entry.

Please can somebody advise.

Im sure i have missed something so simple.

<?php

$result = mysql_query("select * from `indexinfo` where id = 1");
$row = mysql_fetch_array($result);

{
?>
<form action="#" method="post">
<p><h2>EDIT ZONE 1:</h2></p>
<label>Title:<input type="text" name="Title" value="<?php echo $result['Title']; ?>" /></label><br />
<label>Subtitle: <input type="text" name="Subtitle" value="<?php echo $Subtitle; ?>" /></label><br />
<label>Content: <TEXTAREA name="Content" ROWS=10 COLS=100><?php echo $Content; ?></TEXTAREA><br />
<label>Author: <input type="text" name="Author" value="<?php echo $Author; ?>" /></label><br />
<label>Date: <input type="text" name="Date" value="<?php echo $Date; ?>" /></label><br />
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<input type="submit" value="Submit" name="send" /></p>
</form>
<?php } ?>

Where the value of

$id

. !!!!!!!!

$id is the first column name in the table. is at the end of the list as hidden.

In this example the id will always be 1

can u explain more abt the error.?
whether u checkd the db for the new value u have changed.
check whtr the query got executd corrctly..

Hi,

I think i have found something. I have forgotten to add some code.

This is the entire script

<?php

if ( isset( $_POST['send'] ) ) {

  
  $Title = $_POST['Title'];
  $Subtitle = $_POST['Subtitle'];
  $Content = $_POST['Content'];
  $Author = $_POST['Author'];
  $Date = $_POST['Date'];
  $id = $_POST['id'];

		  
		  echo $sql = "UPDATE `indexinfo` SET
          `Title` = '$Title',
          `Subtitle` = '$Subtitle',
        `Content` = '$Content',
        `Author` = '$Author',
          `Date` = '$Date'
          WHERE `id` = 1";  

  if (mysql_query($sql)) {
    echo '<p>Author details updated.</p>';
  } else {
    echo '<p>Error updating author details: ' .
        mysql_error() . '</p>';
  }

?>

<?php

$result = mysql_query("select * from `indexinfo` where id = 1");
$row = mysql_fetch_array($result);

{
?>
<form action="#" method="post">
<p><h2>EDIT ZONE <?php echo $id;?>:  </h2></p>
<label>Title:<input type="text" name="Title" value="<?php $result[] = $Title; ?>" /></label><br />
<label>Subtitle: <input type="text" name="Subtitle" value="<?php echo $Subtitle; ?>" /></label><br />
<label>Content: <TEXTAREA name="Content" ROWS=10 COLS=100><?php echo $Content; ?></TEXTAREA><br />
<label>Author: <input type="text" name="Author" value="<?php echo $Author; ?>" /></label><br />
<label>Date: <input type="text" name="Date" value="<?php echo $Date; ?>" /></label><br />

<input type="submit" value="Submit" name="send" /></p>
</form>
<?php } ?>

<?php
} else {
?>
<form action="#" method="post">
<p>EDIT ZONE 1:</p>
<label>Title: <input type="text" name="Title"  /></label><br />
<label>Subtitle: <input type="text" name="Subtitle" /></label><br />
<label>Content: <TEXTAREA name="Content" ROWS=10 COLS=100></TEXTAREA><br />
<label>Author: <input type="text" name="Author" /></label><br />
<label>Date: <input type="text" name="Date" /></label><br />
<input type="hidden" name="id" />
<input type="submit" value="Submit" name="send" /></p>
</form>
<?php } ?>

What is meant to happen is

get the record with the value of 1

populate the relevant text box with that data, which can be typed over

replace the database with what is now in the relevant cell

oopz i didnt chk tat..... nav33n was correct

Hi,

I have found the problem.

I was using the incorrect syntax after the "else" statement.

} else {

$result = mysql_query("select * from `indexinfo` where id = 1");
$row = mysql_fetch_array($result);

?>
<form action="#" method="post">
<p>EDIT ZONE  <?php echo $row['id'];?>:</p>
<label>Title: <input type="text" name="Title" value="<?php echo $row['Title'] ?> /></label><br />

Hi all,

Now its only allowing me to display the first 2 cells of information (namely id and subtitle)

thank you all for you help

<?php

if ( isset( $_POST['send'] ) ) {  
  $Title = $_POST['Title'];
  $Subtitle = $_POST['Subtitle'];
  $Content = $_POST['Content'];
  $Author = $_POST['Author'];
  $Date = $_POST['Date'];
  $id = $_POST['id'];

		  
		  echo $sql = "UPDATE `indexinfo` SET
          `Title` = '$Title',
          `Subtitle` = '$Subtitle',
        `Content` = '$Content',
        `Author` = '$Author',
          `Date` = '$Date'
          WHERE `id` = 1";  

  if (mysql_query($sql)) {
    echo '<p>Author details updated.</p>';
  } else {
    echo '<p>Error updating author details: ' .
        mysql_error() . '</p>';
  }

$result = mysql_query("select * from `indexinfo` where id = 1");
$row = mysql_fetch_array($result);
?>
<form action="#" method="post">
<p><h2>EDIT ZONE <?php echo $id;?>:  </h2></p>
<label>Title:<input type="text" name="Title" value="<?php echo $row['Title']; ?>" /></label><br />
<label>Subtitle: <input type="text" name="Subtitle" value="<?php echo $row['Subtitle']; ?>" /></label><br />
<label>Content: <TEXTAREA name="Content" ROWS=10 COLS=100><?php echo $row['Content']; ?></TEXTAREA><br />
<label>Author: <input type="text" name="Author" value="<?php echo $row['Author']; ?>" /></label><br />
<label>Date: <input type="text" name="Date" value="<?php echo $row['Date']; ?>" /></label><br />

<input type="submit" value="Submit" name="send" /></p>
</form>
<?php
} else {
?>
<form action="#" method="post">
<p>EDIT ZONE 1:</p>
<label>Title: <input type="text" name="Title"  /></label><br />
<label>Subtitle: <input type="text" name="Subtitle" /></label><br />
<label>Content: <TEXTAREA name="Content" ROWS=10 COLS=100></TEXTAREA><br />
<label>Author: <input type="text" name="Author" /></label><br />
<label>Date: <input type="text" name="Date" /></label><br />
<input type="hidden" name="id" />
<input type="submit" value="Submit" name="send" /></p>
</form>
<?php } ?>

Didn't test it, but I hope you can see the difference. ie., $row :)

You should also consider sanitizing user's inputs. Check out mysql_real_escape_string !
Btw, the value of $id is always null in this above script. You aren't assigning a value to $id anywhere in the script.

What is meant to happen is

get the record with the value of 1

populate the relevant text box with that data, which can be typed over

replace the database with what is now in the relevant cell

My prob is :
How to display the content of database in the Rich Text Editor... need of php Code.........

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.