Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User submitted data?
#1
Alright, I'll try to explain this the best I can.

How would I make a website where users can submit their own data to a database. For example, (I'm not doing this, it's just an example) say I have a website with a database full of first names. Someone's name, because it's unique, isn't on there. How would that person add their name to the database. I'm sorry if it doesn't make sense, but I'm tired right now and can't explain it in a better way. What type of language would I need to know for this?

It's kind of like UrbanDictionary.com. If you click a letter of the alphabet on the top bar, it'll come with all of the user submitted names and definitions with that specific letter.

I'm assuming this is PHP? Can anyone fill me in please?
[Image: fixedt.png]
Reply
#2
Yeah, based on what you have wrote (I'm not sure if I have the right idea) but this is php. mysql databases.
Reply
#3
It's all done in PHP / mySQL. I could sit here and explain the basics, but I personally believe you could easily accomplish this reading the basic tutorials.

PHP is the actual code, and mySQL would be what would store the stuff. You would insert into mySQL using code, and then use a query to find all "a" entries in the mySQL database.

You can learn a lot of this stuff from online tutorials. I assure you something like that wouldn't be that hard to accomplish. It'll take a bit to learn but it's WELL worth it. It's the only language I feel the need to go into detail in learning and striving to do well in it.

Oh, it could be done using other languages too. But PHP is the tried and tested best(IMO), although there is obviously other ones to use.
Reply
#4
Thank you guys for the quick responses!
[Image: fixedt.png]
Reply
#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
#6
Yes, the best way to do this is with PHP.

Learn about MySQL databases and INSERT with PHP.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)