943,682 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 5041
  • PHP RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Aug 23rd, 2007
0

Re: what's wrong in this code?

Well, I tested your php code in my computer. After i
mysql> create table guestbook
-> (name varchar(150),
-> location varchar(150),
-> email varchar(150),
-> url varchar(150),
-> comments text);
Query OK, 0 rows affected (0.01 sec)

It works. like:
View my GuestBook!!
Name:a
Location:a
Email:a
URL:a
Comments:b

So your code no problem, but i don't know whether your db is prepared or not.
You said sign.php and create_entry.php worked, so you can check in your db.
Use : mysql> use guestbook;
mysql> select * from guestbook;
To see whether there are records.
Mine has recoreds:
mysql> select * from guestbook;
+------+----------+-------+------+----------+
| name | location | email | url | comments |
+------+----------+-------+------+----------+
| a | a | a | a | b |
| w | w | w | e | s |
| h | h | h | h | h |
+------+----------+-------+------+----------+
3 rows in set (0.01 sec)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mikewzp is offline Offline
4 posts
since Aug 2007
Aug 24th, 2007
0

Re: what's wrong in this code?

Click to Expand / Collapse  Quote originally posted by Nichito ...
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...
Could you post the HTML Source of the output from view.php.

Also, place the following above the page:
php Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. error_reporting(E_ALL);
  4. display_errors(true);
  5.  
  6. ?>

Or the equivalent in your PHP.ini.

That way any warnings, notices, etc. will be printed.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Aug 24th, 2007
0

Re: what's wrong in this code?

Click to Expand / Collapse  Quote originally posted by Nichito ...
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:
Everything looks like its good to me except what Mitko said. I belive he may be right if else. The codes look good, I would check or uninstall/reinstall xampp. digital-ether is right also.
Last edited by mikeSQL; Aug 24th, 2007 at 5:07 pm.
Reputation Points: 16
Solved Threads: 3
Junior Poster
mikeSQL is offline Offline
196 posts
since Dec 2004
Aug 25th, 2007
0

Re: what's wrong in this code?

i think ther might be an error in XAMPP installation, since it doesn't seem to recognize the echo command... i'll try uninstalling and installing it again... (the other two worked well, since there were no "echo-es" in them...
Featured Poster
Reputation Points: 424
Solved Threads: 57
Posting Virtuoso
Nichito is offline Offline
1,594 posts
since Mar 2007
Aug 25th, 2007
0

Re: what's wrong in this code?

Click to Expand / Collapse  Quote originally posted by Nichito ...
i think ther might be an error in XAMPP installation, since it doesn't seem to recognize the echo command... i'll try uninstalling and installing it again... (the other two worked well, since there were no "echo-es" in them...
I'd recommend testing any theories individually before going through the whole uninstall/install process.

Just try a PHP file with:

PHP Syntax (Toggle Plain Text)
  1. <?php echo 'hello'; ?>

see if echo behaves funny.. etc.

BTW: Nichito, your avatar is scary! lol.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Aug 25th, 2007
0

Re: what's wrong in this code?

try escaping the '' like so:
\"
and in your record set use single quotes like so:
$row['name']
Last edited by JeniF; Aug 25th, 2007 at 4:54 pm.
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
JeniF is offline Offline
52 posts
since Aug 2007
Aug 26th, 2007
0

Re: what's wrong in this code?

i tried the <?php echo "hello" ?>command, and the output was:
Quote ...
so i guess that confirms my supposition...

though, i reinstalled in succesfully and it still returns the same output... i even tried other codes consisting in echoes and nothing happened...
Featured Poster
Reputation Points: 424
Solved Threads: 57
Posting Virtuoso
Nichito is offline Offline
1,594 posts
since Mar 2007
Aug 26th, 2007
0

Re: what's wrong in this code?

you forgot the ;
<?php echo "Hello"; ?>
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
JeniF is offline Offline
52 posts
since Aug 2007
Aug 26th, 2007
0

Re: what's wrong in this code?

didn't really matter, since the output was exactly the same... though, it would have given my an error...
Featured Poster
Reputation Points: 424
Solved Threads: 57
Posting Virtuoso
Nichito is offline Offline
1,594 posts
since Mar 2007
Aug 27th, 2007
0

Re: what's wrong in this code?

the only thing that could be wrong is u have something u are not seing
so u could rewrite the code again
maybe..........
;P
Reputation Points: 18
Solved Threads: 9
Junior Poster
w_3rabi is offline Offline
160 posts
since Dec 2006

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