| | |
what's wrong in this code?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2007
Posts: 4
Reputation:
Solved Threads: 0
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)
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)
•
•
•
•
here are all my codes:
dbconnect.php
php Syntax (Toggle Plain Text)
<?php mysql_connect("localhost","nobody","ydobon") or die("<h3>could not connect to MySQL</h3>\n"); mysql_select_db("guestbook") or die("<h3>could not select database 'guestbook'</h3>\n"); ?>
sign.php
php Syntax (Toggle Plain Text)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <BODY> <h2>Sign my guestbook!</h2> <form method="post" action="create_entry.php"> <b>Name:</b> <input type="text" size="40" name="name"> <br> <b>Location:</b> <input type="text" size="40" name="location"> <br> <b>Email:</b> <input type="text" size="40" name="email"> <br> <b>Home Page URL:</b> <input type="text" size="40" name="url"> <br> <b>Comments:</b> <textarea name="comments" cols="40" rows="4" wrap="virtualv"></textarea> <br> <input type="submit" name="submit" value="Sign!"> <input type="reset" name="reset" value="Start Over"> </form> </BODY> </HTML>
create_entry.php
php Syntax (Toggle Plain Text)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <BODY> <?php include("dbconnect.php"); if ($_REQUEST["submit"]=="Sign!") { $query="insert into guestbook(name,location,email,url,comments) values ('" .$_REQUEST["name"] ."', '" .$_REQUEST["location"] ."', '" .$_REQUEST["email"] ."', '" .$_REQUEST["url"] ."', '" .$_REQUEST["comments"] ."') " ; mysql_query($query); ?> <h2>Thanks!!</h2> <h2><a href="view.php">View my GuestBook!!</a></h2> <?php } else { include("sign.php"); } ?> </BODY> </HTML>
view.php
php Syntax (Toggle Plain Text)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <BODY> <?php include("dbconnect.php") ?> <h2>View my GuestBook!!</h2> <?php $result = mysql_query("select * from guestbook") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { echo "Name:"; echo $row["name"]; echo "<br>\n"; echo "<b>Location:</b>"; echo $row["location"]; echo "<br>\n"; echo "<b>Email:</b>"; echo $row["email"]; echo "<br>\n"; echo "<b>URL:</b>"; echo $row["url"]; echo "<br>\n"; echo "<b>Comments:</b>"; echo $row["comments"]; echo "<br>\n"; echo "<br>\n"; echo "<br>\n"; } mysql_free_result($result); ?> <h2><a href="sign.php">Sign my GuestBook</a></h2> </BODY> </HTML>
everything works just fine until when it gets to view.php... dunno what the problem is...
Also, place the following above the page:
php Syntax (Toggle Plain Text)
<?php error_reporting(E_ALL); display_errors(true); ?>
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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
•
•
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...the output is like this:php Syntax (Toggle Plain Text)
<?php include("dbconnect.php") ?> <h2>View my GuestBook!!</h2> <?php $result=mysql_query("select * from guestbook") or die(mysql_error()); while ($row=mysql_fetch_array($result)) { echo "<b>Name:</b>"; echo $row["name"]; echo "<br>\n"; echo "<b>Location:</b>"; echo $row["location"]; echo "<br>\n"; echo "<b>Email:</b>"; echo $row["email"]; echo "<br>\n"; echo "<b>URL:</b>"; echo $row["url"]; echo "<br>\n"; echo "<b>Comments:</b>"; echo $row["comments"]; echo "<br>\n"; echo "<br>\n"; echo "<br>\n"; } mysql_free_result($reslut); ?>
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!;)
•
•
•
•
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...
Just try a PHP file with:
PHP Syntax (Toggle Plain Text)
<?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!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
i tried the
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...
<?php echo "hello" ?>command, and the output was:•
•
•
•
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<-- ![]() |
Similar Threads
- What is Wrong in this simple code ? (Assembly)
- What's wrong with this code? (C#)
- What's wrong with this code? (Python)
- Please help me figure out whats wrong with my code (C++)
- What is wrong with this code? (C++)
- What is wrong with this code??? (Visual Basic 4 / 5 / 6)
- what is wrong with yhis code? (PHP)
- Whats wrong with this code (PHP)
- Something wrong with my code, why Junk character appears? (C)
Other Threads in the PHP Forum
- Previous Thread: receiving an XML Post - how to ?
- Next Thread: cPanel copy php errors help
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend






