Solved

Dynamic Drop Down insert PHP

Posted on 2011-03-17
6
276 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

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.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

856 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