Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Grabbing Mysql Data & Displaying It
Jambo
post Jul 21 2004, 02:54 PM
Post #1


Addicted Dot
Group Icon
Group: *Premier*
Posts: 1,093
Joined: 19-May 04
From: The UK
Member No.: 4





Ok, with a little help from Chase. I got there in the end.
http://www.jamie-barton.com/getphp/form.php
-----------------------------------------------------------------------------------------------------

Step 1
Create new php document, name it connect.php

Enter the following:
CODE
<?

$dbh=mysql_connect ("localhost", "jamie_test", "test") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("jamie_test");

?>


Thats connect done, replace jamie_test with your database name & user, also change the password too.

Step 2
Create new php document, name it form.php

Use the following, you may want to modify this to have more fields etc.

CODE
<?
echo '
<form method=POST action=submit.php name="newform">
<textarea rows="10" cols="30" name="contents">
Enter your article here</textarea>
<input type=submit value="Submit Info"><br>
</form>
';
?>


Step 3
Create new php document, name it submit.php

Use the following code:

CODE
<?php
include("connect.php");
mysql_query("UPDATE test SET
contents='$contents' WHERE ID='1' LIMIT 1");

echo('<center><font size=3>Thank you, data sent to Database</font>
<META HTTP-EQUIV="refresh" content="1; URL=http://www.url/folder/index.php">
');
?>


Rename:
CODE
http://www.url/folder/index.php


To whatever meets your specification.

Step 4
Create new php document, name it index.php

Insert the following code into index.php

CODE
<table width="201" border="0">
 <tr>
   <td width="82"><strong>Data</strong></td>
   <td width="500"><?php
include('connect.php');
$result = mysql_query("SELECT * FROM test");
while ( $row = mysql_fetch_array($result)) {
echo($row['contents']);
}
?> </td>
 </tr>
</table>


Above, i have contents & test. test is the name of my table in the database & contents is the name of the field.

In order to do this, go to your MyPhpAdmin & setup a new database, name the database whatever you want (note: Remember to change your field name and table name in all the files above also.)

Its very simple, that should be it complete!


Preview: http://www.jamie-barton.com/getphp/form.php



Have fun,

Regards,
Jamie smile.gif


IPB
 
+Quote Post  Go to the top of the page
*D*
post Jul 21 2004, 03:21 PM
Post #2


Merry KissMoose
Group Icon
Group: Main Team
Posts: 15,988
Joined: 18-May 04
From: North Pole
Member No.: 2





Kewl stuff Jamie but what would you use this for? Guestbook with a few more adjustments?
 
+Quote Post  Go to the top of the page
Jambo
post Jul 21 2004, 03:43 PM
Post #3


Addicted Dot
Group Icon
Group: *Premier*
Posts: 1,093
Joined: 19-May 04
From: The UK
Member No.: 4





Just teaching u php/mysql noobs (like myself) how to connect, get and post stuff to a database.


Thats all smile.gif


btw, this is Jamie, this is my new name victory.gif


IPB
 
+Quote Post  Go to the top of the page
Colin-uk
post Jul 22 2004, 12:28 AM
Post #4


Completely Dotty
Group Icon
Group: Member
Posts: 630
Joined: 8-June 04
From: UK
Member No.: 72





Thanks
nice to read a basic mysql tut when you just starting out in learning it bigwink.gif

and i wondered who it was lol ;P

This post has been edited by Colin-uk: Jul 22 2004, 12:28 AM


IPB
 
+Quote Post  Go to the top of the page
Iceshifter
post Jun 14 2005, 10:09 AM
Post #5


New Member
Group Icon
Group: Member
Posts: 3
Joined: 14-June 05
Member No.: 4,705



Hiyas, thanks for making this little tutorial. However, I'm proving to be more of an idiot than ever. I cannot seem to get this to work. This is the error I get on the index.php file. Any help to trouble shoot this would be greatly appreciated.


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/lyrics/public_html/lyrics/index.php on line 9
 
+Quote Post  Go to the top of the page
Iceshifter
post Jun 14 2005, 11:13 AM
Post #6


New Member
Group Icon
Group: Member
Posts: 3
Joined: 14-June 05
Member No.: 4,705



Nm, found out what it was. The table needed to be created in mysql. Might want to put this up a bit on the tutorial. I stressed out over this one LOL.

Also, this thread is the #1 hit on google for "php for noobs"
Thought you might like to know ^_~
 
+Quote Post  Go to the top of the page
90Design
post Jul 8 2005, 09:21 AM
Post #7


New Member
Group Icon
Group: Member
Posts: 9
Joined: 17-June 05
Member No.: 4,791



Nice tut smile.gif, ive created such a system mysel, (N00b @ PHP tongue.gif) Illtry to post it asap here
 
+Quote Post  Go to the top of the page

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 2nd December 2008 - 12:40 PM
Credit Report | Accommodation in Prague | Secured Loan | Myspace Codes | Loan