Jump to content

[SOLVED] Remove row


PrettyHotProgrammer

Recommended Posts

I am not getting the Rows deleted when i do this?

 

<?php

 

header("Location: URL where I want it redirected");

 

$aid=$_POST[aid];

$aName=$_POST[aName];

$sid=$_POST[sid];

$description=$_POST[description];

 

include("configuration.php");

if (!($db = mysql_pconnect($hostname, $username , $password))){

die("Can't connect to database server.");

}else{

// select a database

 

if (!(mysql_select_db("$database",$db))){

die("Can't connect to database.");

}

}

$sql = "DELETE FROM Assignment WHERE AssignmentID = $aid";

 

mysql_query($sql);

or die(mysql_error());

?>

Link to comment
Share on other sites

try:

 

<?php
   $aid=$_POST['aid'];
   $aName=$_POST['aName'];
   $sid=$_POST['sid'];
   $description=$_POST['description'];

   include("configuration.php");
   if (!($db = mysql_pconnect($hostname, $username , $password))){
         die("Can't connect to database server.");
      }else{
         // select a database
         
         if (!(mysql_select_db("$database",$db))){
            die("Can't connect to database.");
         }
      }
    $sql = "DELETE FROM `Assignment` WHERE `AssignmentID` = '$aid'";

   mysql_query($sql)
     or die(mysql_error().' - '.$sql);
   header("Location: URL where I want it redirected");
   exit;
?>

Link to comment
Share on other sites

try

 

<?php
  //Error Reporting On
  ini_set('display_errors','on');
  error_reporting(E_ALL ^ E_NOTICE);
  
  $aid=$_POST['aid'];
  $aName=$_POST['aName'];
  $sid=$_POST['sid'];
  $description=$_POST['description'];

  include("configuration.php");
  mysql_connect($hostname, $username , $password)
    or die("Can't connect to database server.");
  mysql_select_db($database)
    or die("Can't connect to database.");

  $sql = "DELETE FROM `Assignment` WHERE `AssignmentID` = '$aid'";

  mysql_query($sql)
    or die(mysql_error().' - '.$sql);
  header("Location: http://www.google.com");
  exit;
?>

Link to comment
Share on other sites

E_NOTICE should not be excluded from error_reporting in a learning/development/debugging situation. For example, the previous mysql syntax error is likely due to an empty $aid variable, either because it does not exist in the form or no form is submitting data to this code.

Link to comment
Share on other sites

This page is being called up when i submit a form from another page... and aid is being sent from that form

 

 

I have no idea what that meant but here is what your problems probably are:

 

1) not redirecting... it is likely that configuration.php outputs something onto the screen. When output is made, it wont redirect. end of story.

 

2) Where is your data coming from? Will you show us the form you're using to remove the data to begin with? If you dont have a form, then there's your problem right there. But if you do, show it to us.

 

3) thirdly... since this page is only meant to delete a row, why are you doing anything with $_POST['aName'],$_POST['sid'], and$_POST['description']? In fact, why do those variables even exist?

 

I think the most crucial thing right now is what does your form page look like.

 

EDIT: @PFMaBiSmAd -  I'm pretty sure that there shouldnt be an error if $aid is empty.. it just wont delete anything.

Link to comment
Share on other sites

I changed some stuff... it still isn't working... it must have been a PHP error because it was not even getting to the MySQL statements...

 

 

Here is the code now...

<?php

  //Error Reporting On

  ini_set('display_errors','on');

  error_reporting(E_ALL ^ E_NOTICE);

 

 

  $Remove = $_POST[removeAID];

 

  include("config.php");

  if (!($db = mysql_pconnect($hostname, $username , $password))){

        die("Can't connect to database server.");

      }else{

        // select a database

       

        if (!(mysql_select_db("$database",$db))){

            die("Can't connect to database.");

        }

      }

    $sql = "DELETE FROM `Assignment` WHERE `AssignmentID` = '$Remove'";

 

  mysql_query($sql)

    or die(mysql_error().' - '.$sql);

header("Location: MyURL");");

  exit;

?>

 

 

Here is the Form...

    <form action="NewAssignment3.php" method="post">

    <table width = "100%" border="5">

        <tr>

            <td width="33%" align="center"> Remove At Assignment ID</td>

                <td width="33%" align="center"><input type="text" size="10" name="removeAID"></td>

                <td width="33%" align="center"><input type="submit" />

            </tr>

        </table>

    </form>

Link to comment
Share on other sites

Is all of this in one file? If so, whats the file called? Your form's action goes to NewAssignment3.php so you need to put that php code into a file and name it NewAssignment3.php(if you havent already).

 

Otherwise, the code looks alright. MAKE SURE in the php file that the <?php is at the very top of the file with nothing in front of it(no new lines or anything) and also make sure config.php isn't outputting anything.

 

Also, I'd say make exit; into exit(); not sure if that matters, but just play it safe.. it's a function.

 

One last thing.. after your "header" statement, under it and above the exit(), put a little echo statement that says "did not redirect" that way if it prints that, you know that there was output before the header statement.

 

Link to comment
Share on other sites

They are in Different Files... the form is in a file called NewAssignment.php and it goes to NewAssignment3.php and the Config file is just Simply full of Variables that I am using... that is where I am storing everything I will try to do the echo statement that you suggested but Nothing is printing out and I think that that means there is an error somewhere that is crashing the entire thing... This is killing me...

 

Thanks for all of your help... i'm going to stay up all night tonight and stress over it so if anyone can help at all please let me know!!

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.