Script errors

Reply

Join Date: Jun 2009
Posts: 140
Reputation: whiteyoh is an unknown quantity at this point 
Solved Threads: 2
whiteyoh whiteyoh is offline Offline
Junior Poster

Script errors

 
0
  #1
Jul 10th, 2009
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

  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 } ?>
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 763
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: Script errors

 
0
  #2
Jul 10th, 2009
It'd help if you told us what errors you're getting.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 171
Reputation: Menster is an unknown quantity at this point 
Solved Threads: 22
Menster's Avatar
Menster Menster is offline Offline
Junior Poster

Re: Script errors

 
0
  #3
Jul 10th, 2009
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
$me = new Person();
if (isset($_COOKIE)){
$me->eat($_COOKIE);
} else { $me->starve(); }
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 340
Reputation: Josh Connerty is an unknown quantity at this point 
Solved Threads: 26
Josh Connerty's Avatar
Josh Connerty Josh Connerty is offline Offline
Posting Whiz

Re: Script errors

 
0
  #4
Jul 10th, 2009
What do you mean as in if you haven't submitted the form you still get the row updated message?
Posts should be like mini-skirts, long enough to cover enough, but not too long that you cover too much.

My Liveperson: http://liveperson.com/josh-connerty/
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 140
Reputation: whiteyoh is an unknown quantity at this point 
Solved Threads: 2
whiteyoh whiteyoh is offline Offline
Junior Poster

Re: Script errors

 
0
  #5
Jul 16th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 340
Reputation: Josh Connerty is an unknown quantity at this point 
Solved Threads: 26
Josh Connerty's Avatar
Josh Connerty Josh Connerty is offline Offline
Posting Whiz

Re: Script errors

 
0
  #6
Jul 16th, 2009
Originally Posted by whiteyoh View Post
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.

  1. $query = mysql_query("QUERY") or die( "UPDATE ERROR:" . mysql_error() );
  2. // QUERY being the update query you have been using.
Posts should be like mini-skirts, long enough to cover enough, but not too long that you cover too much.

My Liveperson: http://liveperson.com/josh-connerty/
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC