944,127 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 5041
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Aug 21st, 2007
0

what's wrong in this code?

Expand Post »
so, i started at php and i'm doing some exercises from the book, but when i type this code into my "view.php", the output is all wrong...
php Syntax (Toggle Plain Text)
  1. <?php include("dbconnect.php") ?>
  2.  
  3. <h2>View my GuestBook!!</h2>
  4.  
  5. <?php
  6.  
  7. $result=mysql_query("select * from guestbook")
  8. or die(mysql_error());
  9. while ($row=mysql_fetch_array($result))
  10. {
  11. echo "<b>Name:</b>";
  12. echo $row["name"];
  13. echo "<br>\n";
  14. echo "<b>Location:</b>";
  15. echo $row["location"];
  16. echo "<br>\n";
  17. echo "<b>Email:</b>";
  18. echo $row["email"];
  19. echo "<br>\n";
  20. echo "<b>URL:</b>";
  21. echo $row["url"];
  22. echo "<br>\n";
  23. echo "<b>Comments:</b>";
  24. echo $row["comments"];
  25. echo "<br>\n";
  26. echo "<br>\n";
  27. echo "<br>\n";
  28. }
  29. mysql_free_result($reslut);
  30. ?>
the output is like this:
Quote ...
View my GuestBook!!

Name:"; echo $row["name"]; echo "
\n"; echo "Location:"; echo $row["location"]; echo "
\n"; echo "Email:"; echo $row["email"]; echo "
\n"; echo "URL:"; echo $row["url"]; echo "
\n"; echo "Comments:"; echo $row["comments"]; echo "
\n"; echo "
\n"; echo "
\n"; } mysql_free_result($reslut); ?>

Sign my GuestBook
Similar Threads
Featured Poster
Reputation Points: 424
Solved Threads: 57
Posting Virtuoso
Nichito is offline Offline
1,594 posts
since Mar 2007
Aug 21st, 2007
0

Re: what's wrong in this code?

I think your server doesn't recognize php file, so
it doesn't interpret it. Do you install and configure
correctly PHP ?


- Mitko Kostov
Last edited by MitkOK; Aug 21st, 2007 at 1:26 pm.
Reputation Points: 59
Solved Threads: 12
Junior Poster
MitkOK is offline Offline
142 posts
since Jul 2007
Aug 21st, 2007
0

Re: what's wrong in this code?

i installed XAMPP... and i already made another php file that worked correctly, which was the one that writes the information this one is supposed to read...
Featured Poster
Reputation Points: 424
Solved Threads: 57
Posting Virtuoso
Nichito is offline Offline
1,594 posts
since Mar 2007
Aug 21st, 2007
0

Re: what's wrong in this code?

here are all my codes:

dbconnect.php
php Syntax (Toggle Plain Text)
  1. <?php
  2. mysql_connect("localhost","nobody","ydobon")
  3. or die("<h3>could not connect to MySQL</h3>\n");
  4. mysql_select_db("guestbook")
  5. or die("<h3>could not select database 'guestbook'</h3>\n");
  6. ?>

sign.php
php Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE> New Document </TITLE>
  5. <META NAME="Generator" CONTENT="EditPlus">
  6. <META NAME="Author" CONTENT="">
  7. <META NAME="Keywords" CONTENT="">
  8. <META NAME="Description" CONTENT="">
  9. </HEAD>
  10.  
  11. <BODY>
  12. <h2>Sign my guestbook!</h2>
  13. <form method="post" action="create_entry.php">
  14.  
  15. <b>Name:</b>
  16. <input type="text" size="40" name="name">
  17. <br>
  18. <b>Location:</b>
  19. <input type="text" size="40" name="location">
  20. <br>
  21. <b>Email:</b>
  22. <input type="text" size="40" name="email">
  23. <br>
  24. <b>Home Page URL:</b>
  25. <input type="text" size="40" name="url">
  26. <br>
  27. <b>Comments:</b>
  28. <textarea name="comments" cols="40" rows="4"
  29. wrap="virtualv"></textarea>
  30. <br>
  31.  
  32. <input type="submit" name="submit" value="Sign!">
  33. <input type="reset" name="reset" value="Start Over">
  34.  
  35. </form>
  36. </BODY>
  37. </HTML>

create_entry.php
php Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE> New Document </TITLE>
  5. <META NAME="Generator" CONTENT="EditPlus">
  6. <META NAME="Author" CONTENT="">
  7. <META NAME="Keywords" CONTENT="">
  8. <META NAME="Description" CONTENT="">
  9. </HEAD>
  10.  
  11. <BODY>
  12. <?php
  13. include("dbconnect.php");
  14.  
  15. if ($_REQUEST["submit"]=="Sign!")
  16. {
  17. $query="insert into guestbook(name,location,email,url,comments) values ('"
  18. .$_REQUEST["name"]
  19. ."', '"
  20. .$_REQUEST["location"]
  21. ."', '"
  22. .$_REQUEST["email"]
  23. ."', '"
  24. .$_REQUEST["url"]
  25. ."', '"
  26. .$_REQUEST["comments"]
  27. ."') "
  28. ;
  29. mysql_query($query);
  30. ?>
  31. <h2>Thanks!!</h2>
  32. <h2><a href="view.php">View my GuestBook!!</a></h2>
  33. <?php
  34. }
  35. else
  36. {
  37. include("sign.php");
  38. }
  39. ?>
  40. </BODY>
  41. </HTML>

view.php
php Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE> New Document </TITLE>
  5. <META NAME="Generator" CONTENT="EditPlus">
  6. <META NAME="Author" CONTENT="">
  7. <META NAME="Keywords" CONTENT="">
  8. <META NAME="Description" CONTENT="">
  9. </HEAD>
  10.  
  11. <BODY>
  12. <?php include("dbconnect.php") ?>
  13.  
  14. <h2>View my GuestBook!!</h2>
  15.  
  16. <?php
  17.  
  18. $result = mysql_query("select * from guestbook")
  19. or die(mysql_error());
  20. while ($row = mysql_fetch_array($result))
  21. {
  22. echo "Name:";
  23. echo $row["name"];
  24. echo "<br>\n";
  25. echo "<b>Location:</b>";
  26. echo $row["location"];
  27. echo "<br>\n";
  28. echo "<b>Email:</b>";
  29. echo $row["email"];
  30. echo "<br>\n";
  31. echo "<b>URL:</b>";
  32. echo $row["url"];
  33. echo "<br>\n";
  34. echo "<b>Comments:</b>";
  35. echo $row["comments"];
  36. echo "<br>\n";
  37. echo "<br>\n";
  38. echo "<br>\n";
  39. }
  40. mysql_free_result($result);
  41. ?>
  42.  
  43. <h2><a href="sign.php">Sign my GuestBook</a></h2>
  44.  
  45. </BODY>
  46. </HTML>

everything works just fine until when it gets to view.php... dunno what the problem is...
Featured Poster
Reputation Points: 424
Solved Threads: 57
Posting Virtuoso
Nichito is offline Offline
1,594 posts
since Mar 2007
Aug 21st, 2007
0

Re: what's wrong in this code?

I would suspect this lack of a semi-colon might be causing your problem
php Syntax (Toggle Plain Text)
  1. <?php include("dbconnect.php") ?>
though I'm not sure why you aren't getting an immediate script error from it.
Last edited by Ezzaral; Aug 21st, 2007 at 7:39 pm.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Aug 21st, 2007
0

Re: what's wrong in this code?

according to what i know, it shouldn't affect... since it is a single command...

still... tried it, and no response... the same exact results...
Featured Poster
Reputation Points: 424
Solved Threads: 57
Posting Virtuoso
Nichito is offline Offline
1,594 posts
since Mar 2007
Aug 21st, 2007
0

Re: what's wrong in this code?

Click to Expand / Collapse  Quote originally posted by Nichito ...
according to what i know, it shouldn't affect... since it is a single command...

still... tried it, and no response... the same exact results...
Yes, I wondered about it and a couple quick tests here came up the same. The semi-colon did not matter. That was the only thing that stood out that might have caused it to switch parsing modes. I don't really see anything else yet that would be problematic.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Aug 21st, 2007
0

Re: what's wrong in this code?

did you try it? i mean, the whole 'combo'?
Featured Poster
Reputation Points: 424
Solved Threads: 57
Posting Virtuoso
Nichito is offline Offline
1,594 posts
since Mar 2007
Aug 21st, 2007
0

Re: what's wrong in this code?

Click to Expand / Collapse  Quote originally posted by Nichito ...
did you try it? i mean, the whole 'combo'?
No, as that would entail creating db tables as well
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Aug 21st, 2007
0

Re: what's wrong in this code?

true... hehe... i don't think there's a problem with my php setup, since two out of three pages were working just fine...

maybe it's just something unnoticeable... or the example is not well written... i'll try some more and see if it persists...
Featured Poster
Reputation Points: 424
Solved Threads: 57
Posting Virtuoso
Nichito is offline Offline
1,594 posts
since Mar 2007

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: receiving an XML Post - how to ?
Next Thread in PHP Forum Timeline: cPanel copy php errors help





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


Follow us on Twitter


© 2011 DaniWeb® LLC