View Full Version : Newbie Trying out PHP/MySQL

07-25-2002, 08:33 PM
Ok...I'v started a MySql Db thanx to ipowerwebs easy setup feature and they gave me this PHP code to use for a connection...

Now what do i do with that....

Im trying to make a simple Form that will alow useres to enter their infomation and store it in my db..

It will serve no purpose i just want to do it so i can Add PHP/MySQL to my portfolio...Im really serious about learning this so is there anyone on AOL or AIM that might be able to help me one on one...Or can you guys start a step by step thing in this Thread...

I dont need it all in one day so if you just gave me a new thing to try every day that would make me go WOW! that would be great..

07-27-2002, 02:45 PM
What you're given is a connection. You put that at the top of your page (or just before you do any queries).


$db = mysql_connect ("","me","mypassword") or die ("Unable to connect");
mysql_select_db ("my_database_name") or die ("Cannot select database");

Then you can start querying!

to insert:

$result = mysql_query ("INSERT INTO table_name (field_name1,field_name1) VALUES ('$field_value1','$field_value2')") or die (mysql_error());

That'll insert the values $field_value1 and $field_value2 into the fields field_name1 and field_name2 which are in your table.

Make sure you have a table first, though. If you don't, use phpMyAdmin to make one.

Now to pull it out:

<table border="0">
<td bgcolor="#cccccc">Value of field_name1</td>
<td bgcolor="#cccccc">Value of field_name2</td>
$result = mysql_query ("SELECT * FROM table_name");
while ($row = mysql_fetch_array ($result)){
<? } ?>

That'll print the values of field_name1 and field_name2 in your DB.

Doh! I have to go to work now, so if you need anymore help which I assume you will, you can contact me at "aaronvvright @ hotmail DOT com"