Jump to content

PHP DropDown List - Send information selected to database


Brentatechnologies

Recommended Posts

Hey Everyone...

 

First off, I am only a young web developer and i'm working on a school project and am making a text-based game online...

 

Now what i'm having trouble with...

 

I want a drop-down list that has a list of characters classes

Clubber

Mixer

Sauceror

Tamer

 

And I want whatever is selected to be placed into the database along with the username/password (THIS ALL WORKS FINE JUST NOT THE DROP DOWN LIST)

 

All help appreciated

Will do now sorry :P

 

 

CODE:

 

<form enctype="multipart/form-data" action="sendfile.php" method="post">

  Gender:

  <select name="gender">

    <option value="Male"> Male</option>

    <option value="Female">Female</option>

  </select>

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

  <input type="submit" value="Add">

</form>

(example of what I want... except in php?)

 

 

 

 

database code:

This is what i'm having trouble with....

 

 

 

As I said still young...

What do you mean?

 

I meen, your php code.

 

CODE:

<center>

<?php

echo "<title>Register Here!</title>"; //Page title

echo "<h1>Register Page</h1>"; //Heading

echo "<form action='finished.php' method='post'>";

echo "Username: <input type='text' name='usrnme' /><br>";  //Username box

echo "Password: <input type='password' name='pwd' />  <br>"; //Password box

echo "<input type='hidden' name='registerform' value='1'>"; //Hidden Field.

echo "Character: <input type='text' name='class' /><br>"; //Class Field

echo "<input type='submit' value='submit'>"; //Submit button.

echo "</form>";

?>

</center>

 

 

finished.php:

<?php

session_start();

mysql_connect("", "", ""); // Server connection

mysql_select_db(""); // Database selection

$page = $_POST['registerform']; // Setting the page value

$user = $_POST['usrnme']; // Setting the user value

$pass = $_POST['pwd']; // Setting the pass value

 

if($page == 1)

{

    //This means that the page is the register form so the register form code goes here

    $query = mysql_query("select * FROM userdata WHERE username = '$user'"); // Queries the Database to check if the user already exists

    if(mysql_num_rows($query) !== 0) // Checks if there is any rows with that user

    {

        echo "THIS USER IS ALREADY TAKEN!"; // Stops there

    }

    else

    {

        mysql_query("INSERT INTO userdata (username, password) VALUES('$user', '$pass')"); // Inserts into the database.

        echo "REGISTERED! <BR> <a href='index.php'>Go to the login page</a>"; //Link and text to go to the login

 

    }   

}

?>

 

<?php

if($page == 0)

{

    //This means that the page is the login form so the register form code goes here

    $query = mysql_query("SELECT username FROM userdata WHERE username = '$user'"); // Queries the Database to check if the user doesn't exist

    if(mysql_num_rows($query) == 0) // Checks if there is any rows with that user

    {

        echo "User doesn't exist"; // Stops there

    }

    $query = mysql_query("SELECT username FROM userdata WHERE username = '$user' AND password = '$pass'");

    if(mysql_num_rows($query) !== 0) // Checks if there is any rows with that user and pass

    {

 

        echo "LOGGED IN! <BR> <a href='logged.php'>Go to the logged in</a>"; //Link and text to go to the login

        $_SESSION['LOGGEDIN'] = 1;

    }

   

}

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.