| | |
what's wrong in this code?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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); ?>
•
•
•
•
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<-- here are all my codes:
dbconnect.php
sign.php
create_entry.php
view.php
everything works just fine until when it gets to view.php... dunno what the problem is...
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...
-->sometimes i wanna take my toaster in a bath<-- I would suspect this lack of a semi-colon might be causing your problem though I'm not sure why you aren't getting an immediate script error from it.
php Syntax (Toggle Plain Text)
<?php include("dbconnect.php") ?>
Last edited by Ezzaral; Aug 21st, 2007 at 7:39 pm.
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.
![]() |
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 |
ajax apache api array basic beginner binary body broken cakephp checkbox class cms code computing cookies cron curl database date date/time delete display dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert interactive ip javascript job joomla js limit link login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop outofmemmory paging parse paypal pdf php procedure query radio ram random regex remote script search server sessions source space sql stored subdomain syntax system table tutorial unicode update upload url validation validator variable video web webapplications websitecontactform xml youtube






