what's wrong in this code?

Reply

Join Date: Mar 2007
Posts: 1,429
Reputation: Nichito is an unknown quantity at this point 
Solved Threads: 29
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

what's wrong in this code?

 
0
  #1
Aug 21st, 2007
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...
  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:
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
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 142
Reputation: MitkOK is an unknown quantity at this point 
Solved Threads: 12
MitkOK's Avatar
MitkOK MitkOK is offline Offline
Junior Poster

Re: what's wrong in this code?

 
0
  #2
Aug 21st, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,429
Reputation: Nichito is an unknown quantity at this point 
Solved Threads: 29
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: what's wrong in this code?

 
0
  #3
Aug 21st, 2007
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...
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,429
Reputation: Nichito is an unknown quantity at this point 
Solved Threads: 29
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: what's wrong in this code?

 
0
  #4
Aug 21st, 2007
here are all my codes:

dbconnect.php
  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
  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
  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
  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...
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,424
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: what's wrong in this code?

 
0
  #5
Aug 21st, 2007
I would suspect this lack of a semi-colon might be causing your problem
  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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,429
Reputation: Nichito is an unknown quantity at this point 
Solved Threads: 29
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: what's wrong in this code?

 
0
  #6
Aug 21st, 2007
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...
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,424
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: what's wrong in this code?

 
0
  #7
Aug 21st, 2007
Originally Posted by Nichito View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,429
Reputation: Nichito is an unknown quantity at this point 
Solved Threads: 29
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: what's wrong in this code?

 
0
  #8
Aug 21st, 2007
did you try it? i mean, the whole 'combo'?
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,424
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: what's wrong in this code?

 
0
  #9
Aug 21st, 2007
Originally Posted by Nichito View Post
did you try it? i mean, the whole 'combo'?
No, as that would entail creating db tables as well
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,429
Reputation: Nichito is an unknown quantity at this point 
Solved Threads: 29
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: what's wrong in this code?

 
0
  #10
Aug 21st, 2007
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...
-->sometimes i wanna take my toaster in a bath<--
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