PrettyHotProgrammer Posted June 26, 2008 Share Posted June 26, 2008 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()); ?> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 The header() redirect should happen AFTER the PHP code to do the delete Quote Link to comment Share on other sites More sharing options...
PrettyHotProgrammer Posted June 26, 2008 Author Share Posted June 26, 2008 Ok I moved the Redirect to the end of the page and now it is not redirecting and it is just a plain white page. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 mysql_query($sql); or die(mysql_error()); should be mysql_query($sql) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
PrettyHotProgrammer Posted June 26, 2008 Author Share Posted June 26, 2008 Shoulda Seen that... now I am getting You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 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; ?> Quote Link to comment Share on other sites More sharing options...
PrettyHotProgrammer Posted June 26, 2008 Author Share Posted June 26, 2008 no redirect, no remove, no error :'( Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 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; ?> Quote Link to comment Share on other sites More sharing options...
PrettyHotProgrammer Posted June 26, 2008 Author Share Posted June 26, 2008 Same... no Errors, No Remove, Nothing... White page Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 26, 2008 Share Posted June 26, 2008 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. Quote Link to comment Share on other sites More sharing options...
PrettyHotProgrammer Posted June 26, 2008 Author Share Posted June 26, 2008 This page is being called up when i submit a form from another page... and aid is being sent from that form Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 26, 2008 Share Posted June 26, 2008 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted June 26, 2008 Share Posted June 26, 2008 Actually, the most crucial thing is determining if this is a mysql problem or not. Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 26, 2008 Share Posted June 26, 2008 but if data isnt even being posted correctly, mysql errors mean nothing Quote Link to comment Share on other sites More sharing options...
PrettyHotProgrammer Posted June 27, 2008 Author Share Posted June 27, 2008 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> Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 27, 2008 Share Posted June 27, 2008 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. Quote Link to comment Share on other sites More sharing options...
PrettyHotProgrammer Posted June 27, 2008 Author Share Posted June 27, 2008 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!! Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 27, 2008 Share Posted June 27, 2008 I found what may be the problem: $Remove = $_POST[removeAID]; needs to be $Remove = $_POST['removeAID']; I'm almost positive this will do the trick Quote Link to comment Share on other sites More sharing options...
PrettyHotProgrammer Posted June 27, 2008 Author Share Posted June 27, 2008 What do you think if we change header("Location: MyURL");"); that to this header("Location: MyURL"); haha the little things that we miss eh? Quote Link to comment Share on other sites More sharing options...
PrettyHotProgrammer Posted June 27, 2008 Author Share Posted June 27, 2008 THANKS VERY MUCH TO EVERYONE FOR HELPING OUT!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.