PDA

View Full Version : php database access



tyson59
March 11th, 2006, 03:37
anyone here able to point me in the direction of a premade script that i can change or even help me with a custom made script that from a form inputs
title, name, description, picture and location to a database

then also one that can display the contents in a format like this:

title - name - location
title - name - location

then if you cilck that it goes to full view of the ad

title | location
description picture
name

thanks in advance.

Richard
March 11th, 2006, 05:12
Not sure i understand what you mean?

Reading from a database and outputting results?

stuffradio
March 11th, 2006, 14:00
Ok, this is what you have to do...

config.php:


<?php
mysql_connect("localhost", "username", "password");
mysql_select_db("db_name");
?>

Ok, that first file there connects to the database. You need all that information so you can connect to it and dump data in to it. Next file you can
name it whatever you want, but I'm naming it index.php and I will have a form
that allows you to enter information in to the database.


index.php


<?php
// This is including the config file so it stores the db information.
include("config.php");

echo ("<form action=index.php?action=register method=post><table>
<tr>
<td>Username:</td> <td><input type=text name=username></td>
</tr>
<tr>
<td>Password:</td> <td><input type=password name=password></td>
</tr>
<tr>
<td colspan=2><input type=submit value=Register> <input type=reset value=Clear></td>
</tr></form></table>");

if ($action == "register") {
mysql_query("INSERT INTO dbname (username, password) VALUES ('$username', '$password')");
echo "You have registered your username and password. Click <a href=index.php>here</a> to continue.";
}
?>

That should be what you want! Good luck..