mardi 23 décembre 2014

How to generate selections for a drop down menu with rows/record data from a database that can populate a form?


I'm trying to figure out a way to pre fill a form with data with past form information submitted in the past.


I have a form and a database. In my form I have a input named “email” that holds the preloaded default value of a logged in members email address that is read-only.


How can I generate a selection under a drop down menu that when selected will pre fill a form with row/record data from my database.


I've been at if for weeks now and can not seem to find any sense of direction on how to achieve this. Can't really find any tutorials site, video, sample code or anything close on how to make this possible thanks for your help in advance.


FORM



</header>

<body>

<form action="/demoform/contact_form.php" class="well" id="contactForm" method="post" name="sendMsg" novalidate="">

<big>LOAD PAST ORDERS:</big>
<select id="extrafield1" name="extrafield1">
<option value="">Please select...</option>
<option value="xxx">SAMPLE SELECTION</option>
</select>

</br>

<input type="text" required id="mile" name="mile" placeholder="Miles"/>

</br>

<input id="email" name="email" placeholder="Email" required="" type="text" value="demo@gmail.com" readonly="readonly"/>

</br>

<input id="name" name="itemname" placeholder="ITEM NAME 1" required="" type="text" />

</br>

<input type="reset" value="Reset" />


<button type="submit" value="Submit">Submit</button>


</form>


</body>


</html>


PHP FILE



<?php

define('DB_NAME', 'u780546296_demo');
define('DB_USER', 'u780546296_demo');
define('DB_PASSWORD', 'apple9');
define('DB_HOST', 'mysql.1freehosting.com');

$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);

if(!$connection){
die('Database connection failed: ' . mysqli_connect_error());
}

$db_selected = mysqli_select_db($connection, DB_NAME);

if(!$db_selected){
die('Can\'t use ' .DB_NAME . ' : ' . mysqli_connect_error());
}

echo 'Connected successfully';

if (isset($_POST['itemname'])){
$itm = $_POST['itemname'];
}
else {
$itm = '';
}



if($_POST['mile']){
$mi = $_POST['mile'];
}else{
echo "Miles not received";
exit;
}



if($_POST['email']){
$email = $_POST['email'];
}else{
echo "email not received";
exit;
}




$sql = "INSERT INTO seguin_orders (itemname, mile, email)
VALUES ('$itm', '$mi', '$email')";

if (!mysqli_query($connection, $sql)){
die('Error: ' . mysqli_connect_error($connection));
}


PIC


http://ift.tt/1ta7nqK





Aucun commentaire:

Enregistrer un commentaire