Jump to content

Errors on Multiple Dropdown Selections


swatisonee

Recommended Posts

Hello:

 

Heres what i want to do on a single php file:

a. I have a form.

b. A user will select from the mysql tables a customer, the form needs to re-load to allow him to either select one of the customers and their corresponding address/contact info.

c Once selected, he continues with the rest of the form , filling in the data etc and then submits it for processing to another php script.

 

The code below seeks to do this but I am unable to spot the errors.  Would be obliged if someone could take a look and advise .

 

Many Thanks:Swati

 


<html>

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=Generator content="Microsoft Word 11 (filtered)">
<title>INTERACTION REPORT</title>
<?
header("Cache-Control: public");
include ("../include/session.php"); // session start
include ("../indl.php"); //db info for DB2
include ("../include/style.css"); 
//include ("../datepicker/datetimepicker_css.js"); //doesnt work - hence separate js below

$userid = $_SESSION['userid']; // works 
if(!isset($_SESSION['userid'])){
echo "<center><font face='Calibri' size='2' color=red>Sorry, Please login and use this page </font></center>";
exit;}

echo $userid; 
//works;
?>
<script type="text/javascript" src="http://www.abc.com/eecindl/Industrial/datepicker/datetimepicker_css.js"></script>

<SCRIPT language=JavaScript>

function reload(form)
{
var val=form.id.options[form.id.options.selectedIndex].value;
self.location="sales.php?userid=<? echo $userid ?>&cid=" + val ;
}


</script>
</head>

<td><h2 align=left style='text-align:left'><span lang=EN-US style='color:#000058'>
  UID: 
<input type=hidden name="uid" size=8 value="<? echo $userid ?>">
<input type=text name="uid"  size=8 value="<? echo $userid ?>" disabled="true">
</span></h2>
</td>
<td><h2 align=left style='text-align:left'><span lang=EN-US style='color:#000058'>Date:
<input id="meetdate1" type="text" size="12"> 
<a href="javascript:NewCssCal('meetdate1')"> 
<img src="http://www.abc.com/eecindl/Industrial/datepicker/images/cal.gif" width="16" height="16" alt="Pick a date"></a>
</span></h2>
</td>
</tr> // works fine till here


<p class=MsoNormal><span lang=EN-US style='color:#000058'>Company: </span>
<span lang=EN-US style='font-family:Calibri;color:#000058'><select name=cid><option value="">[select One]

//ideally i'd like the user to type a few letters of the company name and then filter out the dropdown accordingly. this pulls out the entire customer list which is unwieldy


<?

