Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User submitted data?
#5
insert.php
PHP Code:
<?PHP

//Database Information

$dbhost "localhost";
$dbname "changethis";
$dbuser "changethis";
$dbpass "changethis";

//Connect to database

mysql_connect $dbhost$dbuser$dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

    
$name $_POST['name'];



// lets check to see if the username already exists

$checkuser mysql_query("SELECT username FROM users WHERE username='$username'");

$username_exist mysql_num_rows($checkuser);

if(
$username_exist 0){
    echo 
"I'm sorry but the name you specified has already been submitted.";
    unset(
$name);
    include 
'create.html';
    exit();
}

// lf no errors present with the username
// use a query to insert the data into the database.

$query "INSERT INTO users (firstnames)
VALUES('
$name')";
mysql_query($query) or die(mysql_error());
mysql_close();

echo 
"You have successfully Registered.";
?>
create.html
Code:
<html>
<body>

<form action="insert.php" method="post">
Firstname: <input type="text" name="name" />
<input type="submit" />
</form>

</body>
</html>

Not entirely sure if this is what you were looking for. But what this does is allows a user to submit a first name, it then add's that name to the database.
Of course you will have to change the database information as well.
[Image: pineapple.gif]
Reply


Messages In This Thread
User submitted data? - by ElephantShoe - 10-31-2010, 10:35 PM
RE: User submitted data? - by AceInfinity - 10-31-2010, 11:06 PM
RE: User submitted data? - by Brandon - 10-31-2010, 11:21 PM
RE: User submitted data? - by ElephantShoe - 10-31-2010, 11:22 PM
RE: User submitted data? - by Pineapple - 11-01-2010, 06:18 AM
RE: User submitted data? - by Bauer - 11-04-2010, 09:49 PM

Forum Jump:


Users browsing this thread: 6 Guest(s)