Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 08-07-2008, 07:55 PM delete an MySQL row
Super Talker

Posts: 102
Trades: 0
Here is the error
Code:
Warning:  Invalid argument supplied for foreach() in /home/zybersca/public_html/news/deletebeta.php on line 17
Here is the php
Code:
<?php
include("include/config.php");
include("include/opendb.php");

if( isset($_POST['submit']) )
{
    $error['2'] = true;

    if( count($_POST['box']) < 1)
    {
        $error['0'] = ture;
        $error['1'][] = "Please choose something to delete";
    }

    if( $error['0'] == false )
    {
        foreach( $_POST['box'] as $delete )
        {
            mysql_query("DELETE FROM `test` WHERE `news` = '$delete'") or die(mysql_error());
            mysql_query("DELETE FROM `test` WHERE `shout` = '$delete'") or die(mysql_error());
        }
        
        $error['1'][] = "Successfully deleted news";
    }
}

if( $error['2'] == true )
{
    foreach( $error['1'] as $message )
    {
        echo "$message<br />\n";
    }
}

$content = array();

$query = mysql_query("SELECT * FROM `test`");
while( $array = mysql_fetch_assoc($query) )
{
    $content[] = "    <td> <input type=\"checkbox\" name=\"box\" value=\"{$array['news']}\" /> </td>
                <td> {$array['news']} </td>
                <td><input type=\"checkbox\" name=\"box\" value=\"{$array['shout']}\" /></td>
                <td> {$array['shout']} </td>\n";
}
echo "    <form action=\"deletebeta.php\" method=\"post\">";
echo "        <table>\n";

foreach( $content as $tds )
{
    echo "        \t<tr>
                \t$tds
        \t</tr>\n";
}
echo "        </table>
        <input type=\"submit\" name=\"submit\" value=\"delete\" />
    </form>";
?>
Aaron™ is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-07-2008, 08:47 PM Re: delete an MySQL row
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
foreach is for looping through an array. $_POST['box'] isn't an array, it is an item in an array.

Just forget the loop and append the $_POST['box'] where you currently have $delete.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is online now
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 08-07-2008, 08:51 PM Re: delete an MySQL row
Super Talker

Posts: 102
Trades: 0
So how would that part of the code look? im really new with PHP
Aaron™ is offline
Reply With Quote
View Public Profile
 
Old 08-08-2008, 12:44 AM Re: delete an MySQL row
Super Talker

Posts: 102
Trades: 0
I got it to not show an error but it doesn't delete when a check box is selected, and then when you just click delete it still echo's Success.

Code:
<?php
include("include/config.php");
include("include/opendb.php");

if( isset($_POST['submit']) )
{
    $error['2'] = true;

    if( count($_POST['box']) < 1)
    {
        $error['0'] = ture;
        $error['1'][] = "Please choose something to delete";
    }

    if( $error['0'] == false )
    {
            mysql_query("DELETE FROM `test` WHERE `news` = '$delete'") or die(mysql_error());
            mysql_query("DELETE FROM `test` WHERE `shout` = '$delete'") or die(mysql_error());
        }
        
        $error['1'][] = "Successfully deleted news";
    }

if( $error['2'] == true )
{
    foreach( $error['1'] as $message )
    {
        echo "$message<br />\n";
    }
}

$content = array();

$query = mysql_query("SELECT * FROM `test`");
while( $array = mysql_fetch_assoc($query) )
{
    $content[] = "    <td> <input type=\"checkbox\" name=\"box\" value=\"{$array['news']}\" /> </td>
                <td> {$array['news']} </td>
                <td><input type=\"checkbox\" name=\"box\" value=\"{$array['shout']}\" /></td>
                <td> {$array['shout']} </td>\n";
}
echo "    <form action=\"deletebeta.php\" method=\"post\">";
echo "        <table>\n";

foreach( $content as $tds )
{
    echo "        \t<tr>
                \t$tds
        \t</tr>\n";
}
echo "        </table>
        <input type=\"submit\" name=\"submit\" value=\"delete\" />
    </form>";
?>

Last edited by Aaron™; 08-08-2008 at 12:45 AM..
Aaron™ is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to delete an MySQL row
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14735 seconds with 12 queries