Hi all,

This following code doesnt update the database. I get the following error message

Parse error: parse error in C:\wamp\www\testbin\edit.php on line 41

Please can you advise as to the error. I have worked on this for a few hours now but to no avail.

Many thanks

<?php

if (isset($_POST['$SUBMIT'])):
  // The author's details have been updated.

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

  $sql = "UPdATE indexinfo SET
          Title='$Title',
          Subtitle='$Subtitle',
	    Content='$Content',
	    Author='$Author',
          Date='$Date'
          WHERE id='$id'";
  if (@mysql_query($sql)) {
    echo '<p>Author details updated.</p>';
  } else {
    echo '<p>Error updating author details: ' .
        mysql_error() . '</p>';
  }

?>


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Edit the author:</p>
<label>Title: <input type="text" name="Title" value="<?php echo $Title; ?>" /></label><br />
<label>Subtitle: <input type="text" name="Subtitle" value="<?php echo $Subtitle; ?>" /></label><br />
<label>Content: <input type="text" name="Content" value="<?php echo $Content; ?>" /></label><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" /></p>
</form>

Recommended Answers

All 19 Replies

try this

<?php

if (isset($_POST['SUBMIT']))
  // The author's details have been updated.
{
  
  $Title = $_POST['Title'];
  $Subtitle = $_POST['Title'];
  $Content = $_POST['Content'];
  $Author = $_POST['Author'];
  $Date = $_POST['Date'];
  $id = $_POST['id'];

  $sql = "UPdATE indexinfo SET
          Title='$Title',
          Subtitle='$Subtitle',
	    Content='$Content',
	    Author='$Author',
          Date='$Date'
          WHERE id='$id'";
  if (@mysql_query($sql)) {
    echo '<p>Author details updated.</p>';
  } else {
    echo '<p>Error updating author details: ' .
        mysql_error() . '</p>';
  }
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Edit the author:</p>
<label>Title: <input type="text" name="Title" value="<?php echo $Title; ?>" /></label><br />
<label>Subtitle: <input type="text" name="Subtitle" value="<?php echo $Subtitle; ?>" /></label><br />
<label>Content: <input type="text" name="Content" value="<?php echo $Content; ?>" /></label><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" /></p>
</form>

check this line
<input type="submit" value="SUBMIT" />
it should be
<input type="submit" value="SUBMIT" name="SUBMIT" />
then in the isset function write like this

if (isset($_POST['SUBMIT'])):
{

remove the $ mark.

any way which is ur line 41??

Hi,

its giving me the following error, which is wierd as its the end of the file

Parse error: parse error in C:\wamp\www\testbin\edit.php on line 43

uhhh have you tried my code yet?

Hi Keirol,

The post regarding the repeated error is regarding your post.

Mrniceguy, i have implimented your suggestions too. The code stands as the following, but the error is always relating to the last line.

ive spent all day on this little bugger. Your helps much appreciated!!!

<?php

if (isset($_POST['SUBMIT'])):
  // The author's details have been updated.
{
  
  $Title = $_POST['Title'];
  $Subtitle = $_POST['Title'];
  $Content = $_POST['Content'];
  $Author = $_POST['Author'];
  $Date = $_POST['Date'];
  $id = $_POST['id'];

  $sql = "UPDATE indexinfo SET
          Title='$Title',
          Subtitle='$Subtitle',
	    Content='$Content',
	    Author='$Author',
          Date='$Date'
          WHERE id='$id'";
  if (@mysql_query($sql)) {
    echo '<p>Author details updated.</p>';
  } else {
    echo '<p>Error updating author details: ' .
        mysql_error() . '</p>';
  }

?>


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Edit the author:</p>
<label>Title: <input type="text" name="Title" value="<?php echo $Title; ?>" /></label><br />
<label>Subtitle: <input type="text" name="Subtitle" value="<?php echo $Subtitle; ?>" /></label><br />
<label>Content: <input type="text" name="Content" value="<?php echo $Content; ?>" /></label><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="SUBMIT" /></p>
</form>

you didn't do the changes that I said. This code does work.

<?php
if (isset($_POST['SUBMIT']))
  // The author's details have been updated.
{
  $Title = $_POST['Title'];
  $Subtitle = $_POST['Title'];
  $Content = $_POST['Content'];
  $Author = $_POST['Author'];
  $Date = $_POST['Date'];
  $id = $_POST['id'];

  $sql = "UPdATE indexinfo SET
          Title='$Title',
          Subtitle='$Subtitle',
	    Content='$Content',
	    Author='$Author',
          Date='$Date'
          WHERE id='$id'";
  if (@mysql_query($sql)) {
    echo '<p>Author details updated.</p>';
  } else {
    echo '<p>Error updating author details: ' .
        mysql_error() . '</p>';
  }
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>Edit the author:</p>
<label>Title: <input type="text" name="Title" value="<?php echo $Title; ?>" /></label><br />
<label>Subtitle: <input type="text" name="Subtitle" value="<?php echo $Subtitle; ?>" /></label><br />
<label>Content: <input type="text" name="Content" value="<?php echo $Content; ?>" /></label><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="SUBMIT" />
</form>

I sometimes have difficulty with using the 'isset' function. You might try using 'if( ! empty($_POST) )' instead.

also, using PHP_SELF is a terrible way to call back the form. use nothing "" or htmlspecialchars() on the PHP_SELF. If you don't you open yourself up to bad things.

Hi,

I have tried every combination suggested.

Kireol, the code you have provided gives the following error in each text box that appears.

<br /><b>Notice</b>: Undefined variable: Title in <b>C:\wamp\www\testbin\edit.php</b> on line <b>36</b><br />

Which i dont understand why it is there as it is clearly defined.

im really baffled

Can you suggest some alternative code?

call the content of the variables from mysql and display directly to text boxes with update button when on click states success all on same page?

Hi,

I found out the problem. I needed to make a few adjustments to the php.ini error corrections.

I only have 1 more question.

the "details updated" message is always visible. ive checked the code but again, as im new, seems fine

Try this as yours is riddled with errors:

<?php

if ( isset( $_POST['send'] ) ) {
  // The author's details have been updated.

  
  $title = $_POST['Title'];
  $subtitle = $_POST['Subtitle'];
  $content = $_POST['Content'];
  $author = $_POST['Author'];
  $date = $_POST['Date'];
  $id = $_POST['id'];

  $sql = "UPDATE `indexinfo` SET
          `Title` = '$title',
          `Subtitle` = '$subtitle',
	    `Content` = '$content',
	    `Author` = '$author',
          `Date` = '$date'
          WHERE `id` = '$id'";
  if (mysql_query($sql)) {
    echo '<p>Author details updated.</p>';
  } else {
    echo '<p>Error updating author details: ' .
        mysql_error() . '</p>';
  }

}

?>


<form action="#" method="post">
<p>Edit the author:</p>
<label>Title: <input type="text" name="Title" value="<?php echo $title; ?>" /></label><br />
<label>Subtitle: <input type="text" name="Subtitle" value="<?php echo $subtitle; ?>" /></label><br />
<label>Content: <input type="text" name="Content" value="<?php echo $content; ?>" /></label><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>

Try this it might work allot better.

A list of problems you had or may have had (methods that may cause problems):
- Capitals at the start of a variable $Title - SQL Statement was messy. All fields or table names should be contained with ` (key to the left of 1 but not the numpad numbers the top row)
- PHP_SELF as stated before isn't advised. Your better of using #.
- The use of if( STATEMENT ): isn't advised for newbies. Stick to the standard if( STATEMENT ) { } - $_POST[''] refers to a form field "name" not the value, that is what it is retreiving.

But other than these issues you seem to be okay, the only other thing I ntoiced is you haven't connected or selected a database. If you removed these so as not to give away details then please leve the lines and replace sensative data (i.e. passwords) with asterix's.

Oh and try to avoid using the @ suppresants until you have the script working and perfect else you may be missing some important errors.

i yhink u will give same name for assigning tiltle ...

$Title = $_POST['Title'];  
$Subtitle = $_POST['Title'];
instead of
$Title = $_POST['Title'];  
$Subtitle = $_POST['Subtitle'];

and u will give like this..

$sql = "UPdATE indexinfo SET          Title='".$Title."',          Subtitle='$Subtitle',	    Content='$Content',	    Author='".$Author."',          Date='".$Date."'          WHERE id='$id'";

it seems that no matter what i do the localhost claims that the variables in the form are undeclared

Oh thats because you need to declare the ones in the form as $_POST etc as you are only declaring them if the form has been submitted try this:

<?php

if ( isset( $_POST['send'] ) ) {
  // The author's details have been updated.

  
  $title = $_POST['Title'];
  $subtitle = $_POST['Subtitle'];
  $content = $_POST['Content'];
  $author = $_POST['Author'];
  $date = $_POST['Date'];
  $id = $_POST['id'];

  $sql = "UPDATE `indexinfo` SET
          `Title` = '$title',
          `Subtitle` = '$subtitle',
	    `Content` = '$content',
	    `Author` = '$author',
          `Date` = '$date'
          WHERE `id` = '$id'";
  if (mysql_query($sql)) {
    echo '<p>Author details updated.</p>';
  } else {
    echo '<p>Error updating author details: ' .
        mysql_error() . '</p>';
  }

?>


<form action="#" method="post">
<p>Edit the author:</p>
<label>Title: <input type="text" name="Title" value="<?php echo $title; ?>" /></label><br />
<label>Subtitle: <input type="text" name="Subtitle" value="<?php echo $subtitle; ?>" /></label><br />
<label>Content: <input type="text" name="Content" value="<?php echo $content; ?>" /></label><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
} else {
?>
<form action="#" method="post">
<p>Edit the author:</p>
<label>Title: <input type="text" name="Title" /></label><br />
<label>Subtitle: <input type="text" name="Subtitle" /></label><br />
<label>Content: <input type="text" name="Content" /></label><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>

The only problem is you need to specify the ID somehow. Without using PHP.

bingo, that now works without error, except that the "Author details updated" is always there

ok I got it. All sorted.


Thank you everybody for your help. very much appreciated and i have learnt a lot!

Glad you got it to work ;)

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.