vanvoquan Posted March 6, 2009 Share Posted March 6, 2009 Hi everyone, I try to use this form for my site but the if and else statement doesn't work. I want my customers to chose for the quantity they desire and if they don't, the form automatic post an value of " 1 " to the quantity in the database. But for some reason, if my customers not chose the quantity, the form automatic post a " 0 " for the quantity in the database. Below is the code of the form, any help will be greatly appriciate. thank you. <tr> <? if($row['selling_method']=="auction" or $row['selling_method']=="dutch_auction") { if($row[Quantity] > 0) { ?> <form name="fix_form" action="detail.php" method="post"> <td height="27" class="banner1">Quantity</td><td>:</td> <td align="left"> <select name=qty <?if($row[Quantity]==0 or $row[status]=='Closed'){echo "disabled";}?>> <option value="Quantity">Quantity</option> <? for($i=1;$i<=$row[Quantity];$i++) { ?> <option value="<?= $i;?>"><?= $i;?></option> <? } ?> </select> </td> <? } ?> </tr> <? } else { ?> <input type="hidden" name="qty" value="1"> <? } ?> <tr> <input type="hidden" value="1" name="flag"> <input type="hidden" value="<?= $err_flag; ?>" name="err_flag"> <input type="hidden" value="fix" name="sell_method"> <input type="hidden" value="<?= $item_id;?>" name="item_id"> <input type="hidden" value="<?= $row[quick_buy_price];?>" name="fixed_price"> <td class="banner1">Buy It Now Price</td> <td class="banner1">:</td> <td width="45%" class="detail888txt">US <?= $row['currency']; ?><?= $row['quick_buy_price']; ?>           <input type="image" src="images/images/buyit.gif" name="Image70" value="buy" width="81" height="24" border="0" id="Image70" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image70','','images/images/buyito.gif',1)" onClick="return confirm_buynow(<?=$row[Quantity];?>)"; <?if(($row[Quantity]==0) or ($row[status]=='Closed') or ($today_date<0)){echo "disabled";}?> </td> </form> </tr> Quote Link to comment Share on other sites More sharing options...
btherl Posted March 6, 2009 Share Posted March 6, 2009 You can't use php like that .. it can't modify the form after printing it out. But what you can do is have the php script that accepts the form check the quantity, and set it to 1 if it's not set in the form. Edit: Alternatively, you can use javascript to set the value just before the form is submitted. Quote Link to comment Share on other sites More sharing options...
vanvoquan Posted March 6, 2009 Author Share Posted March 6, 2009 thanks for your respond. I'm not very good at php. Can you provide me in more detail about how to write a php script that accetps the form check the quantity. Thanks alot ! Quote Link to comment Share on other sites More sharing options...
btherl Posted March 6, 2009 Share Posted March 6, 2009 Well, if you have a form, you must also have a script that accepts values from the form. If you post the code for that I can show you how to modify it to have a default value for quantity. Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 6, 2009 Share Posted March 6, 2009 please remove this post it was posted in the wrong post /Cheers Quote Link to comment Share on other sites More sharing options...
ztealmax Posted March 6, 2009 Share Posted March 6, 2009 ohh can someone delete my post, it posted in the wrong post??? Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 6, 2009 Share Posted March 6, 2009 // if you want that effect why this there then please? //And post your code as we can not guess your coding and my Cristal ball broke. if($row[Quantity]==0 Quote Link to comment Share on other sites More sharing options...
vanvoquan Posted March 7, 2009 Author Share Posted March 7, 2009 Thanks for all the helps. With the guides from all of you, I fix the code and it works. Thanks so much. if($qty==0) { $query="update placing_item_bid set status='Closed',Quantity='0',quantity_sold='1',sale_price=$fix where item_id='$item_id'"; mysql_query($query); } else if($qty > 0) { $query="update placing_item_bid set status='Closed',Quantity='$quantitans',quantity_sold='$qty',sale_price=$fix where item_id='$item_id'"; mysql_query($query); } 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.