Jump to content

[SOLVED] MySQL DELETE FROM Error


maxudaskin

Recommended Posts

I use

 

$sql2 = "DELETE FROM `applications` WHERE `id` = '{$id}' LIMIT 1;";

 

to delete a row from a database. It does not end up deleting it, but it does not produce an error.

 

<?php
$accept = $_REQUEST["accept"];
$deny = $_REQUEST["deny"];
if(isset($accept))
{
$id = $_REQUEST["appid"];
$hub = $_REQUEST["hub"];
$temppid = rand(1001,3999);
$fname = $_REQUEST["fname"];
$lname = $_REQUEST["lname"];
$email = $_REQUEST["email"];
$pass = $_REQUEST["pass"];
$position = $_REQUEST["position"];
$type = $_REQUEST["role"];
$appdate = $_REQUEST["appdate"];
$birthday = $_REQUEST["birthday"];
$country = $_REQUEST["country"];
$vatsim = $_REQUEST["vatsim"];
$ivao = $_REQUEST["ivao"];
$ip = $_REQUEST["ip"];
$result = mysql_query("SELECT * FROM `users` WHERE `pid`='{$temppid}'");
if (mysql_num_rows($result) == 1)
{
$pidcheck = 1;
}
else
{
$pidcheck = 0;
}
do
  {
  $$temppid++;
  }
while ($pidcheck==1);
if ($pidcheck==0);
{
$pid = $temppid;
$sql="INSERT INTO users (appid, fname, lname, email,  pass,  hub, birthday, country, vatsim, ivao, position, ip, acceptdate, appdate, type, pid)
VALUES
('$id','$fname','$lname','$email','$pass','$hub','$birthday','$country','$vatsim','$ivao','$position','$ip', NOW( ), '$appdate', '$type', $pid)";

if (!mysql_query($sql,$LeadHost))
  {
  die('Error: ' . mysql_error());
  }
echo "1 user added...";
echo "<br>";
echo "</br>";
echo "Thank you For Using Max Udaskin's Virtual Airline Administration Script.";
$subject = "Application Accepted" ;
$message = "Hello ".$fname." ".$lname.",

Your application to Virtual Zoom Airlines has been accepted.

You may now login to the website using the user name and password you registered with:

Pilot ID: ".$temppid."
Password: ".$password."

Be sure to register for the forums and check out the latest NOTAMS before your first flight.

Feel free to contact us for assistance, but please do not reply to this email.


Regards,
Virtual ZOOM Airlines Management";
mail($email, "Subject: $subject",
$message, "From: Virtual Zoom Airlines" );
}
}
elseif (isset($deny))
{
mysql_select_db($database_LeadHost, $LeadHost);
$id = $_GET['apps'];
$sql2 = "DELETE FROM `applications` WHERE `id` = '{$id}' LIMIT 1;";
if (!mysql_query($sql2,$LeadHost))
  {
  die('Error: ' . mysql_error());
  }
echo "Application Denied and Deleted.";
}

?>

Link to comment
Share on other sites

First off, you have an extra semi-colon in there, so first try this:

 

$sql2 = "DELETE FROM `applications` WHERE `id` = '$id' LIMIT 1";

 

If that doesn't work, try removing the limit 1:

$sql2 = "DELETE FROM `applications` WHERE `id` = '$id'";

 

 

Didn't work...

Link to comment
Share on other sites

Try replacing this code:

<?php

$sql2 = "DELETE FROM `applications` WHERE `id` = '{$id}' LIMIT 1;";
if (!mysql_query($sql2,$LeadHost))
  {
  die('Error: ' . mysql_error());
  }
echo "Application Denied and Deleted.";

?>

 

With:

<?php

$sql2 = "DELETE FROM `applications` WHERE `id` = '$id'";

if (mysql_query($sql2,$LeadHost)){
  echo "Application Denied and Deleted.";
} else {
    die('Error: ' . mysql_error());
}

