Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


Anibor

25 posts

Geek


#68690 26-Sep-2010 14:47
Send private message

I want to print a message via php only if my mysql statement performs

if ( $_POST['Delete'])
{
    $Customer_Code_form = $_POST['Customer_Code'];
    mysql_query("DELETE FROM customer WHERE Customer_Code = '$Customer_Code_form'") or die(mysql_error());
   
    Echo ">>>$Customer_Code_form has been deleted<<<";
   
}

right now this code will output whatever number was sent to it where or not something was deleted... and im too hung over atm to figure out how to solve this myself

Create new topic
LennonNZ
2459 posts

Uber Geek

ID Verified
Trusted

  #384549 26-Sep-2010 15:18
Send private message

Do you really trust $_POST putting it into a mysql query without quoting it?

try a little $Customer_Code_form = mysql_quote($_POST['Customer_Code']);

If you are echoing html then...

echo "<center>&gt;&gt;&gt; $Customer_Code_form has been deleted &lt;&lt;&lt;</center>"; is what you need to do.

With the result thingy..

what you need to look at is:

http://php.net/manual/en/function.mysql-query.php

so something like

if ($mysql_query (......)) {
       echo "......"; # OK Result
       } else {
      echo "......."; # ERROR Result
}

     




freitasm
BDFL - Memuneh
79295 posts

Uber Geek

Administrator
ID Verified
Trusted
Geekzone
Lifetime subscriber

  #384556 26-Sep-2010 15:29
Send private message

As said.... Don't trust ANY input. Ever. By using the input directly in your code you are opening it up for SQL Injections.






Please support Geekzone by subscribing, or using one of our referral links: Quic Broadband (free setup code: R587125ERQ6VE) | Samsung | AliExpress | Wise | Sharesies | Hatch | GoodSync 


Anibor

25 posts

Geek


  #384566 26-Sep-2010 15:56
Send private message

Cheers guys and dont worry this isnt going to be the final code, im passing it over to another coder to put in the catches and testing so its not unsafe :D



k1wi
484 posts

Ultimate Geek


  #384567 26-Sep-2010 16:06
Send private message

just so long as they atleast put in a few mysql_real_escape_string()'s.

It's a really good habit to put make your code as safe as possible as early as possible. Relying on someone else to run through your code and do all the securing is running a real risk that they'll miss something, the risk increases exponentially as your code grows too.

Anibor

25 posts

Geek


  #384570 26-Sep-2010 16:17
Send private message

Yeah this still aint working

    $delete = ("DELETE FROM customer WHERE Customer_Code = '$Customer_Code_form'");
    if ( mysql_query($delete))
    {
        Echo "<center>>>>$Customer_Code_form has been deleted<<<</center>";
    }
    else { echo "fail";}

k1wi
484 posts

Ultimate Geek


  #384579 26-Sep-2010 16:59
Send private message

You could add some conditioning/checking by creating a couple of Mysql queries for the customer ID before and after deleting....

I.E. check to see whether the customer ID exists, if it exists, delete the variable, then check again after the delete whether the variable exists or not, and build the logic around that.

Or you could probably use mysql result...

LennonNZ
2459 posts

Uber Geek

ID Verified
Trusted

  #384612 26-Sep-2010 18:41
Send private message

ah..

http://php.net/manual/en/function.mysql-affected-rows.php


if (mysql_affected_rows() > 0) {
 echo "something got deleted";
  } else {
 echo "nothing got deleted";
}



Create new topic





News and reviews »

Air New Zealand Starts AI adoption with OpenAI
Posted 24-Jul-2025 16:00


eero Pro 7 Review
Posted 23-Jul-2025 12:07


BeeStation Plus Review
Posted 21-Jul-2025 14:21


eero Unveils New Wi-Fi 7 Products in New Zealand
Posted 21-Jul-2025 00:01


WiZ Introduces HDMI Sync Box and other Light Devices
Posted 20-Jul-2025 17:32


RedShield Enhances DDoS and Bot Attack Protection
Posted 20-Jul-2025 17:26


Seagate Ships 30TB Drives
Posted 17-Jul-2025 11:24


Oclean AirPump A10 Water Flosser Review
Posted 13-Jul-2025 11:05


Samsung Galaxy Z Fold7: Raising the Bar for Smartphones
Posted 10-Jul-2025 02:01


Samsung Galaxy Z Flip7 Brings New Edge-To-Edge FlexWindow
Posted 10-Jul-2025 02:01


Epson Launches New AM-C550Z WorkForce Enterprise printer
Posted 9-Jul-2025 18:22


Samsung Releases Smart Monitor M9
Posted 9-Jul-2025 17:46


Nearly Half of Older Kiwis Still Write their Passwords on Paper
Posted 9-Jul-2025 08:42


D-Link 4G+ Cat6 Wi-Fi 6 DWR-933M Mobile Hotspot Review
Posted 1-Jul-2025 11:34


Oppo A5 Series Launches With New Levels of Durability
Posted 30-Jun-2025 10:15









Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.