[looking For A Script] - Computers



Search Tech-Forums - link takes you to our Forum's search page.

Note: The following is only a text archive!


To view the actual forum discussion, please visit our website at http://www.tech-forums.net

Pages:1



looking For A Script

(Click here to view the original thread with full colors/images)



Posted by: Tkey

im looking for a script that when user access page fills in feilds eg
Name
Address
Phone no

hit submit and then is able to view all of the submitted info

eg

Mr A Jones
44 aaa Road
09876545

Mr B Jones
45 aaa Road
98765443


is this possiable , will i need to database?



Posted by: Tkey

I have the follwing files

1 a simple form page that when subbmitted needs to enter info into database , this is what im struggling with , how do i enter the info into a database?

The also how do i view the info in the database ??



Posted by: baronvongogo

What are you creating the program in? visual basic? c# or using HTML and PHP with SQL?



Posted by: Tkey

Im not sure how i would do it thats the question , i was thinking html & php but im not sure if you can do that with the database?



Posted by: baronvongogo

if the database is SQL then php is the best way to do it. If its an access database then visual basic or c# would be better.



Posted by: Tkey

The database is MySQL



Posted by: Tkey

So do you have an idea how i could do this , i take it i would need to include the sql info in the php script?



Posted by: ainstushar

sorry to interrupt but,
THIS TOPIC SHOULD BE IN PROGRAMMER'S LEAGUE. NOT IN WWW!!
Hope that wasn't harsh. :)



Posted by: Tkey

Since im looking for the script and not actully programming ....



Posted by: CrazeD

Ok so wait...

You want a page with some forms. Randomguy1 fills out the forms, and hits submit. You want it to go to a page where Randomguy1 can see what he submitted, or do you want the info to be seen only by you (IE: email it to you)?

Either way is easy enough, but the code will differ greatly depending which way you want it done.

Lemme know exactly what you want and I can help.



Posted by: Tkey

Randomguy1 submits info in form , randomguy1 can see his submitted info and randomguy2's info , randomguy3's etc...



Posted by: CrazeD

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_pa
ssword')) {
if (!@mysql_select_db ('database_name'))
{
die ('<p>Could not select the database because: <b>' . mysql_error() . '</b></p>');
}

} else {

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

}

?>
[/code]
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 '<p>The table has been created.</p>';

} else {
die ('<p>Could not create the table because: <b>' . mysql_error() . '</b></p><p>The query being run was: ' . $query . '</p>');
}


mysql_close();

?>
[/code]
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 '<p>Your info has been submitted!</p>';

} else { // MySQL Error

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

}

mysql_close();

} else { // Submit was not pressed

print '<form method="post" action="page.php">
<p>Name: <input type="text" name="name" /><br />
Address: <input type="text" name="address" /><br />
Phone Number: <input type="text" name="phone_number" /><br /><br />
<input type="submit" name="submit" value="Submit" /></p></form>';

}

?>
</body>
</html>
[/code]
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 "<p>
{$row['name']}<br />
{$row['address']} <br />
{$row['phonenumber']}<br />
</p>";

}

} else { // MySQL Error

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

}

mysql_close();

?>

</body>
</html>
[/code]
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.

[url=http://crazed.110mb.com/test/page.php]Click here to see an example.[/url]


If you have any more questions, feel free to ask.



Posted by: Tkey

Thanks but i get this error when submitting the page.php

Error: Table '**MY USERNAME**.tedt' doesn't exist



Posted by: CrazeD

Did you run the "install.php" file?



Posted by: Tkey

yes and it says the table was done successfully



Posted by: CrazeD

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,[/code]

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.





vBulletin Copyright ©2000 - 2003, Jelsoft Enterprises Limited.


PPC Management
vB Easy Archive Final - Created by Xenon