?>

Link to comment
Share on other sites

Why do you have those bac-tic things in their? the tablename and column names should not be enclosed in quotes.

 

Also, you should always escape any variables going into a SQL command to help protect against SQL injection, even if that variable is coming from another query.

$sql1 = "DELETE FROM applications WHERE id = '".mysql_real_escape_string($id)."'

 

Let me know... :)

Link to comment
Share on other sites

In your code near this delete line, you have a mysql_select_db. Where is your connect string at?

 

Also, try just putting the string directly into the mysql_query function.

 

mysql_query("DELETE FROM applications WHERE id = '".mysql_real_escape_string($id)."'");

Link to comment
Share on other sites

The INSERT INTO works but the DELETE FROM doesn't.

 

<?php
$accept = $_REQUEST["accept"];
$deny = $_REQUEST["deny"];
if(isset($accept))
{
$id = $_REQUEST["appid"];
$hub = $_REQUEST["hub"];
$temppid = rand(1001,3999);
$fname = $_REQUEST["fname"];
$lname = $_REQUEST["lname"];
$email = $_REQUEST["email"];
$pass = $_REQUEST["pass"];
$position = $_REQUEST["position"];
$type = $_REQUEST["role"];
$appdate = $_REQUEST["appdate"];
$birthday = $_REQUEST["birthday"];
$country = $_REQUEST["country"];
$vatsim = $_REQUEST["vatsim"];
$ivao = $_REQUEST["ivao"];
$ip = $_REQUEST["ip"];
$result = mysql_query("SELECT * FROM `users` WHERE `pid`='{$temppid}'");
if (mysql_num_rows($result) == 1)
{
$pidcheck = 1;
}
else
{
$pidcheck = 0;
}
do
  {
  $$temppid++;
  }
while ($pidcheck==1);
if ($pidcheck==0);
{
$pid = $temppid;
$sql="INSERT INTO users (appid, fname, lname, email,  pass,  hub, birthday, country, vatsim, ivao, position, ip, acceptdate, appdate, type, pid)
VALUES
('$id','$fname','$lname','$email','$pass','$hub','$birthday','$country','$vatsim','$ivao','$position','$ip', NOW( ), '$appdate', '$type', $pid)";

if (!mysql_query($sql,$LeadHost))
  {
  die('Error: ' . mysql_error());
  }
echo "1 user added...";
echo "<br>";
echo "</br>";
echo "Thank you For Using Max Udaskin's Virtual Airline Administration Script.";
$subject = "Application Accepted" ;
$message = "Hello ".$fname." ".$lname.",

Your application to Virtual Zoom Airlines has been accepted.

You may now login to the website using the user name and password you registered with:

Pilot ID: ".$temppid."
Password: ".$password."

Be sure to register for the forums and check out the latest NOTAMS before your first flight.

Feel free to contact us for assistance, but please do not reply to this email.


Regards,
Virtual ZOOM Airlines Management";
mail($email, "Subject: $subject",
$message, "From: noreply@virtualzoom.net" );
}
}
elseif (isset($deny))
{
mysql_select_db($database_LeadHost, $LeadHost);
$id = $_GET['appid'];


if (mysql_query("DELETE FROM applications WHERE id = '".mysql_real_escape_string($id)."'")){
  echo "Application Denied and Deleted.";
} else {
    die('Error: ' . mysql_error());
}
  $subject = "Application Denied" ;
$message = "Hello ".$fname." ".$lname.",

Your application to Virtual Zoom Airlines has been accepted.

You may now login to the website using the user name and password you registered with:

Pilot ID: ".$temppid."
Password: ".$password."

Be sure to register for the forums and check out the latest NOTAMS before your first flight.

Feel free to contact us for assistance, but please do not reply to this email.


Regards,
Virtual ZOOM Airlines Management";
mail($email, "Subject: $subject",
$message, "From: noreply@virtualzoom.net" );
}

?>

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.