943,884 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 562
  • PHP RSS
Jul 10th, 2009
0

Script errors

Expand Post »
Hi,

Firstly apologies as i shouldnt have set a previous thread as solved.

The following script should:

1. get record with id of 1 and display in text box
2. after user changes it, it is written to mysql
3. the screen informs user that this has been achieved

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $result = mysql_query("select * from indexinfo where id = 1");
  3. $row = mysql_fetch_assoc($result);
  4. if ( isset( $_POST['send'] ) ) {
  5. // The author's details have been updated.
  6.  
  7.  
  8. $title = $_POST['Title'];
  9. $subtitle = $_POST['Subtitle'];
  10. $content = $_POST['Content'];
  11. $author = $_POST['Author'];
  12. $date = $_POST['Date'];
  13. $id = $_POST['id'];
  14.  
  15. $sql = "UPDATE `indexinfo` SET
  16. `Title` = '$title',
  17. `Subtitle` = '$subtitle',
  18. `Content` = '$content',
  19. `Author` = '$author',
  20. `Date` = '$date'
  21. WHERE `id` = '$id'";
  22. if (mysql_query($sql)) {
  23. echo '<p>Author details updated.</p>';
  24. } else {
  25. echo '<p>Error updating author details: ' .
  26. mysql_error() . '</p>';
  27. }
  28.  
  29. ?>
  30.  
  31.  
  32. <form action="#" method="post">
  33. <p>Edit the author:</p>
  34. <label>Title: <input type="text" name="Title" value="<?php echo $title; ?>" /></label><br />
  35. <label>Subtitle: <input type="text" name="Subtitle" value="<?php echo $subtitle; ?>" /></label><br />
  36. <label>Content: <TEXTAREA name="Content" ROWS=10 COLS=100><?php echo $content; ?></TEXTAREA><br />
  37. <label>Author: <input type="text" name="Author" value="<?php echo $author; ?>" /></label><br />
  38. <label>Date: <input type="text" name="Date" value="<?php echo $date; ?>" /></label><br />
  39. <input type="hidden" name="id" value="<?php echo $id; ?>" />
  40. <input type="submit" value="Submit" name="send" /></p>
  41.  
  42.  
  43.  
  44. </form>
  45. <?php
  46. } else {
  47. ?>
  48. <form action="#" method="post">
  49. <p>Edit the author:</p>
  50. <label>Title: <input type="text" name="Title" /></label><br />
  51. <label>Subtitle: <input type="text" name="Subtitle" /></label><br />
  52. <label>Content: <TEXTAREA name="Content" ROWS=10 COLS=100></TEXTAREA><br />
  53. <label>Author: <input type="text" name="Author" /></label><br />
  54. <label>Date: <input type="text" name="Date" /></label><br />
  55. <input type="hidden" name="id" />
  56. <input type="submit" value="Submit" name="send" /></p>
  57. </form>
  58. <?php } ?>
Similar Threads
Reputation Points: 15
Solved Threads: 15
Posting Pro in Training
whiteyoh is offline Offline
474 posts
since Jun 2009
Jul 10th, 2009
0

Re: Script errors

It'd help if you told us what errors you're getting.
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004
Jul 10th, 2009
0

Re: Script errors

Hi there,
You don't actually have a problem statement in your post, so I'm not really sure where you are going wrong.

But, I notice that after querying the database at the top of the file, you don't do anything with the $row variable, which is why you aren't seeing anything in your form the first time you load the page.

Hope this helped
Reputation Points: 49
Solved Threads: 22
Junior Poster
Menster is offline Offline
175 posts
since Jun 2009
Jul 10th, 2009
0

Re: Script errors

What do you mean as in if you haven't submitted the form you still get the row updated message?
Reputation Points: 31
Solved Threads: 27
Unverified User
Josh Connerty is offline Offline
342 posts
since Apr 2009
Jul 16th, 2009
0

Re: Script errors

The form itself displays each of the headers.... title, subtitle, content, author and date..... but it doesnt echo the data that is held in the mysql database.

On changing the cell information and clicking submit, a success message is given, but the row in the database is not updated.
Reputation Points: 15
Solved Threads: 15
Posting Pro in Training
whiteyoh is offline Offline
474 posts
since Jun 2009
Jul 16th, 2009
0

Re: Script errors

Click to Expand / Collapse  Quote originally posted by whiteyoh ...
The form itself displays each of the headers.... title, subtitle, content, author and date..... but it doesnt echo the data that is held in the mysql database.

On changing the cell information and clicking submit, a success message is given, but the row in the database is not updated.
Okay in that case, please add the following at the end of your update query.

php Syntax (Toggle Plain Text)
  1. $query = mysql_query("QUERY") or die( "UPDATE ERROR:" . mysql_error() );
  2. // QUERY being the update query you have been using.
Reputation Points: 31
Solved Threads: 27
Unverified User
Josh Connerty is offline Offline
342 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Dropdown not showing in table
Next Thread in PHP Forum Timeline: PHP Object method extension





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC