Solved

Dynamic Drop Down insert PHP

Posted on 2011-03-17
6
273 Views
Last Modified: 2012-05-11
Hi Experts,

Ive got a probably rather simple question for you guys.

How do i post the data from a drop down box created dynamicly and post the information selected to the next page and then insert the data into my database..

both pages of code are attached..

am i doing something wrong here?

many thanks
//////////////////// FORM FOR GETTING THE DYNAMIC DROP DOWN ////////////////

<?php
$sql = "SELECT customer_name FROM customer ORDER BY title";
$rs = mysql_query($sql);
echo $sql;
while($row = mysql_fetch_array($rs)) {
  echo "<option value=\"".$row['customer_name']."\">" . $row['customer_name'] . "</option>"; 

}
?>
</select></td>
</tr>
<tr>
<td bgcolor="#ffffff">Mobile Number</td>
<td bgcolor="#ffffff">:</td>
<td bgcolor="#ffffff"><input type ="text" size="20" maxlength="15" name="mobile_number"> </td>
</tr>
<tr>
<td bgcolor="#ffffff">Month of Connection</td>
<td bgcolor="#ffffff">:</td>
<td bgcolor="#ffffff"><input type ="text" size="20" maxlength="30" name="month_conn"> </td>
</tr>
<tr>
<td bgcolor="#ffffff">Contract Start Date</td>
<td bgcolor="#ffffff">:</td>
<td bgcolor="#ffffff"><input type ="text" size="20" maxlength="30" name="start_contract"> </td>
</tr>
<tr>
<td bgcolor="#ffffff">Contract End Date</td>
<td bgcolor="#ffffff">:</td>
<td bgcolor="#ffffff"><input type ="text" size="20" maxlength="30" name="end_contract"> </td>
</tr>
<tr>
<td bgcolor="#ffffff">IMEI</td>
<td bgcolor="#ffffff">:</td>
<td bgcolor="#ffffff"><input type="text" size="20" maxlength="40" name="IMEI"></td>
</tr>
<td bgcolor="#ffffff">Type Of Account (Con/Upg)</td>
<td bgcolor="#ffffff">:</td>
<td bgcolor="#ffffff"><input type ="text" size="20" maxlength="3" name="type_acc">
</td>
</tr>
<tr>
<td bgcolor="#ffffff">Account Number</td>
<td bgcolor="#ffffff">:</td>
<td bgcolor="#ffffff"><input type="text" size="20" maxlength="20" name="account_number"></td>
</tr>
<tr>
<td bgcolor="#ffffff">Term</td>
<td bgcolor="#ffffff">:</td>
<td bgcolor="#ffffff"><input type="text" size="20" maxlength="15" name="term"></td>
</tr>
<tr>
<td bgcolor="#ffffff">Tariff</td>
<td bgcolor="#ffffff">:</td>
<td bgcolor="#ffffff"><input type="text" size="20" maxlength="25" name="tariff"></td>
</tr>
<tr>
<td bgcolor="#ffffff"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</form>

///////////////// THE INSERT PAGE ////////////////


<?php
session_start();
ob_start();
?>
<?php 
error_reporting(E_ALL);

$customer_name = $_POST['ddlCompanies'];
$mobile_number = $_POST['mobile_number'];
$month_conn = $_POST['month_conn'];
$start_contract = $_POST['start_contract'];
$end_contract = $_POST['end_contract'];
$IMEI = $_POST['IMEI'];
$type_acc = $_POST['type_acc'];
$account_number = $_POST['account_number'];
$term = $_POST['term'];
$tariff = $_POST['tariff'];
include 'myphp.php';




//insert details gatherd from registertation form into the datbase

$sql="INSERT INTO customer_details(customer_name, mobile_number, month_conn, start_contract, end_contract, IMEI, type_acc, account_number, term, tariff)VALUES('".$customer_name."', '".$mobile_number."', '".$month_conn."', '".$start_contract."', '".$end_contract."', '".$IMEI."', '".$type_acc."', '".$account_number."', '".$term."', '".$tariff."')";
$result=mysql_query($sql);

if($result){
	echo"Successful";
	echo"<BR>";
	echo"<a href='home.php'>Back to admin home</a>";
}
else{
	echo "ERROR";
}
mysql_close();

?>

Open in new window

0
Comment
Question by:NeoAshura
  • 3
  • 3
6 Comments
 
LVL 24

Expert Comment

by:mankowitz
ID: 35157086
where's the beginning of the select tag. All you posted was this:

<?php
$sql = "SELECT customer_name FROM customer ORDER BY title";
$rs = mysql_query($sql);
echo $sql;
while($row = mysql_fetch_array($rs)) {
  echo "<option value=\"".$row['customer_name']."\">" . $row['customer_name'] . "</option>";

}
?>
</select>


Does it generate the dropdown box for you?
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35157100
apologies, here you go.


<select id="ddlCompanies">
<?php
$sql = "SELECT customer_name FROM customer ORDER BY title";
$rs = mysql_query($sql);
echo $sql;
while($row = mysql_fetch_array($rs)) {
  echo "<option value=\"".$row['customer_name']."\">" . $row['customer_name'] . "</option>";

}
?>
</select>
0
 
LVL 6

Accepted Solution

by:
NeoAshura earned 0 total points
ID: 35157409
problem solved was a stupid error i didn't give my select box a name.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 24

Expert Comment

by:mankowitz
ID: 35157477
change it to <select name="ddlCompanies">
0
 
LVL 24

Expert Comment

by:mankowitz
ID: 35157478
oops. you got it.
0
 
LVL 6

Author Closing Comment

by:NeoAshura
ID: 35187298
own problem solved.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now