Help I cannot understand why CommentDelete script not working

Well i have script CommentsShow(Show all comment what had users added) and inside that I have include Pre.Delete.php whose add two forms for buttons( one is for delete comment and other for edit comment) $ReportNum variables purpose is for specific Query.(In specific query delete comment for example better to understand in image 1) .
After pressing delete button it always show Report1 and no id of question(if you change values by hand it works)

ALL files are with php extension!

ReportsPage where ReporNum variable appier with image 1(Querys) and image 3(what happens when you press delete button)

Pre.delete.php

<?php
		print"
		    <!--Edit wizard-->
		    <form id='editText'>
		    </form >
		    <!--Delete wizard-->
		    <form method ='POST' action = 'CommentDelete($conn)'  id = 'deleteText'>
				<input type ='hidden' name ='id' value =$row["id"]>
				<input type ='hidden' name ='Report' value =$ReportNum>
				<p>$Answer_ID</p>
		    </form>
		    <!--buttons of action-->
			<button type ='submit' form ='editText' value ='editComment'>EDIT</button>
			<button type ='submit' form ='deleteText' name='deleteComment' >DELETE</button>	
		";
?>

CommentShow par where comments show

if ($result->num_rows > 0) {
          // output data of each row
          while($row = $result->fetch_assoc()) {
         //prints comments
		print"    
		    <b>client at</b> {$row["date"]} <b>from</b> {$row["client"]}<br>
		    <mark>{$row["text"]}</mark>
		 ";
        //delete and edit button forms appier
		include 'Pre.Delete.php';
		echo"<br>";
		echo"<p>".$ReportNum."</p>"; //here it shows correct ReportNum in web page
          }

CommentDelete

 if(isset($_POST['deleteComment'])){
		    //delete from that id
	    echo"IH!";
		$id = $_POST['id'];
		$ReportNum = $_POST['ReportNum'];
		echo"<p>".$ReportNum."</p>";
		echo"<p>".$id."</p>";
		$sqlD = "DELETE FROM $ReportNum WHERE id ='$id'";
		$resultD = $connD->query($sqlD);
	    if (mysqli_query($connD, $sqlD)) {
	    //      echo "Comment deleted";
	    } else {
	          echo "Error: " . $sqlD . "<br>" . mysqli_error($connD);
	    }
}

*Why using this ->’ not ->" because otherwise in Reports webpage javaScript dies.

and what error is shown?

Script is “working” but not get proper id of comment and proper report name(a.k.a query)
In image 3(appier text for testing "Ih Report1 " but must be also "IH " but diferent Report name and also must be shown id of comment)

Don’t you get a parse error because of the double-quotes around id in your pre.delete.php?

What does it show there when you display your page and view the source?

Well there was a mistake value =$row[“id”] to {$row[“id”]}

<?php
		print"
		    <!--Edit wizard-->
		    <form id='editText'>
		    </form >
		    <!--Delete wizard-->
		    <form method ='POST' action = 'CommentDelete($conn)'  id = 'deleteText'>
				<input type ='hidden' name ='id' value ={$row["id"]}>
				<input type ='hidden' name ='Report' value ='$ReportNum'>
				<p>$Answer_ID</p>
		    </form>
		    <!--buttons of action-->
			<button type ='submit' form ='editText' value ='editComment'>EDIT</button>
			<button type ='submit' form ='deleteText' name='deleteComment' >DELETE</button>	
		";
?>

End here is erro happens if you press delete

IH!
Error: DELETE FROM WHERE id =‘’
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE id =’‘’ at line 1

OK, so that shows that no value for $id is coming through.

I’ll ask this again.

I’d have thought that rather than enclosing the variable in curly-braces, you’d use single-quotes around id. Embedded quotes is a pain - I often break out of the main string assignment and concatenate to remove any confusion.

Well if i change value ={$row[“id”]} to value ='$row[‘id’] ’
java script dies
$row[“id”] i get id of comment from CommentShow script

Hard to comment as there’s no JavaScript anywhere in the code you showed.

To get around it, what about just adding

$rowid = $row["id"];

on a line before your print statement, and using that variable instead of the array?

If you have JavaScript involved in posting the form to commentdelete.php, can you show it please? That might have a bearing on why your form variables aren’t coming through.

Java script purpose is in Reports web page (JavaScript allows me to crate tabs in page)
How i understand what JS is “dead” i cannot open tabs

I added what you had wrote into the code
added part before print → $rowid = $row[“id”];
and in form value =’ $rowid ’

nothing changed

Error: DELETE FROM WHERE id =‘’
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE id =’‘’ at line 1

This line confuses me a little

<form method ='POST' action = 'CommentDelete($conn)'  id = 'deleteText'>

as the action seems to look as if it’s trying to call a function, but should have a URL in it. That’s why I wondered whether something else is trying to process the form submission.

Also, your buttons are outside of the <form> definition - you have a closing </form> tag on the line before. Might that be causing it?

what line I also change trying on my own now action is → value = ‘CommentDelete.php’

BTW maybe will be more sense if i send link to pastebin with full CommentDelete and Pre.Delete code?

this link is with full code of Pre.Delete.php → https://pastebin.com/6qhc0Cj8
this into CommentShow.php → https://pastebin.com/aVck8Agh

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.