Jump to content

[SOLVED] Problem deleting record?


lokie538

Recommended Posts

Hi,

 

Ive never deleted a row out of a table before and it is not working for me hehe. Ive got too different codes with ive tried, the top one works in phpmyadmin but when inserted into the code it always dies. Does the 3rd query below need picid to be the index or primary key? If there a way too see what the actually error is?

 

<?php
include ("checkio.php"); 

$picid = "3";

/*$_GET['picid'];*/

$query = "SELECT * FROM images WHERE picid = '" . $picid . "'";
$result = mysqli_query($cxn,$query) or die ("Couldnt execute queryLOL1111132.");
$row = mysqli_fetch_assoc($result);


$query2 = "INSERT INTO `1300facepainting`.`deletedpic` (`picid`, `creatorid`, `title`, `sumo`, `sumiototal`, `type`) VALUES ('" . $row['picid'] . "', '" . $row['creatorid'] . "', '" . $row['title'] . "', '" . $row['sumo'] . "', '" . $row['sumiototal'] . "0', '" . $row['type'] . "')";
$result2 = mysqli_query($cxn,$query2) or die ("Couldnt execute queryLOL222.");

//This is the code that phpmyadmin made and works when entered into the sql section in phpmyadmin
$query4 = "DELETE FROM images WHERE picid = '" . $picid . "'";
$result4 = mysqli_query($cxn,$query4) or die ("Couldnt execute deleting fails .");

// Tried this aswell but no luck
$query3 = "DELETE FROM '1300facepainting'.'images' WHERE 'images'.'picid' = '" . $row['picid'] . "' AND 'images'.'creatorid' = '" . $row['creatorid'] . "' AND 'images'.'title' = '" . $row['title'] . "' AND 'images'.'sumo' = '" . $row['sumo'] . "' AND 'images'.'sumiototal' = '" . $row['sumiototal'] . "' AND 'images'.'type' = '" . $row['type'] . "' LIMIT 1";
$result3 = mysqli_query($cxn,$query3) or die ("Couldnt execute deleting fails .");




echo "good";
?>

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/139007-solved-problem-deleting-record/
Share on other sites

$query3 = "DELETE FROM `images` WHERE `picid` = '" . $row['picid'] . "' AND `creatorid` = '" . $row['creatorid'] . "' AND `title` = '" . $row['title'] . "' AND `sumo` = '" . $row['sumo'] . "' AND `sumiototal` = '" . $row['sumiototal'] . "' AND `type` = '" . $row['type'] . "' LIMIT 1";

 

That is alot of conditions for a delete, but to each there own.

 

Your main problem was using ' instead of ` around table/column names. The above should work with less confusion.

Nixed the old comment about OOP, you can use or die(mysqli_error($link));

 

Thanks,

 

im getting

 

"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 ''images' WHERE 'picid' = '3' AND 'creatorid' = 'JUDSPE' AND 'title' = 'MMosqito'' at line 1"

 

as an error?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.