krysco Posted November 13, 2008 Share Posted November 13, 2008 Ok so this is my second time posting today (not my day huh....). So here's the story...again... The first time I posted was in the PHP forum. That problem was solved (boneheaded mistake). So I'm still reading this book still on the first chapter still working the same tutorial. I got the php file to work now my problem is with MySQL (I think). The tutorial is to create a guestbook using MySQL and PHP and it all seems very easy. My Setup: I have Ubuntu Linux (Hardy Heron Release) installed on my Mac Pro running in a VM through Fusion. I have PHP5, Apache2, and MySQL(not sure what version), all installed and running correctly. I used a tutorial that showed me how to set things up. You can take a look at it here: http://maketecheasier.com/setting-up-a-lamp-server-in-ubuntu-hardy-heron/2008/08/06 first thing the book wants you to do is create a database but it uses the terminal to do so. when i tried to do it through the terminal i got a message that basically told me i do not have permission to make a table....whatever. so i figure i'll go make the database in phpMyAdmin. So I do so with the following settings: database name: guestbook utf8_unicode_ci (i chose this the second go round with the database b/c swedish seemed wrong) table name: guestbook with 5 fields so now i'm at the screen where you put in the column info for the table in the database it is as follows (excuse the makeshift table): Field Type Length/Values Collation Attributes Null Default Extra name Varchar 40 utf8_unicode_ci Null location Varchar 40 utf8_unicode_ci Null email Varchar 40 utf8_unicode_ci Null url Varchar 40 utf8_unicode_ci Null comments Varchar 40 utf8_unicode_ci Null Then i hit save and all seems well. So I continue on in the book and create three more files: First was a file to connect to the database called "dbconnect.php" <? mysql_connect("localhost" , "root" , "catch2@") or die ("Could not connect to database"); mysql_connect("guestbook") or die ("Could not select database"); ?> Then the file with the form called "sign.php" <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=virtual></textarea> <br> <input type=submit name=submit value="Sign!"> <input type=reset name=reset vaue="Start Over"> </form> Lastly the script thats supposed to put the data into the database called "create_entry.php" <?php include("dbconnect.php"); if ($submit == "Sign!") { $query = "insert into guestbook (name , location , email , url , comments) values ('$name' , '$location' , '$email' , '$url' , '$comments' , )" ; mysql_query($query) or die (mysql_error()); ?> <h2>Thanks!!</h2> <h2><a href="view.php">View My Guest Book!!!</a></h2> <?php } else { include("sign.php"); } So I have these three files all in the same directory. I fill out the form, hit submit, and the browser tells me this: Not Found The requested URL /tutorials/function.mysql-connect was not found on this server. _____________________________________________________________________________________ Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4 with Suhosin-Patch Server at localhost Port 80 And now I'm stuck. Intuition tells me that some function needed to communicate between PHP and MySQL isn't installed but I'm just guessing. This is my first time venturing into either of these areas. Is there something I'm missing or doing wrong? Quote Link to comment Share on other sites More sharing options...
krysco Posted November 13, 2008 Author Share Posted November 13, 2008 I have a small edit to the above post. When I submit the form I do not get the "Not Found" error posted above I get this error: Warning: mysql_connect() [function.mysql-connect]: Unknown server host 'guestbook' (1) in /var/www/tutorials/dbconnect.php on line 4 Could not select database And I have something to add: I decided to go on in the tutorial (still the same guestbook exercise) to the part where you're supposed to pull the info from the database and display it. I get the same error as mentioned above on this page too. Here is the code: <? php include("dbconnect.php");?> <h2>View My Guest Book!!!</h2> <?php $result = mysql_query("select * from guestbook") or die (mysql_eror()); 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 $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($reslult) ?> <h2><a href="sign.php">Sign My Guest Book!!</a></h2> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.