OldManRiver Posted September 12, 2007 Share Posted September 12, 2007 All, Trying to get some understanding on this code: <?php $sql = "SELECT cli_no, cli_cnm FROM client ORDER BY cli_cnm;"; $result = mysql_query($sql); $comp_list=""; while ($row = mysql_fetch_assoc($result)) { $cn = $row['cli_no']; $vl = $row['cli_cnm']; $comp_list .= "<option value=$cn>$vl</option>"; } if (if-condition) { processing; } ?> <td width=150 align=left> <SELECT NAME="inv_cmp" onchange="this.form.submit()"> <?php echo $comp_list; ?> </SELECT> </td> Need to know whether this code calls current file/page again, or is a javascript needed? Also have seen this code: <td width=150 align=left> <SELECT NAME="inv_cmp" onchange="load(this.form)"> <?php echo $comp_list; ?> </SELECT> </td> Wonder which actually calls the current PHP page, without needing javascript? I've also seen examples where javascript is used to pickup and parse the selection values and pass them to PHP for processing, but want to stay java free, if I can. Please let me know what the code does and how best to approach a java free solution to my problem. I am trying to populate the remaining fields on my form, by executing a new MySQL query from the selection value. Thanks! OMR Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 12, 2007 Share Posted September 12, 2007 javascript != java! Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted September 12, 2007 Share Posted September 12, 2007 whne the drop down changes the page is submitted to its self (I don't see a form tag in there but assume there is one). what ever code is on teh page that uses the 'inv_cmp' will be affected... Quote Link to comment Share on other sites More sharing options...
OldManRiver Posted September 12, 2007 Author Share Posted September 12, 2007 All, Full code in pastebin at: http://pastebin.org/2293 Notice the echo statements: echo "Act => $action <br>"; echo "Sel => $select <br>"; both always come back blank. When this goes right they should have values after the form processes. Let me know what I need to change! Thanks! OMR Quote Link to comment Share on other sites More sharing options...
OldManRiver Posted September 12, 2007 Author Share Posted September 12, 2007 All, Updated code at: http://pastebin.org/2309 at least echos the selected field value when "submit" button is clicked, but does not process on the drop down update. Still needing the piece that makes this work. Thanks! OMR Quote Link to comment Share on other sites More sharing options...
OldManRiver Posted September 14, 2007 Author Share Posted September 14, 2007 All, So never did get answer on original Q. Which method it better? <SELECT NAME="inv_cmp" onchange="this.form.submit()"> or <SELECT NAME="inv_cmp" onchange="load(this.form)"> and do they need java or a javascript to run? If they must have java/javascript to run/execute, then how are the "selected option" index number and value passed from: <OPTION VALUE=$cn>$vl</OPTION>"; to PHP for processing in PHP? Thanks! OMR Quote Link to comment Share on other sites More sharing options...
OldManRiver Posted September 19, 2007 Author Share Posted September 19, 2007 when the drop down changes the page is submitted to its self (I don't see a form tag in there but assume there is one). what ever code is on the page that uses the 'inv_cmp' will be affected... Toon, Does not process unless the "Submit" button is clicked. Need it to update on the change. OMR Quote Link to comment Share on other sites More sharing options...
OldManRiver Posted September 20, 2007 Author Share Posted September 20, 2007 All, Here is current code: <?php require('./functions/db_connect.php'); $cur_cnt = "001"; $cur_dat = date("m/d/y"); $sql = "SELECT inv_no, inv_rep FROM invoice WHERE inv_dat=$cur_dat;"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $rct = $row['inv_no']; $rep = $row['inv_rep']; } if (isset($rct)) { $cur_cnt = $rct + 1; } $cur_yrr = date("y"); $cur_day = date("d"); $cur_mnt = date("m"); $cur_pre = $cur_yrr."-".$cur_mnt."-".$cur_day; $cur_inv = $cur_pre.$cur_cnt; $sql = "SELECT cli_no, cli_cnm FROM client ORDER BY cli_cnm;"; $result = mysql_query($sql); $comp_list=""; while ($row = mysql_fetch_assoc($result)) { $cn = $row['cli_no']; $vl = $row['cli_cnm']; $comp_list .= "<option value=$cn>$vl</option>"; } $frm_date = "<INPUT TYPE='text' SIZE=25 NAME='inv_dat' VALUE=$cur_dat>"; $frm_cont = "<INPUT TYPE='text' SIZE=25 NAME='inv_ctt'>"; $frm_invn = "<INPUT TYPE='text' SIZE=25 NAME='inv_num' VALUE=$cur_inv>"; $frm_emal = "<INPUT TYPE='text' SIZE=25 NAME='inv_eml'>"; $frm_ordr = "<INPUT TYPE='text' SIZE=25 NAME='inv_ord'>"; $frm_addr = "<INPUT TYPE='text' SIZE=25 NAME='inv_adr'>"; $frm_rpnm = "<INPUT TYPE='text' SIZE=15 NAME='inv_rep'>"; $frm_fobf = "<INPUT TYPE='text' SIZE=8 NAME='inv_fob'>"; $frm_city = "<INPUT TYPE='text' SIZE=25 NAME='inv_cty'>"; $frm_stat = "<INPUT TYPE='text' SIZE=2 NAME='inv_stt'>"; $frm_zipc = "<INPUT TYPE='text' SIZE=9 NAME='inv_zip'>"; $frm_phon = "<INPUT TYPE='text' SIZE=25 NAME='inv_phn'>"; $frm_faxn = "<INPUT TYPE='text' SIZE=25 NAME='inv_fax'>"; if (isset($HTTP_POST_VARS['process'])) { $select = (isset($HTTP_POST_VARS['inv_cmp']) ? $HTTP_POST_VARS['inv_cmp'] : ''); echo "Sel => $select <br>"; $sql = "SELECT * FROM client WHERE cli_no=$select;"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $row_cont = $row['$cli_ctt']; $row_emal = $row['$cli_eml']; $row_addr = $row['$cli_ad1']; $row_add1 = $row['$cli_ad2']; $row_add2 = $row['$cli_ad3']; if (!is_null($row_add1)) { $row_addr .= ", ".$row_add1; } if (!is_null($row_add2)) { $row_addr .= ", ".$row_add2; } $row_city = $row['$cli_cty']; $row_stat = $row['$cli_st']; $row_zipc = $row['$cli_zip']; $row_phon = $row['$cli_ph']; $row_faxn = $row['$cli_fax']; $frm_date = "<INPUT TYPE='text' SIZE=25 NAME='inv_dat' VALUE=$cur_dat>"; $frm_cont = "<INPUT TYPE='text' SIZE=25 NAME='inv_ctt' VALUE=$row_cont>"; $frm_invn = "<INPUT TYPE='text' SIZE=25 NAME='inv_num' VALUE=$cur_inv>"; $frm_emal = "<INPUT TYPE='text' SIZE=25 NAME='inv_eml' VALUE=$row_emal>"; $frm_addr = "<INPUT TYPE='text' SIZE=25 NAME='inv_adr' VALUE=$row_addr>"; $frm_rpnm = "<INPUT TYPE='text' SIZE=15 NAME='inv_rep' VALUE=$rep>"; $frm_city = "<INPUT TYPE='text' SIZE=25 NAME='inv_cty' VALUE=$row_city>"; $frm_stat = "<INPUT TYPE='text' SIZE=2 NAME='inv_stt' VALUE=$row_stat>"; $frm_zipc = "<INPUT TYPE='text' SIZE=9 NAME='inv_zip' VALUE=$row_zipc>"; $frm_phon = "<INPUT TYPE='text' SIZE=25 NAME='inv_phn' VALUE=$row_phon>"; $frm_faxn = "<INPUT TYPE='text' SIZE=25 NAME='inv_fax' VALUE=$row_faxn>"; } } /* <SCRIPT LANGUAGE=JavaScript> <!-- Hide from other browsers parent.location = this.form; // End hiding from other browsers --> </SCRIPT> */ ?> <html> <head> <title>MyOps System - Work Order</title> </head> <BODY BGCOLOR="#ffFFdd"> <FORM name="ops" METHOD="POST" ACTION="<?php $_SERVER['PHP_SELF']; ?>"> <TABLE BORDER=2 CELLPADDING=5 WIDTH=90% height=400 align=center BGCOLOR="#F0F8FF" > <TR> <TD> <TABLE BORDER=0 CELLPADDING=5 WIDTH=95% align=center BGCOLOR="#F0F8FF" class=bd> <TR> <TD colspan=10 ALIGN=center VALIGN=bottom> <H1>MyOps System - Work Order</H1> Company Selection Screen </td> </tr> <tr> <td width=50 align=right>Company:</td> <td width=150 align=left> <input type="hidden" name="process" value=""> <!!SELECT NAME="inv_cmp" onchange="this.form.submit()"> <SELECT NAME="inv_cmp" onchange="load(this.form)"> <?php echo $comp_list; ?> </SELECT> </td> <td width=70 align=right>Date:</td> <td align=left colspan=7><?php echo $frm_date; ?></td> </tr> <tr> <td align=right>Contact:</td> <td align=left><?php echo $frm_cont; ?></td> <td align=right>Invoice:</td> <td align=left colspan=7><?php echo $frm_invn; ?></td> </tr> <tr> <td align=right>EMail:</td> <td align=left><?php echo $frm_emal; ?></td> <td align=right>Order No:</td> <td align=left width=250 colspan=7><?php echo $frm_ordr; ?></td> </tr> <tr> <td align=right>Address:</td> <td align=left><?php echo $frm_addr; ?></td> <td align=right>Rep:</td> <td align=left colspan=4><?php echo $frm_rpnm; ?></td> <td align=right>FOB:</td> <td align=left colspan=2><?php echo $frm_fobf; ?></td> </tr> <tr> <td align=right>City:</td> <td align=left><?php echo $frm_city; ?></td> <td align=right>State:</td> <td align=left><?php echo $frm_stat; ?></td> <td align=right>Zip:</td> <td align=left colspan=5><?php echo $frm_zipc; ?></td> </tr> <tr> <td align=right>Phone:</td> <td align=left><?php echo $frm_phon; ?></td> <td align=right>Fax:</td> <td align=left colspan=7><?php echo $frm_faxn; ?></td> </tr> <tr> <td align=center colspan=10> <INPUT TYPE="submit" NAME="submit" VALUE="Submit"> </td> </tr> </TABLE> </td> </TR> </TABLE> </FORM> </BODY> </HTML> I had suggestion to add the hidden field, then to add a javascript, but script is wrong, cause now get a 404 error. Any help appreciated. Thanks! OMR Quote Link to comment Share on other sites More sharing options...
OldManRiver Posted September 20, 2007 Author Share Posted September 20, 2007 All, Final code: <?php require('./functions/db_connect.php'); $cur_cnt = "001"; $cur_dat = date("m/d/y"); $sql = "SELECT inv_no, inv_rep FROM invoice WHERE inv_dat=$cur_dat;"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $rct = $row['inv_no']; $rep = $row['inv_rep']; } if (isset($rct)) { $cur_cnt = $rct + 1; } $cur_yrr = date("y"); $cur_day = date("d"); $cur_mnt = date("m"); $cur_pre = $cur_yrr."-".$cur_mnt."-".$cur_day; $cur_inv = $cur_pre.$cur_cnt; $sql = "SELECT cli_no, cli_cnm FROM client ORDER BY cli_cnm;"; $result = mysql_query($sql); $comp_list=""; $select = (isset($HTTP_POST_VARS['inv_cmp']) ? $HTTP_POST_VARS['inv_cmp'] : ''); while ($row = mysql_fetch_assoc($result)) { $cn = $row['cli_no']; $vl = $row['cli_cnm']; if ($select==$row['cli_no']) { $comp_list = "<option value=$cn selected>$vl</option>"; } else { $comp_list .= "<option value=$cn>$vl</option>"; } } $frm_date = "<INPUT TYPE='text' SIZE=25 NAME='inv_dat' VALUE=$cur_dat>"; $frm_cont = "<INPUT TYPE='text' SIZE=25 NAME='inv_ctt'>"; $frm_invn = "<INPUT TYPE='text' SIZE=25 NAME='inv_num' VALUE=$cur_inv>"; $frm_emal = "<INPUT TYPE='text' SIZE=25 NAME='inv_eml'>"; $frm_ordr = "<INPUT TYPE='text' SIZE=25 NAME='inv_ord'>"; $frm_addr = "<INPUT TYPE='text' SIZE=25 NAME='inv_adr'>"; $frm_rpnm = "<INPUT TYPE='text' SIZE=15 NAME='inv_rep'>"; $frm_fobf = "<INPUT TYPE='text' SIZE=8 NAME='inv_fob'>"; $frm_city = "<INPUT TYPE='text' SIZE=25 NAME='inv_cty'>"; $frm_stat = "<INPUT TYPE='text' SIZE=2 NAME='inv_stt'>"; $frm_zipc = "<INPUT TYPE='text' SIZE=9 NAME='inv_zip'>"; $frm_phon = "<INPUT TYPE='text' SIZE=25 NAME='inv_phn'>"; $frm_faxn = "<INPUT TYPE='text' SIZE=25 NAME='inv_fax'>"; if (isset($HTTP_POST_VARS['process'])) { $sql = "SELECT * FROM client WHERE cli_no=$select;"; $result = mysql_query($sql); $rowcnt = mysql_num_rows($result); while ($row = mysql_fetch_assoc($result)) { $row_cont = $row['cli_ctt']; $row_emal = $row['cli_eml']; $row_addr = addslashes($row['cli_ad1']); $row_add1 = $row['cli_ad2']; $row_add2 = $row['cli_ad3']; if (!isset($row_add1)) { $row_addr .= ", ".addslashes($row_add1); } if (!isset($row_add2)) { $row_addr .= ", ".addslashes($row_add2); } $row_city = $row['cli_cty']; $row_stat = $row['cli_st']; $row_zipc = addslashes($row['cli_zip']); $row_phon = addslashes($row['cli_ph']); $row_faxn = $row['cli_fax']; $frm_date = "<INPUT TYPE='text' SIZE=25 NAME='inv_dat' VALUE=$cur_dat>"; $frm_cont = "<INPUT TYPE='text' SIZE=25 NAME='inv_ctt' VALUE=$row_cont>"; $frm_invn = "<INPUT TYPE='text' SIZE=25 NAME='inv_num' VALUE=$cur_inv>"; $frm_emal = "<INPUT TYPE='text' SIZE=25 NAME='inv_eml' VALUE=$row_emal>"; $frm_addr = "<INPUT TYPE='text' SIZE=25 NAME='inv_adr' VALUE='".$row_addr."'>"; $frm_rpnm = "<INPUT TYPE='text' SIZE=15 NAME='inv_rep' VALUE=$rep>"; $frm_city = "<INPUT TYPE='text' SIZE=25 NAME='inv_cty' VALUE=$row_city>"; $frm_stat = "<INPUT TYPE='text' SIZE=2 NAME='inv_stt' VALUE=$row_stat>"; $frm_zipc = "<INPUT TYPE='text' SIZE=9 NAME='inv_zip' VALUE=$row_zipc>"; $frm_phon = "<INPUT TYPE='text' SIZE=25 NAME='inv_phn' VALUE=$row_phon>"; $frm_faxn = "<INPUT TYPE='text' SIZE=25 NAME='inv_fax' VALUE=$row_faxn>"; } } ?> <html> <head> <title>MyOps System - Work Order</title> </head> <BODY BGCOLOR="#ffFFdd"> <FORM name="ops" METHOD="POST" ACTION="<?php $_SERVER['PHP_SELF']; ?>"> <TABLE BORDER=2 CELLPADDING=5 WIDTH=90% height=400 align=center BGCOLOR="#F0F8FF" > <TR> <TD> <TABLE BORDER=0 CELLPADDING=5 WIDTH=95% align=center BGCOLOR="#F0F8FF" class=bd> <TR> <TD colspan=10 ALIGN=center VALIGN=bottom> <H1>MyOps System - Work Order</H1> Company Selection Screen </td> </tr> <tr> <td width=50 align=right>Company:</td> <td width=150 align=left> <SELECT NAME="inv_cmp" onchange="document.forms['ops'].submit();"> <?php echo $comp_list; ?> </SELECT> </td> <td width=70 align=right>Date:</td> <td align=left colspan=7><?php echo $frm_date; ?></td> </tr> <tr> <td align=right>Contact:</td> <td align=left><?php echo $frm_cont; ?></td> <td align=right>Invoice:</td> <td align=left colspan=7><?php echo $frm_invn; ?></td> </tr> <tr> <td align=right>EMail:</td> <td align=left><?php echo $frm_emal; ?></td> <td align=right>Order No:</td> <td align=left width=250 colspan=7><?php echo $frm_ordr; ?></td> </tr> <tr> <td align=right>Address:</td> <td align=left><?php echo $frm_addr; ?></td> <td align=right>Rep:</td> <td align=left colspan=4><?php echo $frm_rpnm; ?></td> <td align=right>FOB:</td> <td align=left colspan=2><?php echo $frm_fobf; ?></td> </tr> <tr> <td align=right>City:</td> <td align=left><?php echo $frm_city; ?></td> <td align=right>State:</td> <td align=left><?php echo $frm_stat; ?></td> <td align=right>Zip:</td> <td align=left colspan=5><?php echo $frm_zipc; ?></td> </tr> <tr> <td align=right>Phone:</td> <td align=left><?php echo $frm_phon; ?></td> <td align=right>Fax:</td> <td align=left colspan=7><?php echo $frm_faxn; ?></td> </tr> <tr> <td align=center colspan=10> <INPUT TYPE="submit" NAME="next" VALUE="Submit"> </td> </tr> </TABLE> </td> </TR> </TABLE> <input type="hidden" name="process" value=""> </FORM> </BODY> </HTML> Solution to the problem was two fold: 1. Correct "onchange=" line: <SELECT NAME="inv_cmp" onchange="document.forms['ops'].submit();">, 2. Making sure there is only one "submit" on the form. I had to change the submit button name to "next". Thanks all for you help! OMR Quote Link to comment Share on other sites More sharing options...
OldManRiver Posted September 20, 2007 Author Share Posted September 20, 2007 I don't know if you think this is worthy, but DD-List updating is common, so maybe this should be in the knowledge base? OMR Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.