www.webdeveloper.com
Results 1 to 10 of 10

Thread: php input.

  1. #1
    Join Date
    May 2006
    Posts
    11

    Arrow php input.

    Ok. I am a php noobie. I have good knowledge of html but i know i need some php for this. Any help is very appreciated. thanks

    ok i want a page that has a simple form on it. There are two form inputs "Name" and "Picture Location." Upon the user pressing submit i am guessing that this information must be put into a database? I then need the code that will retrieve information from the database. I want the "Name" and "Picture Location" to be retrieved and put into this format. (hyperlink with frame target and name)

    Code:
    <A HREF="Picture Location retrieved from database eg. www.bob.com/pic.bmp" TARGET="C">Name retrieved from database</a><br>
    it wants to go into a page like this hopefully where the hyperlinks target url and text to display will be collected from the database. This is the code left hand panel on a page with 3 frames.

    Code:
    <HTML>
    <TITLE>Fa1.uK^ Pictures </TITLE>
    <b><u>Welcome to Pictures Page</u></b><br>
    <b>Clan Pictures</b><br>
    <A HREF="http://www.forwardasone.clanservers.com/images/1.JPG" TARGET="C">13th Match</a><br>
    <A HREF="http://www.forwardasone.clanservers.com/images/2.JPG" TARGET="C">13th Match</a><br>
    <A HREF="http://www.forwardasone.clanservers.com/images/3.JPG" TARGET="C">13th Match</a><br>
    <b>Members Pictures</b><br>
    Coming Soon......
    </HTML>
    the actual page is http://www.forwardasone.clanservers....ures/home.html

    email :> mathew.tew@gmail.com

    thanks
    cH3wY
    Last edited by cH3wY; 05-21-2006 at 11:52 AM.

  2. #2
    Join Date
    Apr 2006
    Location
    Silicon Valley
    Posts
    20
    Okay, to do that you need to know how to first desgin a database, second how to connect to it with PHP, and third how to read and write data to it with PHP.

    Let's start with simply designing the database. You're going to want a table of images with a field of name (varchar 255) and location (varchar 255) and id (int 11 unsigned auto_increment) which is a fairly simple design.

    You then can connect to the database with mysql_pconnect() in php, and mysql_select_db(). If you can get that far, we can talk you through querying the database to add and display records.

  3. #3
    Join Date
    May 2006
    Posts
    11
    ok thanks i will have a play with that and then PM you thanks

    cH3wY

  4. #4
    Join Date
    May 2006
    Posts
    11
    ok right i have been playing with the code and reading tutorials to try and understand stuff and i have come up with this code.

    i have used the "//" to make notes. I dont think that the timestamp is correct when i am creating a table

    Code:
    <html>
    
    //head and title
    <head>
    <title>PHP Pictures Test Page</title>
    </head>
    
    //creating and checking database 
    if ( $connid = mysql_connect ( 'localhost' 'username' 'password' ) )
      {  print '<p> Connection Established. </p>';
          if ( @mysql_query ( 'CREATE DATABASE Pictures' ) )
            {  print '<p> Database Created. Yey! <p>';
                if ( @mysql_select_db ( 'Pictures' ) )
                  { print '<p> Databse selected. Yey again! </p>';
                   }
                 else
                  {  die ( ' <p> Falied to Select... :'( ' , mysql_error ( ) , ' </p>' )
                   }
             }
           else
            {  die ( ' <p> Couldnt Create noooooo........ ' , mysql_error ( ) , ' </p>' )
             }
       }
     else
      {  die ( ' <p> Connection failed ' , mysql_error ( ) , ' </p>' )
       }
    
    //creating table
      CREATE TABLE PICTURES (
        contact_id   INT   IDENTITY (1, 1)   NOT NULL , 
        Picture Name   VARCHAR   (10)   NOT NULL ,          //field name Picture Name its a CHAR with 10 charactors top and cant be left empty right?
        URL   VARCHAR   (60)   NOT NULL ,                      //field name URL its a CHAR with 60 charactors top and cant be left empty right?
        UserName VARCHAR   (10)   NOT NULL                 //field name Picture Name its a CHAR with 10 charactors top and cant be left empty right?
        Date and Time DATETIME   (0)   NOT NULL     //Date and Time is field name and i want it too be automatic TIMESTAMP
      );
    
    </html>
    if this right i am going to crack open some beer cause i am proud of that my first database

    I dont understand what i should put in( $connid = mysql_connect ( 'localhost' 'username' 'password' ) ) should it be database name or IP? user name and password confuses me as it is defined by my previous question but if its database name then what do i set these as because i havnt password protected the database i have created in this code. I assume this is why when uploaded i get this error... www.forwardasone.clanservers.com/phpdata.php

    email :> mathew.tew@gmail.com

    cH3wY
    Last edited by cH3wY; 05-21-2006 at 11:52 AM.

  5. #5
    Join Date
    Apr 2006
    Location
    Silicon Valley
    Posts
    20
    Don't try to create your database/tables with PHP yourself. Instead, use a tool like phpmyadmin to do it graphically.

  6. #6
    Join Date
    May 2006
    Posts
    11
    ok then. I have made the database and tables i want using Access. how do i call for them now?

  7. #7
    Join Date
    Apr 2006
    Location
    Silicon Valley
    Posts
    20
    Assuming it's a MySQL database, you need to use mysql_pconnect(server, username, password); then mysql_select_db(database_name); to establish a connection from PHP. Then you can execute a series of queries to read and write data.

    To write data to the database, do something like mysql_query("INSERT INTO table_name SET column1='something', column2='something else'"); and to alter existing rows use something like mysql_query("UPDATE table_name SET column1='something', column2='something else' WHERE id='some id'");

    To read data from the database, store the results of a query in a variable. If you want to pull one specific row, do something like $results = mysql_query("SELECT * FROM some_table WHERE id='some id' LIMIT 1"); then $row = mysql_fetch_object($results); In order to access your data, do something like echo $row->column1; or echo $row->column2; etc.

    To read data when you're expecting multiple results from a query, do something like $results = mysql_query("SELECT * FROM some_table ORDER BY something"); then you place your rows through a loop such as:

    while ($row = mysql_fetch_object($results)) {
    echo $row->column1; etc
    }
    Last edited by Kethinov; 05-22-2006 at 06:24 PM.

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,617
    Quote Originally Posted by Kethinov
    Assuming it's a MySQL database, you need to use mysql_pconnect(server, username, password); ...
    Use mysql_connect() instead of mysql_pconnect() unless you understand the difference and know that you need to use mysql_pconnect() for your script. (And the odds are that you do not.)

    Also, it might be a good time to study this fairly short tutorial on using MySQL with PHP: http://www.zend.com/php/beginners/php101-8.php
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  9. #9
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    from the guide, these are the differences.

    Quote Originally Posted by php.net
    First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

    Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).
    So basically, any connections that come in are typically pooled into one connection. So you'd have to design a checking system to determine that the response is actually yours otherwise you have to throw it out.

    Since connections aren't too costly, this shouldn't be a big deal.

  10. #10
    Join Date
    May 2006
    Posts
    11
    thanks alot guys. I will read the tutorial now thanks NoDog. I will post back later if i have any problems.

    Thanks
    cH3wY

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles