Solved

Dynamic Drop Down insert PHP

Posted on 2011-03-17
6
270 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

758 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

21 Experts available now in Live!

Get 1:1 Help Now