Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    226
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Newbie Trying out PHP/MySQL

    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..

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What you're given is a connection. You put that at the top of your page (or just before you do any queries).

    ex:

    $db = mysql_connect ("12.34.56.78","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:

    PHP Code:
    <table border="0">
    <tr>
    <td bgcolor="#cccccc">Value of field_name1</td>
    <td bgcolor="#cccccc">Value of field_name2</td>
    </tr>
    <?
    $result 
    mysql_query ("SELECT * FROM table_name");
    while (
    $row mysql_fetch_array ($result)){
    ?>
    <tr>
    <td><?=$row["field_name1"]?></td>
    <td><?=$row["field_name2"]?></td>
    </tr>
    <? ?>
    </table>
    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"

    Offtone.com - In the works...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •