Jump to content

'DELETE' sql statement in PHP


Mirandur

Recommended Posts

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

[code]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>';
}
[/code]

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!
Link to comment
Share on other sites

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

Ken
Link to comment
Share on other sites

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

Realize.. with strings, either of these work.

[code]$x = "abc";

print $x;
print "$x";
print '$x';
print "grandma $x"
print 'RAWRRRRRRRR $x';[/code]

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

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

Hope this helped.


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.