Log in

View Full Version : Whats code for this?



Oni
21-03-2007, 04:31 PM
As you probably know im a php noob but I want to know the code for the following.
A kind of form where you submit your
Name:
Site:
Description:
Then everyone else can view it.
Thanks, rep for all helpers.

Invent
21-03-2007, 04:40 PM
If no-one helps, message me on MSN when I come on and ill make the code for you.

Drompo
21-03-2007, 04:41 PM
http://www.habboxforum.com/showthread.php?t=318178&highlight=contact+Form

Hope that helps :D

Invent
21-03-2007, 04:46 PM
Thats a contact form which uses the mail() function.

How will this enable


That veryone else can view it.

He needs a regular script made which inserts the data into an SQL database and then display the data on a different page.

Oni
21-03-2007, 05:13 PM
I still need help so can you msn me whn your on? Ill be on appear offline.

Voldemort
21-03-2007, 10:45 PM
I have a sandbox that I made that will do a pretty basic version of that

do you just want a linear view, like


Name
Info
Info2
Info3
-----------
Name
Info
Info2
Info3
-----------
Name
Info
Info2
Info3
-----------
Name
Info
Info2
Info3
-----------
Name
Info
Info2
Info3

or something else?

Colin-Roberts
21-03-2007, 11:38 PM
some like this: http://colin-roberts.net/v2/show.php

Voldemort
22-03-2007, 01:09 AM
Can you use MySQL databases?

Voldemort
22-03-2007, 03:49 AM
Okay, I just tested this on my host, but I'm half asleep and I don't know if it'll work for you... it's also only half of the code (it'll do the database portion, but you won't see anything)
---------------------------------------------------------------

First log into your host and make a database, write down the name. Then create a table in that database, with these settings:

http://www.yodaofdarkness.com/sql/1.PNG

and fill it with these values:

http://www.yodaofdarkness.com/sql/2.PNG

You should now have a database name, a username, a password, and a table name.

form.html

<form action="processor.php" method="post">
First Name: <input type="text" name="first"><br />
Last Name: <input type="text" name="last"><br />
Hometown: <input type="text" name="home"><br />
Status: <input type="text" name="status"><br />
Grade: <select name="grade">
<option></option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>NA</option>
</select><br />
School: <input type="text" name="school"><br />
Sex: <select name="sex">
<option>M</option>
<option>F</option>
</select><br />
Favourite Town: <input type="text" name="town"><br />
Favourite Color: <input type="text" name="color"><br />
Best Friend(s): <input type="text" name="friends"><br />
Pets: <input type="text" name="pets"><br />
Siblings: <input type="text" name="siblings"> <br />
<input type="submit" name="submit" value="Submit">&nbsp;&nbsp;<input type="reset" name="reset" value="Reset">
</form>

processor.php

<?php

#-----------------------Config Variables---------------------------
$sitename = "localhost"; // Change only if your database is not on the same host as this page
$username = "myusername"; // Change this to your username
$password = "mypass"; // Change this to your password
$dbname = "database"; // Change this to your database name


#---------------------Connect to Database--------------------------
if ( $sqldb = mysql_connect($sitename, $username, $password ) ) {
print "Connection complete<br>";
}
else {
die ("Unable to connect to database. Error: <b>".mysql_error()."</b>");
}

if ( mysql_select_db( $dbname, $sqldb ) ) {
print "Select of database complete!<br>";
}
else {
die ("Select of database failed. Error number: <b>".mysql_errno()." Message: ".mysql_error()."</b>");
}


#-----------------Set user-defined variables-----------------------
$fir = $_POST['first'];
$lat = $_POST['last'];
$hom = $_POST['home'];
$sta = $_POST['status'];
$gra = $_POST['grade'];
$sch = $_POST['school'];
$sex = $_POST['sex'];
$tow = $_POST['town'];
$col = $_POST['color'];
$fri = $_POST['friends'];
$pet = $_POST['pets'];
$sib = $_POST['siblings'];

#-----------------Insert the data into the database-----------------
$query = 'INSERT INTO \''.$dbname.'\' (\'First\',\'Last\',\'Home\',\'Status\',\'Grade\', \'School\',\'Sex\',\'Town\',\'Color\',\'Friends\', \'Pets\',\'Siblings\')
VALUES ($fir,$lat,$hom,$sta,$gra,$sch,$sex,$tow,$col,$fri ,$pet,$sib)';

mysql_query($query);

#-------------------Close the database - Important!-----------------
mysql_close($sqldb);
?>

rest coming soon, or someone else can write it. G'night

Colin-Roberts
22-03-2007, 07:48 PM
if he wonts the code from mine he can have it.

Mentor
22-03-2007, 07:50 PM
Well, i cba to write the form, but for actualy presenting the data when its sent, this tutoral explains basicly how to do it via flat file.
http://www.spoono.com/php/tutorials/tutorial.php?id=32

Voldemort
22-03-2007, 11:07 PM
ah, I set it up for Colin's system thinking this was his thread

I was wondering why Colin already had one done but he was still asking for one... :P

Want to hide these adverts? Register an account for free!