Jump to content

Recommended Posts

I have check boxes next to each item when I call up the items from mySQL . How do i make the item disappear in the mySQL database when i user ticks the box and clicks "sell item"? I've been having trouble on that ..

<html>
<body>
<p><a href="index2.php">Index</a> | <a href="shop.php">Shop</a> | <a href="sell.php">Sell</a> | <a href="logout.php">Logout</a>
</p>
</p> 

<?php 

session_start();
$checked = $_POST['checked'];

if(isset($_SESSION['otherusername'])){

$db=mysql_connect('localhost', 'root', '');

$res=mysql_select_db('txtgame',$db) or die(mysql_error());

    
$otherusername = $_SESSION['otherusername']; //"SELECT item FROM users_items WHERE username='".$Username."'";
    
    $res=mysql_query($otherusername)or die(mysql_error());
    
  
    while($row = mysql_fetch_assoc($res)){


echo ' <input type="checkbox" name="item[]" value="items" />'. ' '.$row['item']."<BR />";

  }
  

  
}else{
   
   echo "Sorry your not a member please join us!";
}
?>

<br><input type="submit" value="sellitem">
</form>
</body>
</html>

 

 

Thanks !

Link to comment
https://forums.phpfreaks.com/topic/170576-how-to-make-a-checkbox-do-something/
Share on other sites

Pretty easy with AJAX - if you want it live (i.e. Click the checkbox and it instantly disappears)

 

But... I think I might have misread your post when I moved it.

 

If you want it when they click the submit button, you need to use a foreach loop to get each checkbox value....

if(isset($_POST['item']) && is_array($_POST['item'])) {
    // there were some items selected:
    foreach($_POST['item'] as $item) {
        // your query string here...
    }
}

 

And the syntax past that is based on how you have your DB setup.

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.