what's wrong in this code?

Reply

Join Date: Aug 2007
Posts: 4
Reputation: mikewzp is an unknown quantity at this point 
Solved Threads: 0
mikewzp mikewzp is offline Offline
Newbie Poster

Re: what's wrong in this code?

 
0
  #21
Aug 23rd, 2007
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)
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: what's wrong in this code?

 
0
  #22
Aug 24th, 2007
Originally Posted by Nichito View Post
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...
Could you post the HTML Source of the output from view.php.

Also, place the following above the page:
  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.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 196
Reputation: mikeSQL is an unknown quantity at this point 
Solved Threads: 3
mikeSQL's Avatar
mikeSQL mikeSQL is offline Offline
Junior Poster

Re: what's wrong in this code?

 
0
  #23
Aug 24th, 2007
Originally Posted by Nichito View 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...
  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.
dynastyCODERS#1 when it comes to Programming Tutorials, Database designs and discussions, Operating Systems, you name it, check us out and drop us a line to tell us your opinions on any and everything in mind!;)
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
  #24
Aug 25th, 2007
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...
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: what's wrong in this code?

 
0
  #25
Aug 25th, 2007
Originally Posted by Nichito View Post
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:

  1. <?php echo 'hello'; ?>

see if echo behaves funny.. etc.

BTW: Nichito, your avatar is scary! lol.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 52
Reputation: JeniF is an unknown quantity at this point 
Solved Threads: 5
JeniF's Avatar
JeniF JeniF is offline Offline
Junior Poster in Training

Re: what's wrong in this code?

 
0
  #26
Aug 25th, 2007
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.
I keep hitting "escape", but I'm still here!!!!
:}
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
  #27
Aug 26th, 2007
i tried the <?php echo "hello" ?>command, and the output was:
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...
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 52
Reputation: JeniF is an unknown quantity at this point 
Solved Threads: 5
JeniF's Avatar
JeniF JeniF is offline Offline
Junior Poster in Training

Re: what's wrong in this code?

 
0
  #28
Aug 26th, 2007
you forgot the ;
<?php echo "Hello"; ?>
I keep hitting "escape", but I'm still here!!!!
:}
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
  #29
Aug 26th, 2007
didn't really matter, since the output was exactly the same... though, it would have given my an error...
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 160
Reputation: w_3rabi is an unknown quantity at this point 
Solved Threads: 8
w_3rabi's Avatar
w_3rabi w_3rabi is offline Offline
Junior Poster

Re: what's wrong in this code?

 
0
  #30
Aug 27th, 2007
the only thing that could be wrong is u have something u are not seing
so u could rewrite the code again
maybe..........
;P
programming is an art ,only for those who can understand it.
- th3 php wr3nch -
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