www.webdeveloper.com
Results 1 to 6 of 6

Thread: How to enter dropdown menu options into phpmyadmin?

  1. #1
    Join Date
    Mar 2011
    Posts
    67

    How to enter dropdown menu options into phpmyadmin?

    Hi everyone,

    I have a select-and-go list as part of my order form. Here is the code for it:
    Code:
    	<select name="selectpoemtype">
    		<option orderfourline="">4 Line Poem/$15</option>
    		<option ordereightline="">8 Line Poem/$25</option>
    		<option ordertwelveline="">12 Line Poem/$40</option>
    		<option ordersixteenline="">16 Line Poem/$50</option>
    		<option ordertwentyline="">20 Line Poem/$75</option>
    	</select>
    How do I enter these options into my phpmyadmin table? I attached a picture of my phpmyadmin setup in case needed.

    Thank you,
    Randy
    Attached Images Attached Images

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,614
    I don't think there is enough information there for us to provide a meaningful answer yet. What does the "poem type" you are selecting have to do with the user data in the table you showed us in the image? (By the way: I suspect you want the firstname, lastname, and email fields to be VARCHAR, not INT?) You mention that this is part of an order form, which might imply that you need a separate database table to store information on each order, in which case that table would likely include a field that stores the "id" value from your users table in order to relate the order to the user (the the term "relational database").

    PS: Just to avoid confusion: you are using a MySQL database, and that is what your PHP code will be concerned with and as such will use MySQL or MySQLi functions; whereas phpMyAdmin is a PHP application designed to provide a convenient interface to MySQL for the administration of MySQL databases.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2011
    Posts
    67
    Thank you for the reply. Yes, on my website: www.poemscribe.com I have a page for ordering poems.

    I have a MySQL database setup to take the order and place the order in the database. I am trying to figure out how to make it so that what ever price option is chosen by the consumer, that will reflect in their order in the database.

    Here is my orderform:
    Code:
    <?php
    
    $dbc = mysqli_connect('localhost', 'mylogin', 'mypassword', 'mydbname')
    or die ('Error connecting to database.');
    
    $query = "INSERT INTO mydbname" (firstname) //not finished....
    
    
    <div id="form">
        <form method="post" action="orderform.php">
    	<label for="firstname">First Name:</label>
    	<div class="input"><input type="text" id="firstname" name="firstname" /></div><br />
    	
    	<label for="lastname">Last Name:</label>
    	<div class="input"><input type="text" id="lastname" name="lastname" /></div><br />
    
    	<label for="email">Email:</label>
    	<div class="input"><input type="text" id="email" name="email" /></div><br />
    
    	<label for="selectpoemtype">Select Poem Type:</label><br />
    	<select name="selectpoemtype">
    		<option orderfourline="">4 Line Poem/$15</option>
    		<option ordereightline="">8 Line Poem/$25</option>
    		<option ordertwelveline="">12 Line Poem/$40</option>
    		<option ordersixteenline="">16 Line Poem/$50</option>
    		<option ordertwentyline="">20 Line Poem/$75</option>
    	</select> 
    	<br />
    	<br />
    
    	<label for="keynames">"Key names to include?"</label>
    	<div class="input"><input type="text" id="keynames" name="keynames"/></div><br />
    
    	<label for="specificwords">Any specific words you would like to include in your poem?</label>
    	<div class="input"><input type="text" id="specificwords" name="specificwords" /></div><br />
    
    	<label for="poemisfor">Who is the poem for?</label>
    	<div class="input"><input type="poemisfor" id="poemisfor" name="poemisfor" /></div><br />
    
    	<label for="relationship">Relationship to you?</label>
    	<div class="input"><input type="relationship" id="relationship" name="relationship" /></div><br />
    
    	<label for="occasion">What is the occasion for this poem?</label>
    	<div class="input"><input type="occasion" id="occasion" name="occasion" /></div><br />
    
    	<label for="overallmessage">What do you want the overall message of this poem to be?</label>
    	<div class="input"><input type="overallmessage" id="overallmessage" name="overallmessage" /></div><br />
    
    	<label for="anythingelse">Any other information you would like for me to know?</label>
    	<div class="input"><input type="anythingelse" id="anythingelse" name="anythingelse" /></div><br />
    
    	<div class="input"><input type="submit" value="Submit" name="submit"</div>
    </form>
    </div><!--form-->
    
    <br />

    I hope this code helps you help me.

    thanks,
    randy

  4. #4
    Join Date
    Mar 2011
    Posts
    67
    Quote Originally Posted by NogDog View Post
    I don't think there is enough information there for us to provide a meaningful answer yet. What does the "poem type" you are selecting have to do with the user data in the table you showed us in the image? (By the way: I suspect you want the firstname, lastname, and email fields to be VARCHAR, not INT?) You mention that this is part of an order form, which might imply that you need a separate database table to store information on each order, in which case that table would likely include a field that stores the "id" value from your users table in order to relate the order to the user (the the term "relational database").

    PS: Just to avoid confusion: you are using a MySQL database, and that is what your PHP code will be concerned with and as such will use MySQL or MySQLi functions; whereas phpMyAdmin is a PHP application designed to provide a convenient interface to MySQL for the administration of MySQL databases.
    Thanks and yes, I understand the difference between PHP and phpmyadmin. We are unconfused.

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,614
    Set a value attribute in your option tags for what you want to use later in the form-processing code, e.g.:
    Code:
    	<select name="selectpoemtype">
    		<option value="4">4 Line Poem/$15</option>
    		<option value="8">8 Line Poem/$25</option>
    		<option value="12">12 Line Poem/$40</option>
    		<option value="16">16 Line Poem/$50</option>
    		<option value="20">20 Line Poem/$75</option>
    	</select>
    Then when you process the input, you want to validate that it is an allowed number of lines, and then correlate that number with a price. One possible strategy:
    PHP Code:
    <?php
    $priceByLines 
    = array(
       
    => 15,
       
    => 25,
       
    12 => 40,
       
    16 => 50,
       
    20 => 75
    );
    $linesOrdered = (!empty($_POST['selectpoemtype'])) ? (int)$_POST['selectpoemtype'] : 0;
    if(isset(
    $priceByLines[$linesOrdered])) {
       
    $price $priceByLines[$linesOrdered];
       
    // continue processing order.....
    }
    else {
       
    // invalid or missing selectpoemtype value, return error to user....
    }
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Mar 2011
    Posts
    67
    Thank you. I will give this a spin and see what happens.

    Randy

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles