looking For A Script

Status
Not open for further replies.
Randomguy1 submits info in form , randomguy1 can see his submitted info and randomguy2's info , randomguy3's etc...
 
Ok...

You're going to need to have a server that supports PHP and you need a MySQL database. The PHP is for the coding part, and the MySQL database is used to store the information so it is there every time you go to the page (otherwise it would only stay there once and then disappear).

I made a very basic example for you. You'll need to upload four .php files.

First, we need to connect to MySQL.
Code:
<?php

if ($dbc = @mysql_connect ('localhost','database_username','database_user_password')) {
		if (!@mysql_select_db ('database_name'))
	{
			die ('

Could not select the database because: [b]' . mysql_error() . '[/b]</p>');
	}
		
} else {

	die ('

Could not connect to MySQL because: [b]' . mysql_error() . '[/b]</p>');

}

?>
Replace "database_username", "database_user_password", and "database_name" with the correct info and then save this file as "mysql.php".

Next, we need to create a table with the right info.
Code:
<?php

require_once('mysql.php');

$query = 'CREATE TABLE your_table_name ( your_table_name_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL, address TEXT NOT NULL, phonenumber VARCHAR(50) NOT NULL )';

if (@mysql_query ($query)) {
	print '

The table has been created.</p>';

} else {
	die ('

Could not create the table because: [b]' . mysql_error() . '[/b]</p>

The query being run was: ' . $query . '</p>');
}


mysql_close();

?>
Change "your_table_name" to whatever you want the table to be called. Save this file as "install.php".

Next, we need the script for the HTML forms which will enter the data into the database.
Code:
<html>
<body>

<?php

require_once('mysql.php');

	if (isset($_POST['submit'])) {

			$query = "INSERT INTO your_table_name (your_table_name_id, name, address, phonenumber) VALUES (0, '{$_POST['name']}', '{$_POST['address']}','{$_POST['phone_number']}')";


		if (@mysql_query ($query)) {

			print '

Your info has been submitted!</p>';

		} else { // MySQL Error

			die ('

Error:[b] ' . mysql_error() . '[/b]</p>');

		}

		mysql_close();

	} else { // Submit was not pressed

		print '<form method="post" action="page.php">
			

Name: <input type="text" name="name" />

			   Address: <input type="text" name="address" />

			   Phone Number: <input type="text" name="phone_number" />


				<input type="submit" name="submit" value="Submit" /></p></form>';

	}

?>
</body>
</html>
If you changed "your_table_name" to something else, you'll need to do so here as well. Save this page as "page.php".

Now we can make the final page which will retrieve the info from the database.
Code:
<html>
<body>

<?php

require_once('mysql.php');

	$query = 'SELECT * FROM your_table_name ORDER BY your_table_name_id DESC';

	if ($r = mysql_query ($query)) {

		while ($row = mysql_fetch_array ($r)) {

			print "


			{$row['name']}

			{$row['address']} 

			{$row['phonenumber']}

					</p>";

		}

	} else { // MySQL Error

		die ('

Error:[b] ' . mysql_error() . '[/b]</p>');

	}

	mysql_close();

?>

</body>
</html>
Keep in mind that if you changed "your_table_name" to something else you must do it here too.

Now, upload all four files to your hosting. Run "install.php" to create the tables with the needed columns. Then you can run "page.php" to submit the info to the database, and then run "page2.php" to see the info.

Click here to see an example.


If you have any more questions, feel free to ask.
 
Thanks but i get this error when submitting the page.php

Error: Table '**MY USERNAME**.tedt' doesn't exist
 
Did you change the table name?

If so, you have to change this part in the "install.php"
Code:
$query = "INSERT INTO your_table_name (your_table_name_id,

To fit your needs. Just change "your_table_name" to whatever you want the table to be called. You must do this in all the scripts.
 
Status
Not open for further replies.
Back
Top Bottom