Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/296405-send-tow-value-over-foreach/
Share on other sites

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.