matthewst Posted June 12, 2007 Share Posted June 12, 2007 Ok, here's one that has been buggin me all day. The page loads fine, it even emails like it's supposed to. The problem I'm having is that the email is only half complete. The email the page generates is supposed to have a restaurant name and a distributer name. example of a good email: Ad ordered for $company on $tablename example what I'm getting: Ad ordered for $company on the $company is the showing up just fine but the $tablename (which is also the rest_name) isn't showing up <? include('include/user_check.php'); include('include/db_con.php'); $id = $_SESSION['track_id']; $dest_email='me@me.net'; set_time_limit ( 0 ); if($submit) { if($P_There) { } else { if ($month < 10 && strlen($month) < 2) { $month='0'.$month; } if ($day < 10 && strlen($day) < 2) { $day='0'.$day; } mysql_query("INSERT INTO ad_order VALUES ('','$ad_num','0','$month/$day/$year','$year$month$day','0','0','0','$table_id','$Got_For','$company','$company_type', '$phone','$fax','$address','$city','$state','$zip','$email','$size','$quote_num','$direction','$cost','$deposit','$check_num','$buyer_name','$ssn','$home_phone', '$home_address','$special','$dest_email')", $db_link); $Get_ID_Num = mysql_query("SELECT id FROM ad_order WHERE order_id='$ad_num' ",$db_link); $ID_Num = mysql_fetch_array($Get_ID_Num); $save_copy = $ID_Num['id']; $ord_date = date('Y') . date('m') . date('d'); $pic_name_new = "$ord_date" . date('H') . date('i') . date('s') . $_SESSION['track_id'] . '.gif'; if($design_name) { copy ("$design", "/WebServer/WebSites/"."abcadmin/copy/$pic_name_new") or die("Could not copy file"); mysql_query("INSERT INTO copy (order_id,pic_location,type,ord_date) VALUES ('$save_copy','$pic_name_new','copy','$ord_date')",$db_link) or die("Please Contact JP Solutions"); } $get_username = mysql_query("SELECT * FROM sales_rep WHERE sales_id='$id'",$db_link); $get = mysql_fetch_array($get_username); $last_name = $get['lname']; $first_name = $get['fname']; //--------===========-----------===============----------THIS SHOULD WORK, BUT DOESN'T--------==============-----------=========--------* //$get_tablename = mysql_query("SELECT abc_tables.rest_name FROM abc_tables INNER JOIN ad_order on abc_tables.table_id = ad_order.cust_id WHERE ad_order.order_id=$ad_num limit 1",$db_link); $get_tablename = mysql_query("SELECT * FROM abc_tables INNER JOIN ad_order on abc_tables.table_id = ad_order.cust_id WHERE ad_order.order_id=$ad_num limit 1",$db_link); //$tablename = mysql_result($get_tablename,1); $g_tablename = mysql_fetch_array($get_tablename); $tablename=$g_tablename['rest_name']; //print (mysql_error()); //--------=========--------------============---------------END THIS SHOULD WORK-------------=============-------------=======----------* $msg .= "A new ad has been ordered for $company on $tablename. This order was placed by $first_name $last_name."; } $msg .= " View: http://www.website.com/get_ad.php?got=&project=$save_copy Sincerely, - abcadvertising.net"; mail($dest_email, "AD ordered for $company on $tablename", $msg, "From: me@me.net\r\n" ."Reply-To: me@me.net\r\n" ."X-Mailer: PHP/" . phpversion()); } //srand((double)microtime()*100000000000); $random = rand(0,999999999); $Num_Is = mysql_query("SELECT id FROM ad_order WHERE order_id='$random'", $db_link); $num = mysql_num_rows($Num_Is); while ($num) { //srand((double)microtime()*100000000000); $random = rand(0,999999999); $Num_Is = mysql_query("SELECT id FROM ad_order WHERE order_id='$random'", $db_link); $num = mysql_num_rows($Num_Is); } $Get_Cust = mysql_query("Select table_id, order_id, table_id, contact_fname, contact_lname, rest_name, set_no FROM abc_tables where dist_id='$id' and status_2<'6' order by rest_name, set_no",$db_link); $Get_Delegated = mysql_query("SELECT table_id , rest_name , set_no , status_3 FROM abc_tables WHERE (del_id_1='$id' or del_id_2='$id' or del_id_3='$id' or del_id_4='$id') and status_2<'6' order by rest_name, set_no", $db_link); ?> <HTML> <HEAD> <tr> <td width="150">Name of Restaurant</td> <td> <? if($under_who) { $Get_id_user = mysql_query("SELECT table_id FROM cust_order WHERE table_id='$under_who'",$db_link); $store_for = mysql_fetch_array($Get_id_user); $stored = $store_for['table_id']; $Get_cust_info = mysql_query("Select table_id, order_id, table_id, contact_fname, contact_lname, rest_name, set_no FROM abc_tables where dist_id='$under_who' AND status_2<'6' order by rest_name, set_no",$db_link); $get_er = mysql_fetch_array($Get_cust_info); echo '<b>' . $get_er['rest_name'] . '</b>'; ?> <input type="hidden" value="<?=$under_who;?>" name="table_id"> <? } else { ?> <select name="table_id" class="formTextbox" size="1"> <option value=""> -- Select Your Restaurant -- </option> <? while($row = mysql_fetch_array($Get_Cust)) { ?> <option value="<?=$row['table_id'];?>"><? echo $row['rest_name']. ' Set #'.$row['set_no']; ?></option> <? } ?> <option value=""> -- Select Delegated Restaurant -- </option> <? while($row = mysql_fetch_array($Get_Delegated)) { ?> <option value="<?=$row['table_id'];?>"><? echo $row['rest_name']. ' Set #'.$row['set_no']; ?></option> <? } ?> </select><? } ?></td> </tr> <tr> <td width="150">Salesperson</td> <td> <select name="Got_For" class="formTextbox"> <? $Get_For = mysql_query("SELECT * FROM sales_rep WHERE sales_id='$id' ORDER by lname", $db_link); //$checked = mysql_fetch_array($Get_For); //$Got_For = $checked['sales_id']; while($checked=mysql_fetch_array($Get_For)) { $Got_For = $checked['sales_id']; $lname = $checked['lname']; $fname = $checked['fname']; ?><option value="<?=$Got_For;?>"><? echo "$lname, $fname"; ?> </option> <? } ?> <? $Get_For = mysql_query("SELECT * FROM sales_rep where spons_id = '$id' ORDER by lname",$db_link); //$checked = mysql_fetch_array($Get_For); //$Got_For = $checked['sales_id']; while($checked=mysql_fetch_array($Get_For)) { $Got_For = $checked['sales_id']; $lname = $checked['lname']; $fname = $checked['fname']; ?> <option value="<?=$Got_For;?>"><? echo "$lname, $fname"; ?></option> <? } ?> </select> </td> </tr> <tr> <td width="150">Ad Size</td> <td><input type="text" class="formTextbox" name="size" size="24"></td> </tr> <tr> <td width="150";>Customer #</td> <td><input type="text" class="formTextbox" name="ad_num" value="<?=$random;?>" size="24" readonly></td> </tr> <tr> <td width="150">Ad #</td> <td><input type="text" class="formTextbox" name="quote_num" size="24"></td> </tr> <tr> <td width="150"></td> <br> <input type="submit" class="formTextbox" name="submit" value="Submit Ad Purchase"></div> </td> </tr> </table> <p><a href="http://www.website.com/admin/techsupport.php" target="_blank"><img src="../IMAGES/techsupport.gif" alt="" height="90" width="120" border="0"></a></p> </div> </form> </div> </TD> </TR> <TR> <TD COLSPAN=3><IMG SRC="images/inside_08.gif" WIDTH=758 HEIGHT=2></TD> </TR> </TABLE> </div> </BODY> </HTML> <? mysql_close(); ?> I had to yank a bunch of code out of the middle to make it fit but all the relevent code should still be there. Quote Link to comment https://forums.phpfreaks.com/topic/55328-solved-email-only-half-works-now-i-didnt-change-anythingreally/ Share on other sites More sharing options...
btherl Posted June 13, 2007 Share Posted June 13, 2007 Try tracking the value back through your code by printing it out. First, print it out immediately before the spot where it has the wrong value. If it's still wrong there, print it out a bit further back. Eventually you will find the exact location at which the value changes from being correct to incorrect (it may even have never been correct from the start). That's where the bug is. Quote Link to comment https://forums.phpfreaks.com/topic/55328-solved-email-only-half-works-now-i-didnt-change-anythingreally/#findComment-273620 Share on other sites More sharing options...
matthewst Posted June 13, 2007 Author Share Posted June 13, 2007 the weird thing is $company still works just not $tablename changed $post to $_post['submit'] I get these errors: Notice: Undefined variable: P_There in /Library/Tenon/WebServer/admin/ad_sale.php on line 18 18-22: if($P_There) { } else { if ($month < 10 && strlen($month) < 2) { $month='0'.$month; } Notice: Undefined variable: design_name in /Library/Tenon/WebServer/WebSites/admin/ad_sale.php on line 39 39-43: if($design_name) { copy ("$design", "/Library/WebServer/WebSites/www.website.net/"."admin/copy/$pic_name_new") or die("Could not copy file"); mysql_query("INSERT INTO copy (order_id,pic_location,type,ord_date) VALUES ('$save_copy','$pic_name_new','copy','$ord_date')",$db_link) or die("Please Contact JP Solutions"); } Notice: Undefined variable: msg in /Library/Tenon/WebServer/WebSites/admin/ad_sale.php on line 67 66-67: $msg .= "A new ad has been ordered for $company on $tablename. This order was placed by $first_name $last_name. "; Notice: Undefined variable: fail1 in /Library/Tenon/WebServer/WebSites/admin/ad_sale.php on line 137 137-138: if ($fail1=='1'){ $log .= "Couldn't copy file 1 to server - it may be too large, or the transfer may have been disrupted<br>"; Notice: Undefined variable: P_There in /Library/Tenon/WebServer/WebSites/admin/ad_sale.php on line 521 151: mysql_query("UPDATE ad_order SET flag='3' WHERE id='$save_copy'",$db_link); Notice: Undefined variable: under_who in /Library/Tenon/WebServer/WebSites/admin/ad_sale.php on line 639 639: <? if($under_who) { $Get_id_user = mysql_query("SELECT table_id FROM cust_order WHERE table_id='$under_who'",$db_link); $store_for = mysql_fetch_array($Get_id_user); $stored = $store_for['table_id']; Quote Link to comment https://forums.phpfreaks.com/topic/55328-solved-email-only-half-works-now-i-didnt-change-anythingreally/#findComment-273803 Share on other sites More sharing options...
GingerRobot Posted June 13, 2007 Share Posted June 13, 2007 Ok, just from a quick glance, would i be right in saying you're not getting this table_name from the database? In which case, you need to check your query. The best way is to put the query into a string, so you can echo it out. And dont forget the or die statement: <?php $query = "SELECT * FROM abc_tables INNER JOIN ad_order on abc_tables.table_id = ad_order.cust_id WHERE ad_order.order_id=$ad_num limit 1",$db_link); $get_tablename = mysql_query($query) or die(mysql_error()); echo $query; ?> That way, you can see exactly what query is being done. Quote Link to comment https://forums.phpfreaks.com/topic/55328-solved-email-only-half-works-now-i-didnt-change-anythingreally/#findComment-273809 Share on other sites More sharing options...
matthewst Posted June 13, 2007 Author Share Posted June 13, 2007 the input field "table_id" isn't being posted but all the others are ??? Quote Link to comment https://forums.phpfreaks.com/topic/55328-solved-email-only-half-works-now-i-didnt-change-anythingreally/#findComment-273837 Share on other sites More sharing options...
matthewst Posted June 13, 2007 Author Share Posted June 13, 2007 other drop down menus on the same page still work ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/55328-solved-email-only-half-works-now-i-didnt-change-anythingreally/#findComment-273863 Share on other sites More sharing options...
matthewst Posted June 13, 2007 Author Share Posted June 13, 2007 Ok, just from a quick glance, would i be right in saying you're not getting this table_name from the database? all the drop down menus are being populated from a database all of the others work (they post like they should) but table_id even though it populates properly it fails to post Quote Link to comment https://forums.phpfreaks.com/topic/55328-solved-email-only-half-works-now-i-didnt-change-anythingreally/#findComment-273865 Share on other sites More sharing options...
matthewst Posted June 13, 2007 Author Share Posted June 13, 2007 I've made progress....kind of. I tried to echo the variables: $get_id_user, $store_for, $stored I even tried to echo $row['rest_name'] //which is echoed in the drop down list// and they all came back empty but the drop down list populates ok drop down <option value="<?=$row['table_id'];?>"><? echo $row['rest_name']. ' Set #'.$row['set_no']; ?></option> what i tried to echo echo $row['rest_name']; Quote Link to comment https://forums.phpfreaks.com/topic/55328-solved-email-only-half-works-now-i-didnt-change-anythingreally/#findComment-273919 Share on other sites More sharing options...
matthewst Posted June 13, 2007 Author Share Posted June 13, 2007 In a nut shell: when the user fills out the form and clicks submit it generates an email containing the information in the form only part of the information is being "posted" to the email the $fname and $lname are working but the $tablename isn't this works: <td width="150">Salesperson</td> <td> <select name="Got_For" class="formTextbox"> <? $Get_For = mysql_query("SELECT * FROM sales_rep WHERE sales_id='$id' ORDER by lname", $db_link); //$checked = mysql_fetch_array($Get_For); //$Got_For = $checked['sales_id']; while($checked=mysql_fetch_array($Get_For)) { $Got_For = $checked['sales_id']; $lname = $checked['lname']; $fname = $checked['fname']; ?><option value="<?=$Got_For;?>"><? echo "$lname, $fname"; ?> </option> <? } ?> this dosen't: <td width="150">Name of Restaurant</td> <td> <? if($under_who) { $Get_id_user = mysql_query("SELECT table_id FROM cust_order WHERE table_id='$under_who'",$db_link); $store_for = mysql_fetch_array($Get_id_user); $stored = $store_for['table_id']; $Get_cust_info = mysql_query("Select table_id, order_id, table_id, contact_fname, contact_lname, rest_name, set_no FROM abc_tables where dist_id='$under_who' AND status_2<'6' order by rest_name, set_no",$db_link); $get_er = mysql_fetch_array($Get_cust_info); echo '<b>' . $get_er['rest_name'] . '</b>'; ?> <input type="hidden" value="<?=$under_who;?>" name="table_id"> <? } else { ?> <select name="table_id" class="formTextbox" size="1"> <option value=""> -- Select Your Restaurant -- </option> <? while($row = mysql_fetch_array($Get_Cust)) { ?> <option value="<?=$row['table_id'];?>"><? echo $row['rest_name']. ' Set #'.$row['set_no']; ?></option> <? } ?> <option value=""> -- Select Delegated Restaurant -- </option> <? while($row = mysql_fetch_array($Get_Delegated)) { ?> <option value="<?=$row['table_id'];?>"><? echo $row['rest_name']. ' Set #'.$row['set_no']; ?></option> <? } ?> </select><? } ?> both are drop down menus on the same page, both populate from the database properly Quote Link to comment https://forums.phpfreaks.com/topic/55328-solved-email-only-half-works-now-i-didnt-change-anythingreally/#findComment-273957 Share on other sites More sharing options...
matthewst Posted June 13, 2007 Author Share Posted June 13, 2007 as it turns out the page is posting the first selection in the database populated dropdown menus no matter what i select the table_id menu is blank when the page loads but the got_for menu has a default value no mater what i select the posted data is whatever the default value of the drop down menus are. drop downs that are hardcoded on the page post just fine How do i fix that? or Lets just start from scratch. How do I email the slection from a dropdow menu that is populated from a database Quote Link to comment https://forums.phpfreaks.com/topic/55328-solved-email-only-half-works-now-i-didnt-change-anythingreally/#findComment-273983 Share on other sites More sharing options...
matthewst Posted June 13, 2007 Author Share Posted June 13, 2007 Here is the page with only the relevent code present. (i just noticed that when I refresh it sends an email, even though I'm not clicking submit) <? include('include/user_check.php'); include('include/db_con.php'); $id = $_SESSION['track_id']; $dest_email='me@website.net'; set_time_limit ( 0 ); //error_reporting(E_ALL); if($_POST['submit']) { if($P_There) { } else { if ($month < 10 && strlen($month) < 2) { $month='0'.$month; } if ($day < 10 && strlen($day) < 2) { $day='0'.$day; } $Get_ID_Num = mysql_query("SELECT id FROM ad_order WHERE order_id='$ad_num' ",$db_link); $ID_Num = mysql_fetch_array($Get_ID_Num); $ord_date = date('Y') . date('m') . date('d'); $pic_name_new = "$ord_date" . date('H') . date('i') . date('s') . $_SESSION['track_id'] . '.gif'; $get_username = mysql_query("SELECT * FROM sales_rep WHERE sales_id='$id'",$db_link); $get = mysql_fetch_array($get_username); $last_name = $get['lname']; $first_name = $get['fname']; $msg .= "Display State: $company \nDisplay Restaurant name: $tablename. \nDisplay Distributer $first_name $last_name."; } $msg .= " View: http://www.website.net/abcadmin/get_ad.php?got=&project=$save_copy Sincerely, - abcadvertising.net"; mail($dest_email, "Display State: $company Display Restaurant name: $tablename", $msg, "From: me@website.net\r\n" ."Reply-To: me@website.net\r\n" ."X-Mailer: PHP/" . phpversion()); } //srand((double)microtime()*100000000000); $random = rand(0,999999999); $Num_Is = mysql_query("SELECT id FROM ad_order WHERE order_id='$random'", $db_link); $num = mysql_num_rows($Num_Is); while ($num) { //srand((double)microtime()*100000000000); $random = rand(0,999999999); $Num_Is = mysql_query("SELECT id FROM ad_order WHERE order_id='$random'", $db_link); $num = mysql_num_rows($Num_Is); } $Get_Cust = mysql_query("Select table_id, order_id, table_id, contact_fname, contact_lname, rest_name, set_no FROM abc_tables where dist_id='$id' and status_2<'6' order by rest_name, set_no",$db_link); $Get_Delegated = mysql_query("SELECT table_id , rest_name , set_no , status_3 FROM abc_tables WHERE (del_id_1='$id' or del_id_2='$id' or del_id_3='$id' or del_id_4='$id') and status_2<'6' order by rest_name, set_no", $db_link); ?> <HTML> <BODY BGCOLOR=#FFFFFF leftmargin="0" marginwidth="0" topmargin="0" marginheight="0"> <TABLE WIDTH=758 BORDER=0 CELLPADDING=0 CELLSPACING=0> <TR height="516"> <TD valign="top" height="516"> <form action="<?=$PHP_SELF;?>" method="post" enctype="multipart/form-data" name="FormName" onSubmit="return document.MM_returnValue"> <table border="0" cellpadding="0" cellspacing="2"> <tr> <td width="300">Name of Restaurant(populated from database)</td> <td> <? if($under_who) { $Get_id_user = mysql_query("SELECT table_id FROM cust_order WHERE table_id='$under_who'",$db_link); $store_for = mysql_fetch_array($Get_id_user); $stored = $store_for['table_id']; $Get_cust_info = mysql_query("Select table_id, order_id, table_id, contact_fname, contact_lname, rest_name, set_no FROM abc_tables where dist_id='$under_who' AND status_2<'6' order by rest_name, set_no",$db_link); $get_er = mysql_fetch_array($Get_cust_info); echo '<b>' . $get_er['rest_name'] . '</b>'; ?> <input type="hidden" value="<?=$under_who;?>" name="table_id"> <? } else { ?> <select name="table_id" class="formTextbox" size="1"> <option value=""> -- Select Your Restaurant -- </option> <? while($row = mysql_fetch_array($Get_Cust)) { ?> <option value="<?=$row['table_id'];?>"><? echo $row['rest_name']. ' Set #'.$row['set_no']; ?></option> <? } ?> <option value=""> -- Select Delegated Restaurant -- </option> <? while($row = mysql_fetch_array($Get_Delegated)) { ?> <option value="<?=$row['table_id'];?>"><? echo $row['rest_name']. ' Set #'.$row['set_no']; ?></option> <? } ?> </select><? } ?></td> </tr> <?php echo "$row"; ?> <tr> <td width="300">Salesperson(populated from database)</td> <td> <select name="Got_For" class="formTextbox"> <? $Get_For = mysql_query("SELECT * FROM sales_rep WHERE sales_id='$id' ORDER by lname", $db_link); //$checked = mysql_fetch_array($Get_For); //$Got_For = $checked['sales_id']; while($checked=mysql_fetch_array($Get_For)) { $Got_For = $checked['sales_id']; $lname = $checked['lname']; $fname = $checked['fname']; ?><option value="<?=$Got_For;?>"><? echo "$lname, $fname"; ?> </option> <? } ?> <? $Get_For = mysql_query("SELECT * FROM sales_rep where spons_id = '$id' ORDER by lname",$db_link); //$checked = mysql_fetch_array($Get_For); //$Got_For = $checked['sales_id']; while($checked=mysql_fetch_array($Get_For)) { $Got_For = $checked['sales_id']; $lname = $checked['lname']; $fname = $checked['fname']; ?> <option value="<?=$Got_For;?>"><? echo "$lname, $fname"; ?></option> <? } ?> </select> </td> </tr> <tr> <td width="300">Advertiser State:(hardcoded)</td> <td><select name="company" CLASS="formTextbox"> <option value="">--- Select US State ---</option> <option value="AL">Alabama</option> <option value="AK">Alaska</option> <option value="AZ">Arizona</option> <option value="AR">Arkansas</option> <option value="CA">California</option> <option value="CO">Colorado</option> <option value="CT">Connecticut</option> <option value="DE">Delaware</option> </select></td> </tr> </td> </tr> <tr> <td colspan="2"> <div align="center"> <br> <input type="submit" class="formTextbox" name="submit" value="Submit Ad Purchase"></div> </td> </tr> </table> </div> <?php echo "$id"; ?> </form> </div> </TD> </TR> </TABLE> </div> </BODY> </HTML> <? mysql_close(); ?> the drop down named company (hard-coded) posts just fine but the drop downs that populate from my database are just posting the default values Quote Link to comment https://forums.phpfreaks.com/topic/55328-solved-email-only-half-works-now-i-didnt-change-anythingreally/#findComment-274019 Share on other sites More sharing options...
matthewst Posted June 21, 2007 Author Share Posted June 21, 2007 I'm an idiot. As it turns out I didn't account for this insert query: mysql_query("INSERT INTO ad_order VALUES ('','$ad_num','0','$month/$day/$year','','$year$month$day','0','0','','0','$table_id','$Got_For','$company','$company_type','$phone','$fax','$address','$city','$state','$zip','$email','$size','$quote_num','$direction','$cost','$deposit','$check_num','$buyer_name','$ssn','$home_phone','$home_address','$special','$dest_email')",$db_link); when I added two new columns to the database. I needed to add a couple ,'', to get it right again. Quote Link to comment https://forums.phpfreaks.com/topic/55328-solved-email-only-half-works-now-i-didnt-change-anythingreally/#findComment-279352 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.