Jump to content


Photo

'DELETE' sql statement in PHP


  • Please log in to reply
3 replies to this topic

#1 Mirandur

Mirandur
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 14 March 2006 - 04:31 PM

I have the following script in one of my pages. It's in an include() file, and a part of my template managing system.

if (!empty($newtemplate)) // if a request about a template has been sent
 {
   $query = "SELECT * FROM templates";
   $test_template_data = mysql_query($query);
   if (!$test_template_data) die(sql_error());

  $test = 0;

   while($testdata = mysql_fetch_array($test_template_data))  // Testing to see if the requested template is registred
   {
     if ($testdata["templatename"] == $newtemplate)  // if template is found in sql database
     {
       switch ($action)
       {
        case 'change':   // change default template
         $query = "UPDATE admin SET template='" . $newtemplate ."' WHERE settingsid='1'";
         $test_update_default_template = mysql_query($query);
         if (!$test_update_default_template) die ('Cannot store settings');
         echo '<font class="message">Template has been changed!</font>';
         $test = 1;
        break;

        case 'del':   // delete template from sql table
         $delquery = "DELETE FROM templates WHERE templatename='" . $template_to_delete . "'";
         $del_template_test = mysql_query($delquery);
         if (!$del_template_test) die('Cannot delete template');
         echo '<font class="message">Template has been deleted!</font>';
         $test = 1;
        break;
        
        default:
        break;
       }
     }
   }
   if (!$test) echo '<font class="message">No such template!</font>';
 }

My problem is, I can't echo out anything in the 'del' case as long as the '$delquery' is not commented out...
The '$test' variable is not changed either.
The record in question is deleted in the sql table, though...

How can I make this work as intended?

Any help would be appreciated!

#2 php_b34st

php_b34st
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 14 March 2006 - 06:29 PM

I think you put to many quotation marks in try replacing:

$delquery = "DELETE FROM templates WHERE templatename='" . $template_to_delete . "'";

with this:

$delquery = "DELETE FROM templates WHERE templatename='$template_to_delete'";


#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 14 March 2006 - 07:57 PM

No both
<?php $delquery = "DELETE FROM templates WHERE templatename='" . $template_to_delete . "'"; ?>
and
<?php $delquery = "DELETE FROM templates WHERE templatename='$template_to_delete'"; ?>
are exactly the same.

Ken

#4 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 14 March 2006 - 08:02 PM

Yeah the double quote single quote period thing is silly. Don't use that shit.

Realize.. with strings, either of these work.

$x = "abc";

print $x;
print "$x";
print '$x';
print "grandma $x"
print 'RAWRRRRRRRR $x';

If you're going to have "" or '' in your text, just

$x = addslashes(' "You're a piece of shit," she said!');

Hope this helped.



Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users