$sql = "SELECT * FROM `Customers` ORDER BY `Company` asc ";
$result = mysql_query($sql);
if ($myrow = mysql_fetch_array($result)) {
do { printf("<option value=%d>
      %s", $myrow["CID"], $myrow["Company"]);
}
if(isset($_GET['cid']))
{
$cat=$_GET['cid'];
}


if(isset($cid) and strlen($cid) > 0){

$sqlb = "SELECT Custaddress a USING(CID) INNER JOIN Cities t USING(CITYID) INNER JOIN v Custcontact WHERE a.CID = '$cid' ";
$resultb=mysql_query($sqlb) or die (mysql_error());
if (strlen($myrowb["Lastname"]) > 0)
{$ln=$myrowb["Lastname"];}
else {  $ln = $_GET["ln"];}

if (strlen($myrowb["Street"]) > 0)
{$street=$myrowb["Street"];}
else {  $street = $_GET["street"];}

if (strlen($myrowb["CITYID"]) > 0)
{$cityid=$myrowb["CITYID"];}
else {  $cityid = $_GET["citiyid"}

$sqlc = "SELECT * FROM Cities WHERE CITYID= '$cityid' ";
$resultc=mysql_query($sqlc) or die (mysql_error());
$city = $myrowc["City"];
}

echo "<form method=post action='report2.php?userid=<? echo $userid ?>&cid=<? echo $cid ?>&cityid=<? echo $cityid?>&ln=<? echo $ln ?>'>";


echo '<input name="cid" type="hidden" value="cid">';
echo '<input name="cityid" type="hidden" value="cityid">';
echo '<input name="companyname" type="hidden" value="companyname">';
echo '<input name="ln" type="hidden" value="ln">';


echo "<select name='cid' onchange=\"reload(this.form)\"><option value=''>Select one</option>";


} while($myrow = mysql_fetch_array($result)) {
if($myrow['CID']==@$cid)
{
echo "<option selected value='$myrow[CID]'>$myrow[Company]</option>"."<BR>";}
else
{echo  "<option value='$myrow[CID]'>$myrow[Company]</option>";}
}
echo "</select>";


?></td>


// here's the issue : on selecting company above, i want the form to reload and then give me data for the office address,city,and person met. From this the user will pick one row which has these 3 things and then the rest of the form gets filled in
  <p class=MsoNormal><span lang=EN-US style='color:#000058'>Type of
   lnteraction:<select name="category">
<option value="">[select One]
<option value="M">M: Meeting
<option value="T">T: Telephone
</select></span></b></p>
   </td>
<p class=MsoNormal><span lang=EN-US style='color:#000058'>Discussion details:
<textarea name="discussions" rows="30" cols="90"></textarea>

<table border="1" cellspacing="1" width="100%" bgcolor="#0000FF">
          <tr>
          <td width="50%" bgcolor="#3366FF"><p align="center"><font
          color="#FFFFFF" size="2" face="Tahoma">SUBMIT <input type="submit" value="Submit"></font></p>
          </td> </tr>  </table>

</form>

<p class=MsoNormal><span lang=EN-US style='color:#000058'> </span></p>

</div>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/201228-errors-on-multiple-dropdown-selections/
Share on other sites

I ended up adding a php page to extract the customer name first, but still have a problem making the rest of this work as commented in the code . Appreciate any pointers as the JS to reload the form doesnt run and the sql query at the bottom doesnt either

Thanks:Swati

 

<html>

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=Generator content="Microsoft Word 11 (filtered)">
<title>CUSTOMER INTERACTION REPORT</title>


<?
header("Cache-Control: public");
include ("../include/session.php"); // session start
include ("../indl.php"); //db info for DB2
include ("../include/style.css"); 

$userid = $_SESSION['userid']; // works 

if(!isset($_SESSION['userid'])){
echo "<center><font face='Calibri' size='2' color=red>Sorry, Please login and use this page </font></center>";
exit;}

//echo $userid; 

$cid = $_POST["choice"];
echo $cid;
// i ended up adding another php script to pre-select the customer

$sqlx = "SELECT * FROM Customers WHERE CID = '$cid' ORDER BY Company asc";

$resultx = mysql_query($sqlx) or die (mysql_error());
while ($myrowx=mysql_fetch_array($resultx)) {
$customer=$myrowx["Company"];
}
?>



<script type="text/javascript" src="http://www.blah.com/eecindl/Industrial/datepicker/datetimepicker_css.js">
//<form enctype='multipart/form-data' action='salesreport2.php?userid=<? echo $userid ?>&cid=<? echo $cid ?>&cityid=<? echo $cityid ?>' method='post'>
function reload(form)
{

var val=form.id.options[form.id.options.selectedIndex].value;
self.location="salesreport1.php?userid=<? echo $userid ?>&cid=<? echo $cid ?>&id=" + val ;

}

</script>


</head>


<body lang=EN-IN>
<div class=Section1>

<p class=MsoNormal align=right style='text-align:right'><span lang=EN-US
style='color:#000058'> </span></p>

<p class=MsoNormal><span lang=EN-US style='color:#000058'> </span></p>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 align=left
width=780 style='width:468.0pt;border-collapse:collapse;margin-left:7.25pt;
margin-right:7.25pt'>
<thead>
  <tr style='page-break-inside:avoid;height:25.2pt'>
   <td width=780 colspan=4 style='width:468.0pt;border:solid windowtext 1.0pt;
   background:#ECFFAF;padding:1.45pt 4.3pt 1.45pt 4.3pt;height:25.2pt'>
   <h1><span lang=EN-US style='font-size:14.0pt;color:#000058'>CUSTOMER
   INTERACTION REPORT</span></h1>
   </td>
  </tr>
</thead>
<tr style='page-break-inside:avoid;height:14.4pt'>
  <td width=390 colspan=2 style='width:234.0pt;border:solid windowtext 1.0pt;
  border-top:none;background:#C6FF0F;padding:1.45pt 4.3pt 1.45pt 4.3pt;
  height:14.4pt'>
  <h2 align=left style='text-align:left'><span lang=EN-US style='color:#000058'>
  UID: 
<input type=hidden name="uid" size=8 value="<? echo $userid ?>">
      <input type=text name="uid"  size=8 value="<? echo $userid ?>" disabled="true">

  </span></h2>
  </td>
  <td width=390 colspan=2 style='width:234.0pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  background:#C6FF0F;padding:1.45pt 4.3pt 1.45pt 4.3pt;height:14.4pt'>
  <h2 align=left style='text-align:left'><span lang=EN-US style='color:#000058'>Date:
  <input id="meetdate1" type="text" size="12"> 
  <a href="javascript:NewCssCal('meetdate1')"> 
  <img src="http://www.blah.com/eecindl/Industrial/datepicker/images/cal.gif" width="16" height="16" alt="Pick a date"></a>
  </span></h2>
  </td>
</tr>
<tr style='page-break-inside:avoid;height:12.95pt'>
  <td width=780 colspan=4 style='width:468.0pt;border:solid windowtext 1.0pt;
  border-top:none;padding:1.45pt 4.3pt 1.45pt 4.3pt;height:12.95pt'>
  <p class=MsoNormal><span lang=EN-US style='color:#000058'>Company: </span>
  <span lang=EN-US style='font-family:Calibri;color:#000058'>
   <input type=hidden name="customer"  value="<? echo $customer ?>" size="50">
<input type=text name="customer"  value="<? echo $customer?>" disabled="true" size="50" > </td>

</span>   </td> </tr>
<tr style='page-break-inside:avoid;height:12.95pt'>
  <td width=780 colspan=4 style='width:468.0pt;border:solid windowtext 1.0pt;
  border-top:none;padding:1.45pt 4.3pt 1.45pt 4.3pt;height:12.95pt'>
  <p class=MsoNormal><span lang=EN-US style='color:#000058'>Meeting Location:
  (if applicable) </span> 

<?

$sqla = "SELECT DISTINCT `CAID`,`Street` FROM `Custaddress` WHERE `CID`='$cid' ORDER BY `Street` asc";

$resulta=mysql_query($sqla) or die (mysql_error());

// get an sql error at this stage
// SELECT DISTINCT `CAID`,`Street` FROM `Custaddress` WHERE `CID`='288' ORDER BY `Street` ascYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'dec2e2728c4495c87624ccf49dbf0 ORDER BY `Lastname` asc' at line 1

if(isset($_GET['id']))
{
$cat=$_GET['id'];
}
//echo "</select>";

if(isset($id) and strlen($id) > 0){

$sqlb = "SELECT DISTINCT `CCID` FROM `Custcontact` WHERE `CAID`= $id  ORDER BY `Lastname` asc";

//echo $sqlb;
$resultb=mysql_query($sqlb) or die (mysql_error());

}
else{
$resultb=mysql_query("SELECT DISTINCT `CCID` FROM `Custcontact` ORDER BY `Lastname`  asc");

}

echo "<form method=post action='salesreport2.php?userid=<? echo $userid ?>&cid=<? echo $cid ?>'>";


echo '<input name="cid" type="hidden" value="cid">';


echo "<select name='id' onchange=\"reload(this.form)\"><option value=''>Select one</option>";


while($myrowa = mysql_fetch_array($resulta)) {
if($myrowa['CAID']==@$id)
{
echo "<option selected value='$myrowa[CAID]'>$myrowa[street]</option>"."<BR>";}
else
{echo  "<option value='$myrowa[CAID]'>$myrowa[street]</option>";}
}
echo "</select>";


?></td>

</tr>

<tr>

        <td>
        <?
     echo "<select name='ln'><option value=''>Select one</option>";
while($myrowb = mysql_fetch_array($resultb)) {
echo  "<option value='$myrowb[Lastname]'>$myrowb[Lastname]</option>";
}
echo "</select>";
?>

            </td>
?>

</p>
  </td>
</tr>
<tr height=0>
  <td width=360 style='border:none'></td>
  <td width=30 style='border:none'></td>
  <td width=150 style='border:none'></td>
  <td width=240 style='border:none'></td>
</tr>
</table>


<p class=MsoNormal><span lang=EN-US style='color:#000058'> </span></p>


<input type="hidden" name="cid" value="<? echo $cid ?>">
<input type="hidden" name="userid" value="<? echo $userid ?>">
//<input type="hidden" name=....others like this
  </form>

</div>

</body>

</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.