Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update statement does not work

Status
Not open for further replies.

btween

Programmer
Aug 7, 2003
338
US
I am trying to use a statement to update a varchar(30) field in a MySQL db. This statement is based on another statement that works. The only difference is that the working statement is using select boxes, and my statement is using a text box for the update.

Any help in figuring why my statement does not work is appreciated:

working statement:

Code:
// Shipping Date
if (isset($HTTP_POST_VARS["year"])) {
$updateSQL = sprintf("UPDATE juvent_orders SET shipped='%s' WHERE orderno='%s'",$HTTP_POST_VARS["year"].'-'.$HTTP_POST_VARS["month"].'-'.$HTTP_POST_VARS["day"],$HTTP_GET_VARS["orderno"]);
$Result1 = mysql_query($updateSQL, $con) or die(mysql_error());

}

Non-working statement:
Code:
// Serial
if (isset($HTTP_POST_VARS["serial"])) {
$updateSQL = sprintf("UPDATE juvent_orders SET serial='%s' WHERE orderno='%s'",$HTTP_POST_VARS["serial"],$HTTP_GET_VARS["orderno"]);
$Result1 = mysql_query($updateSQL, $con) or die(mysql_error());

}

 
Insufficient data for a meaningful answer.

Does an error get output by the "or die(mysql_error())" statement?
What does your query look like?




Want the best answers? Ask the best questions! TANSTAAFL!
 
that is the query there: "UPDATE juvent_orders SET shipped='%s' WHERE....

I'm not too familiar with PHP but maybe this will help. Following is the form that submits the data for the working query:
Code:
<form name="form2" method="post" action="orderdetail.php?orderno=<? echo $thisorder['orderno'];?>">

                    <select name="month" size="1" CLASS='' id="month">
                      <option value="01" selected>Jan</option>
                      <option value="02" <? if ($shipmonth=='02') echo 'selected';?>>Feb</option>
                      <option value="03" <? if ($shipmonth=='03') echo 'selected';?>>Mar</option>
                      <option value="04" <? if ($shipmonth=='04') echo 'selected';?>>Apr</option>
                      <option value="05" <? if ($shipmonth=='05') echo 'selected';?>>May</option>
                      <option value="06" <? if ($shipmonth=='06') echo 'selected';?>>Jun</option>
                      <option value="07" <? if ($shipmonth=='07') echo 'selected';?>>Jul</option>
                      <option value="08" <? if ($shipmonth=='08') echo 'selected';?>>Aug</option>
                      <option value="09" <? if ($shipmonth=='09') echo 'selected';?>>Sep</option>
                      <option value="10" <? if ($shipmonth=='10') echo 'selected';?>>Oct</option>
                      <option value="11" <? if ($shipmonth=='11') echo 'selected';?>>Nov</option>
                      <option value="12" <? if ($shipmonth=='12') echo 'selected';?>>Dec</option>
                    </SELECT>
                     
                    <select name="day" size="1" CLASS='' id="day">
                      <option value="01" selected>01</option>
                      <option value="02" <? if ($shipday=='02') echo 'selected';?>>02</option>
                      <option value="03" <? if ($shipday=='03') echo 'selected';?>>03</option>
                      <option value="04" <? if ($shipday=='04') echo 'selected';?>>04</option>
                      <option value="05" <? if ($shipday=='05') echo 'selected';?>>05</option>
                      <option value="06" <? if ($shipday=='06') echo 'selected';?>>06</option>
                      <option value="07" <? if ($shipday=='07') echo 'selected';?>>07</option>
                      <option value="08" <? if ($shipday=='08') echo 'selected';?>>08</option>
                      <option value="09" <? if ($shipday=='09') echo 'selected';?>>09</option>
                      <option value="10" <? if ($shipday=='10') echo 'selected';?>>10</option>
                      <option value="11" <? if ($shipday=='11') echo 'selected';?>>11</option>
                      <option value="12" <? if ($shipday=='12') echo 'selected';?>>12</option>
                      <option value="13" <? if ($shipday=='13') echo 'selected';?>>13</option>
                      <option value="14" <? if ($shipday=='14') echo 'selected';?>>14</option>
                      <option value="15" <? if ($shipday=='15') echo 'selected';?>>15</option>
                      <option value="16" <? if ($shipday=='16') echo 'selected';?>>16</option>
                      <option value="17" <? if ($shipday=='17') echo 'selected';?>>17</option>
                      <option value="18" <? if ($shipday=='18') echo 'selected';?>>18</option>
                      <option value="19" <? if ($shipday=='19') echo 'selected';?>>19</option>
                      <option value="20" <? if ($shipday=='20') echo 'selected';?>>20</option>
                      <option value="21" <? if ($shipday=='21') echo 'selected';?>>21</option>
                      <option value="22" <? if ($shipday=='22') echo 'selected';?>>22</option>
                      <option value="23" <? if ($shipday=='23') echo 'selected';?>>23</option>
                      <option value="24" <? if ($shipday=='24') echo 'selected';?>>24</option>
                      <option value="25" <? if ($shipday=='25') echo 'selected';?>>25</option>
                      <option value="26" <? if ($shipday=='26') echo 'selected';?>>26</option>
                      <option value="27" <? if ($shipday=='27') echo 'selected';?>>27</option>
                      <option value="28" <? if ($shipday=='28') echo 'selected';?>>28</option>
                      <option value="29" <? if ($shipday=='29') echo 'selected';?>>29</option>
                      <option value="30" <? if ($shipday=='30') echo 'selected';?>>30</option>
                      <option value="31" <? if ($shipday=='31') echo 'selected';?>>31</option>
                    </SELECT>
                     
                    <select name="year" size="1" CLASS='' id="year">
                      <option value="2006" selected>2006</option>
                      <option value="2007" <? if ($shipyear=='2007') echo 'selected';?>>2007</option>
                      <option value="2008" <? if ($shipyear=='2008') echo 'selected';?>>2008</option>
                      <option value="2009" <? if ($shipyear=='2009') echo 'selected';?>>2009</option>
                      <option value="2010" <? if ($shipyear=='2010') echo 'selected';?>>2010</option>
                    </SELECT>
                    <strong>Shipping Date</strong> &nbsp; &nbsp; 
                    
                    <a href="javascript:form2.submit();" ><img src="images/o_btn_save.gif" width="56" height="21" border="0" align="absmiddle"></a> 
                  </form>

The page orderdetail.php starts with:
Code:
<? session_start(); 

if (!isset($_SESSION['loggedin']) || ($_SESSION['loggedin']!=true)) {
$_SESSION['comefrom']='orderdetail.php?orderno='.$HTTP_GET_VARS["orderno"];
header('Location: login.php');
}

if (!isset($HTTP_GET_VARS["orderno"])) header('orderlist.php');
require_once('dbcon/con_order.php');
mysql_select_db($database_con, $con);

and then is followed by the working statement posted in the previous thread.

 
I don't think anyone here needs to see any morfe of your code.

The line which begins:

[tt]$updateSQL = sprintf("UPDATE juvent_orders[/tt]

creates a SQL statement and puts that statement in $updateSQL. I would like to see the query produced. This could be accomplished by your adding the statement:

[tt]print $updateSQL;[/tt]

just after the assignment line, then copying and pasting the query into a post here.

The reason I want to see the query is to verify that the query produced looks reasonable. This is described in my FAQ in this forum: faq434-2999


I also need to know what the line that reads:

[tt]$Result1 = mysql_query($updateSQL, $con) or die(mysql_error());[/tt]

is doing. Does the query generate an error, so that your script outputs the error and dies? Or does the query actually parse and run, but not do anything?

The reason I am asking this is I would like to verify that the database row you're trying to update actually exists. If you input an order number that does not exist in the database, the query will run. It simply does not update anything when it runs because there are no records matching the WHERE clause of your query. If this is the case, there is nothing wrong with your PHP code or your query, but rather with your input.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Thanks for the help but I figured it out. There was nothing wrong with the code. The javascript that submitted the form had javascript:form2.submit(); instead of javascript:forma.submit();

Sorry for the headache.

 
No problem.

But examining the actual query produced would likely have a long time ago given you the clue as to what was wrong. It's important when debugging to verify the state of variables rather than assuming everything is correct.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top