SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems with my CMS.

    1st:
    PHP Code:
    if ($action=="new") {
                if (isset($insert_now)) {
                dbconnect("content");
                //insert the data
                safe_query("INSERT INTO news_stories (author_id, title, story) values ('".$author_id."', '".$story_title."', '".htmlspecialchars($story)."')");
            }
            dbconnect("content");
            $data=safe_query("SELECT author_id, name FROM news_authors WHERE username='".$uid."'");
    ?>
            <form action="<?=$PHP_SELF ?>?action=new" method="post">
            <input type="hidden" name="insert_now" value="1">
            <input type="hidden" name="author_id" value=""><?php echo $data["name"?>">
            <a href="/admin/news.php">News Administration Main</a><br>
            <font class="main_header">Create Story</font><br>
            <table border="0" bgcolor="#000000" cellpadding="4" cellspacing="1" align="left">
                <tr>
                    <td align="right" bgcolor="#ABABAB"><font class="standard">Author:</font></td><td align="left" bgcolor="#ABABAB"><font class="standard"><?php echo $data["name"?></font></td>
                </tr>
                <tr>
                    <td align="right" bgcolor="#BCBCBC"><font class="standard">Title:</font></td><td align="left" bgcolor="#BCBCBC"><input type="text" name="story_title"></font></td>
                </tr>
                <tr>
                    <td align="right" bgcolor="#ABABAB" valign="top"><font class="standard">Story:</font></td><td align="left" bgcolor="#ABABAB"><textarea name="story" cols="50" rows="15"></textarea></td>
                </tr>
                <tr>
                    <td align="right" bgcolor="#BCBCBC">&nbsp;</td><td align="left" bgcolor="#BCBCBC"><input type="submit" value="Submit"> <input type="reset" value="Reset"></td>
                </tr>
            </table>
    This is the little section of code that is giving me problems. It won't select the author's name or id, even though its right there in my query above it. I really don't get why it won't pick it up.

    2nd:
    PHP Code:
    elseif ($action=="delete") {
        dbconnect("content");
                if (isset($delete_now)) {
                    for ($i = 0; $i < count($id); $i++) {
                        // delete based on $id[$i]
                        safe_query("DELETE FROM news_stories WHERE id = '$id[$i]'");
                    }
                }
            $result=safe_query("SELECT id, title FROM news_stories ORDER BY id DESC");
    ?>
            <form action="<?=$PHP_SELF ?>?action=delete" method="post">
            <input type="hidden" name="delete_now" value="1">
            <a href="/admin/news.php">News Administration Main</a><br>    
            <font class="main_header">Delete Stories</font><br>
            <table border="0" bgcolor="#000000" cellpadding="4" cellspacing="1" align="left">
    <?
                
    while ($row mysql_fetch_array($result))
                                {
    ?>
                <tr>
                    <td align="left" bgcolor="#ABABAB"><font class="standard">Story # <?=$row["id"?><?=$row["title"?></font></td>
                </tr>
                <tr>
                    <td align="left" bgcolor="#BCBCBC"><input type="checkbox" name="id[<?=$row["id"?>]"> <input type="submit" value="Delete"></td>
                </tr>
    <?
                                
    }
    ?>
                </table>
            </form>
        <?
        
    }
    This is my delete stories section, lol, I don't know why it won't delete. I know it has something to do with the way I have the checkbox setup, but I really don't understand how to alter it. I am trying to be able to check off the boxes next to the stories I want to delete and then hit one of the submit buttons and have just the selected stories deleted.

  2. #2
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you reccommend I make each of these functions on a separate page? or is it fine like it is on one page?

  3. #3
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1) did you print the query to screen? and then copy on unix/command prompt in mysql and run there? what does it do?
    2) I implement my check boxes a little different;
    <input type="checkbox" name="id[]" value="1">
    <input type="checkbox" name="id[]" value="2">
    <input type="checkbox" name="id[]" value="3">
    then i traverse in array
    try to see what $id[$i] returns in your script? then you will solve problem
    good luck

  4. #4
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The query works, I tested it from telnet, also, I don't understand how you work your checkboxes, I want to delete based off the $id variable.

  5. #5
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Whew!

    Got it all figured out, thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •