Brentatechnologies Posted February 21, 2012 Share Posted February 21, 2012 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 Link to comment https://forums.phpfreaks.com/topic/257440-php-dropdown-list-send-information-selected-to-database/ Share on other sites More sharing options...
trq Posted February 21, 2012 Share Posted February 21, 2012 Post your code. Link to comment https://forums.phpfreaks.com/topic/257440-php-dropdown-list-send-information-selected-to-database/#findComment-1319453 Share on other sites More sharing options...
Brentatechnologies Posted February 21, 2012 Author Share Posted February 21, 2012 Will do now sorry 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.... Link to comment https://forums.phpfreaks.com/topic/257440-php-dropdown-list-send-information-selected-to-database/#findComment-1319456 Share on other sites More sharing options...
trq Posted February 21, 2012 Share Posted February 21, 2012 I meant the code that places the selection in the database. Link to comment https://forums.phpfreaks.com/topic/257440-php-dropdown-list-send-information-selected-to-database/#findComment-1319458 Share on other sites More sharing options...
Brentatechnologies Posted February 21, 2012 Author Share Posted February 21, 2012 As I said still young... What do you mean? Link to comment https://forums.phpfreaks.com/topic/257440-php-dropdown-list-send-information-selected-to-database/#findComment-1319460 Share on other sites More sharing options...
trq Posted February 21, 2012 Share Posted February 21, 2012 As I said still young... What do you mean? I meen, your php code. Link to comment https://forums.phpfreaks.com/topic/257440-php-dropdown-list-send-information-selected-to-database/#findComment-1319463 Share on other sites More sharing options...
Brentatechnologies Posted February 21, 2012 Author Share Posted February 21, 2012 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; } } Link to comment https://forums.phpfreaks.com/topic/257440-php-dropdown-list-send-information-selected-to-database/#findComment-1319474 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.