Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2004, 02:18 PM
Registered User
 
Join Date: Oct 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with a script from your forum

hi,

i found the below script in your forum and have trouble getting it to work. i keep getting the 'Error: the id is not an array!' message and also when i click on the 'Remove' link it will not work but if i put a tick in the remove box a click the delete button it works a treat but of course i still get the 'Error: the id is not an array!' message.

Also i have of course customised the script to fit my needs. Please help I very new to this. cheers

script:

<?php

include('db.php') ;

    if (isset($_POST['remove']) && isset($_POST['id']) && is_array($_POST['id']))
    {
        foreach ($_POST['id'] as $id)
        {
            if (!mysql_query("DELETE FROM courses WHERE id = '$id'"))
            {
                echo error_message(sql_error());
            }
        }
    }
    else
    {
        echo "Error: the id is not an array!<br />\n";
    }

    $result = mysql_query("SELECT id, coursename FROM courses GROUP BY (id) ASC");

    echo "<form action='{$_SERVER['PHP_SELF']}' method='POST'>\n".
         " <table width='500' border='0' cellspacing='0' cellpadding='0'>\n".
         " <tr valign='top'>\n".
         " <td bgcolor=f1f1f1>Course ID</td>\n".
         " <td bgcolor=f1f1f1>Course Name</td>\n".
         " <td bgcolor=f1f1f1>Remove</td>\n".
         " <td></td>\n".
         " </tr>\n";

    while ($row = mysql_fetch_array($result))
    {
        echo " <tr>\n".
             " <td bgcolor=f1f1f1>".$row['id']. "</td>\n".
             " <td bgcolor=f1f1f1>".$row['coursename']. "</td>\n".
             " <td><input type='checkbox' name='id[]' value='{$row['id']}'>{$row['id']}</input></td>\n".
             " <td><a href='{$_SERVER['PHP_SELF']}?action=delete_record&id={$row['id']}' onclick=\"return confirm('Are you sure you want to delete

record $id');\"> DELETE </a></td>\n".
             " </tr>\n";
    }

    echo " <tr>\n".
         " <td colspan='5' align='right'><input type='submit' name='remove' value='Delete' onclick=\"return confirm('Are you sure you want to delete

the selected records?');\" /></td>\n".
         " </tr>\n".
         " </table>\n".
         "</form>";
?>



tom

 
Old October 15th, 2004, 03:52 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Have you POSTed to the page?

-Snib <><
Try new FreshView 0.2!
There are only two stupid questions: the one you don't ask, and the one you ask more than once ;)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Welcome to our forum! WoodyWindy BOOK: Professional Microsoft Office SharePoint Designer 2007 ISBN: 978-0-470-28761-3 1 March 22nd, 2010 12:31 PM
Forum script tufatman Beginning PHP 2 July 9th, 2006 12:31 AM
How can I creat a forum like P2P Forum? pcassiano ASP.NET 1.0 and 1.1 Basics 1 October 31st, 2005 05:00 AM
converting Forum.aspx to Forum.ascx (help) drfunkie BOOK: ASP.NET Website Programming Problem-Design-Solution 1 July 11th, 2003 12:27 PM
Call and run CGI script from a PHP script ... how? dbruins BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 June 10th, 2003 03:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.