Jump to content

Timb75

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Timb75's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. The code I have used to attempt that feat: <?php $con = mysql_connect("(database_name).mysql.aplus.net","yourDatabaseUsername","yourDatabasePassword"); //Replace with your actual MySQL DB Username and Password if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("yourDatabaseName", $con); //Replace with your MySQL DB Name $name=mysql_real_escape_string($_POST['name']); //This value has to be the same as in the HTML form file $email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file $sql="INSERT INTO form_data (name,email) VALUES ('$name','$email')"; /*form_data is the name of the MySQL table where the form data will be saved. name and email are the respective table fields*/ if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "The form data was successfully added to your database."; mysql_close($con); ?> Of course somethings were changed around...sent to the database, but the DB field was blank when I looked at it. Also, what is a good code to use when I do not want users to repeat their choices? SELECT DISTINCT did not work.
  2. Thanks for the help. I need help with the PHP, not the MySQL.
  3. Okay, here is the URL: http://www.olevetpossehideout.com/test/populate-list.php As you can see, it is for testing purposes. Now here is the code (which I shortened to save time) I got, forgive me if it is not very tidy: <?php $user = "username"; $host = "localhost"; $password = "password"; $dbName = "databasename"; /* make connection to database */ mysql_connect($host, $user, $password) OR DIE( "Unable to connect to database"); mysql_select_db($dbName) or die(mysql_error()); //did you forget this line? $sql = "SELECT DISTINCT Name FROM Teams"; $result = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT ?> <form action="process.php" method="post" name="vote"> <table border="0" cellpadding="2" cellspacing="0" align="center" width="400"> <tr> <td colspan="2" align="center"><b><font size="4">Top 25 poll</font></b><br> Please select all spots. <br>All teams are listed in alphabetical order.<br> No duplicates will be allowed!!!</td> </tr> <tr> <td>1.</td> <td> <select name="one"> <option>Who is #1?</option> <?php while ($row = mysql_fetch_array($result)) { echo "<option value=\"" . $row['Name'] . "\">" . $row['Name'] . "</option>\n"; } ?> </td> </tr> <tr> <td>2.</td> <td> <select name="two"> <option>Choose #2:</option> <?php $sql = "SELECT DISTINCT Name FROM Teams"; $result = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT while ($row = mysql_fetch_array($result)) { echo "<option value=\"" . $row['Name'] . "\">" . $row['Name'] . "</option>\n"; } ?> </td> </tr> <tr> <td>3.</td> <td> <select name="three"> <option>Choose #3:</option> <?php $sql = "SELECT DISTINCT Name FROM Teams"; $result = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT while ($row = mysql_fetch_array($result)) { echo "<option value=\"" . $row['Name'] . "\">" . $row['Name'] . "</option>\n"; } ?> </td> </tr> <tr> <td>4.</td> <td> <select name="four"> <option>Choose #4:</option> <?php $sql = "SELECT DISTINCT Name FROM Teams"; $result = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT while ($row = mysql_fetch_array($result)) { echo "<option value=\"" . $row['Name'] . "\">" . $row['Name'] . "</option>\n"; } ?> </td> </tr> <tr> <td>5.</td> <td> <select name="five"> <option>Choose #5:</option> <?php $sql = "SELECT DISTINCT Name FROM Teams"; $result = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT while ($row = mysql_fetch_array($result)) { echo "<option value=\"" . $row['Name'] . "\">" . $row['Name'] . "</option>\n"; } ?> </td> </tr> <tr><td colspan="2"> </td></tr> <tr> <td colspan="2" align="center"> </select> <input type="Submit"> </td> </tr> </table> </form> It seems to work fine...but... Where I need help is: 1. Does this appear to be coded correctly for using multiple drop down lists? 2. How do I prevent someone from submitting the same team twice (I thought SELECT DISTINCT would do it, but I think I am wrong)? and... 3. How do I get what is submitted to go to a database?
  4. That works....thanks. Now for my nex question: What do I need to do to create more than 1 drop down list that are stacked in different rows? How would I create the table to do so? I know HTML, the PHP is what is kicking my butt.
  5. that are populated using the database. I receive this error: No database selected SELECT Name FROM Teams Name is a field inside the Teams table if this helps. Here is the code I am using: <?php $user = ""; $host = ""; $password = ""; $dbName = "olevetpo_polls"; /* make connection to database */ mysql_connect($host, $user, $password) OR DIE( "Unable to connect to database"); mysql_select_db($dbName); //did you forget this line? $sql = "SELECT Name FROM Teams"; $query = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT ?> <form action="action" method="post"> <select name="option"> <?php while ($row = mysql_fetch_array($result)) { echo "<option value=\"" . $row['Name'] . "\">" . $row['Name'] . "</option>\n"; } ?> </select> <input type="submit"> </form> I left the database name, but not the rest for obvious reasons. First, I am a big time noob when it comes to php, I found this code here at phpfreaks. I do know that this only shows one drop list.... With that said, I need some other help too.... I am trying to create a college football human poll, so I need 24 more of these drop downs (stacked on top of each other and with #1, #2, #3, etc preceeding the dropdowns), but only one submit, after the final list. How would I do this?
×
×
  • 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.