0
<?php  
include_once('dbconnect.php');

$sqlPAQuery = "SELECT pages.pageId, pages.pageTitle FROM pages order by 
pages.pageId";
$paqueryResult = mysqli_query($conn,$sqlPAQuery);
echo "<form action = 'delete.php' method = 'post'>";
while ($paqueryRow = mysqli_fetch_assoc($paqueryResult))
    {


    echo "<input type = 'radio' name = '$paqueryRow[pageId]'>".$paqueryRow['pageTitle']."&nbsp"; 
    echo "<input name='Submit' type='submit' value='delete record' /><br/>";




    // FIND ALL ARTICLES FOR THIS PAGE
    $sqlARTICLEQuery = "SELECT * FROM articles where pageId=$paqueryRow[pageId] order by articleId";
    $articlequeryResult = mysqli_query($conn,$sqlARTICLEQuery);
    while ($articlequeryRow = mysqli_fetch_assoc($articlequeryResult))
    {
        echo "<input type = 'radio' name = '$articlequeryRow[articleId]' method = 'post'>".$articlequeryRow['articleTitle']."&nbsp";
        echo "<input name='Submit' type='submit' value='delete record' /><br/>";
        // VIDEOS FOR EACH ARTICLE
        $sqlVIDEOQuery = "SELECT * FROM videos where articleId=$articlequeryRow[articleId] order by videoId";
        $videoqueryResult = mysqli_query($conn,$sqlVIDEOQuery);
        while ($videoqueryRow = mysqli_fetch_assoc($videoqueryResult))
        {
            echo "<input type = 'radio' name = '$videoqueryRow[videoId]' method = 'post'>" . $videoqueryRow['videoTitle'] . "&nbsp";// . $videoqueryRow['videoLoc']."&nbsp"; 
            echo "<input name='Submit' type='submit' value='delete record' /><br/>";
            //echo"</br>";
        }

        // IMAGE FOR EACH ARTICLE
        $sqlIMAGEQuery = "SELECT * FROM images where articleId=$articlequeryRow[articleId] order by imageId";
        $imagequeryResult = mysqli_query($conn,$sqlIMAGEQuery);
        while ($imagequeryRow = mysqli_fetch_assoc($imagequeryResult))
        {
            echo "<input type = 'radio' name = '$imagequeryRow[imageId]' method = 'post'>".$imagequeryRow['imageTitle'] . "&nbsp"; //" . $imagequeryRow['imageLoc']."&nbsp"; 
            echo "<input name='Submit' type='submit' value='delete record' /><br/>";
            //echo"</br>";
        }


        *// TEXT FOR EACH ARTICLE   
        $sqlTEXTQuery = "SELECT * FROM text where articleId=$articlequeryRow[articleId] order by textId";
        $textqueryResult = mysqli_query($conn,$sqlTEXTQuery);
        while ($textqueryRow = mysqli_fetch_assoc($textqueryResult))
        {
            echo "<input type = 'radio' name = '$textqueryRow[textId]' method = 'post'>".$textqueryRow['textTitle']."&nbsp"; 
            echo "<input name='Submit' type='submit' value='delete record' /><br/>";
            if (isset($_POST['textDeleteQuery'])){
                $name = $_POST[$textqueryRow['textId']];
                $textDeleteQuery = "DELETE FROM text where articleId=$articlequeryRow[articleId] AND textId = ".$_POST[textDeleteQuery['textId']]."";

                if(mysqli_query($conn, $textDeleteQuery)){
                    echo "Record deleted successfully";
                } else {
                    echo "Error deleting record: " . $conn->error;
                }
            }
        }*

            echo "<br/>";

    }
    echo "<br/>";
}
echo "</form>";


$conn->close();

?>

cant get text to delete when I press the button nothing happens not sure what im doing wrong db is set up with pages, articles, images, video and text. columns for pages: pages.pageId, pages.pageTitle; columns for article: article.articleId, article.articleTitle, pages.pageId, image columns for videos: videos.videoId, videos.videoTitle, videos.videoLoc, article.articleId columns for images: images.imageId, images.imageTitle, images.imageLoc, article.articleId columns for text: text.textId, text.textTitle, text.textLoc, article.articleId

  • Since you're using procedural MySQLi, you should probably stick to the procedural error logging. `mysqli_error ($conn)` rather than `$conn->error` also, your query is vulnerable to MySQL injection attacks, please opt for using [prepared statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – IsThisJavascript Oct 19 '17 at 08:34
  • There's not enough information here to give a proper diagnostics. Try debugging your queries to see if each of your returns are giving you expected results (use `var_dump()`) – IsThisJavascript Oct 19 '17 at 08:37
  • changed the $conn->error and i will change to prepared statements but still having trouble with form and deleting from db – Adam Zeigler Oct 19 '17 at 08:41
  • Please try and debug your queries, run var_dumps on the returns until you find the query that is breaking (or returning nothing when it should return *something* ) As I can't see anything wrong with this at the moment. – IsThisJavascript Oct 19 '17 at 08:43
  • the query works when i manually add the id's from //TEXT FOR EACH ARTICLE. Article and text (post) not sure about or my isset – Adam Zeigler Oct 19 '17 at 08:44
  • May you post your HTML form code please – IsThisJavascript Oct 19 '17 at 08:47
  • its all included – Adam Zeigler Oct 19 '17 at 08:52
  • Ok I see your issue now. Your logic doesn't work. You are thinking that PHP runs constantly and that any changes to the HTML will reflect the PHP. However, this is not the case. PHP compiles on execute and displays HTML. After PHP has executed, you cannot modify it. For your current situation to work you must use ajax/javascript or split your form up with your SQL queries so they do not depend on each other. – IsThisJavascript Oct 19 '17 at 09:02
  • makes sense so would it be easier to add an html form and php to the background or should i try the ajax/javascript (which im not sure how to do ) – Adam Zeigler Oct 19 '17 at 09:15
  • It would be much easier to add a HTML form and then PHP. Any changes you need to make to forms would require a page refresh (think using `header()` to change the page and force a refresh with `$_GET`, don't forget to `exit()` after a `header()`). However, it'll be more practical and smoother if you use Ajax/Javascript to update the form. Either way, it looks like you need a rewrite. – IsThisJavascript Oct 19 '17 at 09:22
  • So if it will be smoother how and where would i start with ajax/javascript i have know idea – Adam Zeigler Oct 19 '17 at 09:45
  • This is something you will need to research as you go along; try starting here https://stackoverflow.com/questions/29204934/how-to-populate-dependable-drop-down-using-ajax-and-php – IsThisJavascript Oct 19 '17 at 09:47
  • is there anyway that you could guide me im having trouble just understanding what all is going on – Adam Zeigler Oct 19 '17 at 10:04
  • I'm pretty busy for a few hours and don't have the time to dedicate to this. Maybe if I get chance later on. My only recommendation right now is to rewrite the whole thing. Keep your form and php separate and get your php to trigger after you press submit. Try playing around with different parameters to get the displays you want. – IsThisJavascript Oct 19 '17 at 10:07
  • Thanks I will try sweating the form from the php cheers – Adam Zeigler Oct 19 '17 at 17:25

0 Answers0