Solved

Dynamic Drop Down insert PHP

Posted on 2011-03-17
6
274 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Making API calls from hashed passwords 26 52
MS Access - need to reduce row size 25 51
PHP and google maps 13 42
send post values 7 26
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

813 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

15 Experts available now in Live!

Get 1:1 Help Now