PHP Help - Delete row  | |
August 7th, 2006, 10:24 PM
|
#1 (permalink)
| | Ultimate Member
Join Date: Jul 2003
Posts: 1,253
|
I have a script that checks a databases, saves the information as variables temporarily, deletes the old row, and then creates a new row in a different table. The problem is that I can't the old row to delete itself. I've tested it on two machines, I have no idea why I can't get delete stuff. My priveleges are fine. PHP Code: <?php
include "config.php";
$activation = $_GET['id'];
$query="SELECT * FROM unactivated WHERE activation='$activation'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if ($num > 0 ) {
$row = mysql_fetch_assoc ($result);
$user = $row['user'];
$password = $row['password'];
$realname = $row['realname'];
$email = $row['email'];
$joineddate = $row['joindeddate'];
mysql_close();
include "config.php";
mysql_query("DELETE FROM 'unactivated' WHERE activation='$activation'");
$query = "INSERT INTO user (user, password, realname, email, joineddate)
VALUES('".$user."','".$password."','".$realname."','".$email."','".$joineddate."')";
$result = mysql_query($query);
echo "Activation successful!";
echo "$activation";
} else {
echo "Activation unsuccessful. Your activation code wasn't found.";
}
?> |
| |
August 8th, 2006, 10:18 AM
|
#2 (permalink)
| | Member
Join Date: Oct 2001 Location: Louisiana, USA
Posts: 256
|
Any reason why you're including config.php twice - the second time after closing the database connection? If this is within the same database it isn't needed twice. Try this code below and see what happens. It should give you an error why the query is failing. PHP Code: <?php
include "config.php";
$activation = $_GET['id'];
$query="SELECT * FROM unactivated WHERE activation='$activation'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if ($num > 0 ) {
$row = mysql_fetch_assoc ($result);
$user = $row['user'];
$password = $row['password'];
$realname = $row['realname'];
$email = $row['email'];
$joineddate = $row['joindeddate'];
//mysql_close();
//include "config.php";
//
// Modified this line here...
$query = mysql_query("DELETE FROM unactivated WHERE activation='$activation'") or die('Query failed: ' . mysql_error());
$query = "INSERT INTO user (user, password, realname, email, joineddate)
VALUES('".$user."','".$password."','".$realname."','".$email."','".$joineddate."')";
$result = mysql_query($query);
echo "Activation successful!";
echo "$activation";
} else {
echo "Activation unsuccessful. Your activation code wasn't found.";
}
?> |
| |
August 8th, 2006, 01:56 PM
|
#3 (permalink)
| | Ultimate Member
Join Date: Jul 2003
Posts: 1,253
|
I orignally had it without the mysql_close(); and include "config.php", I put them in to try to find the problem. I put the Query failed and mysql_error(); and now it magically works.
Thanks, PHP/MySQL has been acting strange for me lately. |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |