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.
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.
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
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
}
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.)
"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
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.
Bookmarks