Author Topic: HELP-DELETE SOMETHING  (Read 169 times)

jman9944

  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
HELP-DELETE SOMETHING
« on: February 02, 2012, 12:22:10 PM »
Hi,
I am editing a webtester page, and there's a reports page, on which I display reports using:

PHP Code: [Select]

$resultsSQL
='SELECT * FROM Results LEFT JOIN Tests ON Results.TestID=Tests.ID WHERE Tests.Creator =\'' $_SESSION['loggedInName'] . '\'';


To delete a report, I tried a few different ways, none of which work:

When I used:

PHP Code: [Select]

$resultsSQL 
"DELETE FROM Results WHERE ID=" $_POST['delete'][$i];


the webpage said:

Invalid Query: DELETE FROM Results 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 '' at line 1

When I used:

PHP Code: [Select]

$resultsSQL 
'DELETE FROM Results LEFT JOIN Tests ON Results.TestID=Tests.ID WHERE Tests.Creator =\'' $_SESSION['loggedInName'] . '\'';


the webpage said:

Invalid Query: DELETE FROM Results LEFT JOIN Tests ON Results.TestID=Tests.ID WHERE Tests.Creator ='jsherman' - 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 'LEFT JOIN Tests ON Results.TestID=Tests.ID WHERE Tests.Creator ='jsherman'' at line 1

And I tried:

PHP Code: [Select]

$resultsSQL 
'DELETE FROM Results LEFT JOIN Tests ON Results.TestID=Tests.ID WHERE ID=' $_POST['delete'][$i];


and again the webpage said:

Invalid Query: DELETE FROM Results LEFT JOIN Tests ON Results.TestID=Tests.ID 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 'LEFT JOIN Tests ON Results.TestID=Tests.ID WHERE ID=' at line 1


Any idea what I can do?
Do you need to see more code to help?

Thank you

Smokey PHP

  • Web Developer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 529
  • Karma: +5/-0
    • View Profile
Re: HELP-DELETE SOMETHING
« Reply #1 on: February 02, 2012, 04:16:49 PM »
I would personally change the first example to this:

PHP Code: [Select]
var_dump($_POST['delete'][$i]); //this will output the value - make sure it's what you're expecting!
//$resultsSQL = "DELETE FROM Results WHERE ID='" . $_POST['delete'][$i] . "'";