PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old September 3rd, 2002, 08:11 PM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
crazy edit thingy

my code is coming out crazy at the mo, I know the code isn't complete yet, I'm just building it up and debugging it as I go along, but on the edit tutorial, I found that when it comes to the actually editing, it formats all wrong, well you have to see what I mean here http://gmflp.l33t.ca/yepyep/news.php?action=edit&id=4 I dunno whats thats all about, please help

php Code:
Original - php Code
  1.  
  2. <?php
  3. $db = @mysql_connect("$dbhost", "$dbuname", "$dbpage");
  4. if (!$db) {
  5.   echo( "<p>Unable to connect to the " .
  6.         "database server at this time.</p>" );
  7.   exit();
  8. }
  9. mysql_select_db("$dbname", $db);
  10. if (! @mysql_select_db("$dbname") ) {
  11.   echo( "<p>Unable to locate the news " .
  12.         "database at this time.</p>" );
  13.   exit();
  14. }
  15. if($submit)
  16. {
  17. $sql = "INSERT INTO newsdb (name, email, title, news, date) VALUES ('$name', '$email', '$title','$news', now('$date'))";
  18. $result = mysql_query($sql);
  19. echo( "Thank you! Information entered. Click <a href=/news.php>here</a> to view your news" );
  20.  
  21. }
  22. elseif($_GET['action'] == 'edit')
  23. {
  24.  $result = mysql_query("SELECT * FROM newsdb WHERE id=$id",$db);
  25.  $myrow = mysql_fetch_array($result);
  26.  
  27.  
  28. echo "<form method=post action=".$PHP_SELF.">";
  29. echo "<input type=hidden name=id value=".$myrow['id'].">";
  30.  
  31. echo "<b>Title</b>: <input type=Text name=title value=".$myrow['title']."><br>";
  32.  
  33. echo "<b>News:</b> <textarea name=news cols=40 rows=8 value=".$myrow['news']."><br>";
  34.  
  35.  
  36. echo "<b>Name:</b><input type=Text name=name value=".$myrow['name']."><br>";
  37.  
  38. echo "<b>E-mail:</b><input type=Text name=email value=".$myrow['email']."><br>";
  39.  
  40.  
  41. echo "<input type=Submit name=update value=Update information></form>";
  42.  
  43. }
  44. elseif($searchstring)
  45. {
  46. $sql="SELECT * FROM newsdb WHERE title LIKE '%$searchstring%' ORDER BY title ASC";
  47. $result = mysql_query($sql,$db);
  48. while ($myrow = mysql_fetch_array($result))
  49.  
  50. echo("<b>Title:</b> ".$myrow['title']. "<br><b>News:</b> ".$myrow['news']. "<br><a href=?action=edit&id=".$myrow['id'].">Edit</a> | <a href=?action=delete&id=".$myrow['id'].">Delete</a><p>");
  51.  
  52.  
  53.  
  54.  
  55. }
  56. else
  57. {
  58. ?>
  59. <form method="post" action="<?=$PHP_SELF?>">
  60. Name:
  61. <br><input type="Text" name="name">
  62. <br>Email:
  63. <br><input type="Text" name="email">
  64. <br>Title:
  65. <br><input type="Text" name="title"
  66. <br>News:
  67. <br><textarea name="news" cols=40 rows=8></textarea>
  68. <br>
  69. <input type="Submit" name="submit" value="Submit"></form>
  70.  
  71. <h3>MADE AN ERROR? EDIT IT HERE</H3>
  72.  
  73. <form method="POST" action="<?php $PHP_SELF ?>">
  74. Enter the title of the news:<input type="text" name="searchstring" size="28">
  75.  
  76. <br><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2">
  77. </form>
  78.  
  79. <?
  80. }
  81. ?>

Reply With Quote
  #2  
Old September 3rd, 2002, 08:48 PM
Nimco Nimco is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 132 Nimco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to Nimco
RE: crazy edit thingy

OK, the reason your textarea has lots of code inside is because you have got the syntax wrong. The syntax for a textarea is as follows:

php Code:
Original - php Code
  1.  
  2. <textarea name="mytextbox">Default text goes here</textarea>


Also, here's a little hint I find very useful. When you are writing PHP script to print HTML or plain text straight to the page, do it outside of the PHP:

php Code:
Original - php Code
  1.  
  2. echo "<b>News:</b> <textarea name=news cols=40 rows=8 value=".$myrow['news']."><br>";
  3.  
  4. becomes:
  5.  
  6. <b>News:</b><textarea name="news" cols="40" rows="8"><?=$myrow['news']?></textarea>


If you didn't already know, the "<?=" is the same as "<? echo" - just a useful shorthand.

Reply With Quote
  #3  
Old September 7th, 2002, 03:58 PM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: crazy edit thingy

thank you man

Reply With Quote
  #4  
Old September 7th, 2002, 04:02 PM
Nimco Nimco is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 132 Nimco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to Nimco
RE: crazy edit thingy

No problem

Reply With Quote
  #5  
Old September 8th, 2002, 03:18 PM
jv jv is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 jv User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: crazy edit thingy

I'll tell you one trick..

if you do your brackets always like this...

php Code:
Original - php Code
  1.  
  2. if (etc == etc)
  3. {
  4.      dothis..
  5.      and this..
  6.      and this...
  7. }


rather than this..

php Code:
Original - php Code
  1.  
  2. if () {
  3.    do this
  4. }


it makes it text times easier to see what is going on, and where each of your code blocks are.


Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > crazy edit thingy


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway