abdu808 Posted May 19, 2015 Share Posted May 19, 2015 hi every body my database 1st table =>(basket) {b_id | basket_name | qu | basket_price | active | date_insert} 2nd table => (member) {id | fileid | name | etc>>} 3d table =>(users) {id | name | pass } 4nd table =>(operationlog) {log_id | idno | fileid | basket_name | basket_price | user | } my code is : <form action="?p=addlog" method="post"> <div> <?php $q=mysql_query("SELECT * FROM `basket` where active = 1 and qu >=1 "); if(mysql_num_rows($q)){ while($m=mysql_fetch_assoc($q)) { ?> <td> <input type="checkbox" name="basket[]" value="<?echo $m["basket_name"] ;?>" /> <? echo "<span>". $m["basket_name"]."</span> "; } ?> <? } ?> </div></br> <input type="submit" value="SEND" /> </form> <? if($_GET[p]=="addlog"){ $reqtime=date("h:i:s"); foreach($_POST["basket"] as $basket1) { if(mysql_query("insert operationlog set idno='$_POST[curid]',fileid='$_POST[curfid]',basket_name='$basket1',basket_price='$basket1',username='{$_SESSION['loginname']}'")) ?> it works fine but basket_price (basket_price='$basket1') dosnt send value , it send value = 0 so i know "foreach($_POST["basket"] as $basket1)" is the problem > thanks Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted May 20, 2015 Share Posted May 20, 2015 Your form only submits the the basket name in the form of a checkbox value <td> <input type="checkbox" name="basket[]" value="<?echo $m["basket_name"] ;?>" /> The foreach loop will be looping through the values from the submitted checkboxes. The $basket1 variable will only contain the value from the checkbox (which is the basket_name). You are seeing 0 in the basket_price field because its data type is an integer and its is being truncated to 0 because you are trying insert a string value into it (the baskek name). You need another input field to submit the basket price and insert that value into the basket_price field in your operationlog table. But you should not be inserting the basket name/price into another table you should ideally be referencing those values using the primary key of the basket table as the foreign key in the operationlog table. Later on when you go to display the data from the operationlog table you would use a join to get the basket name/price values. Also you should not be using raw $_POST data in your queries. You should be validating and sanitizing the input before using it in your queries. And note the mysql_ functions are deprecated (no longer supported) you should update your code to use PDO or MySQLi database api's Quote Link to comment Share on other sites More sharing options...
abdu808 Posted May 20, 2015 Author Share Posted May 20, 2015 thanks for replay ch0cu3 basket its price is edited e.g: baske"a" its price in may = 50$ .... and in jun = 55$ cause this i would send price and basket name for every operation >. Quote Link to comment Share on other sites More sharing options...
abdu808 Posted May 21, 2015 Author Share Posted May 21, 2015 any idea to send basket_name and basket_price 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.