justin2021 Posted December 27, 2011 Share Posted December 27, 2011 I'm trying to write a PHP program that a user will use to register to my site. I have a temporary table temp for which the user's information will be stored until they verify their account using an email that is sent to them. Once they verify their account through email, the information stored in the temporary table will be moved to a table called 'users'. I then want to delete the temporary data that they had stored. Unfortunately I'm having trouble doing this. This snippet of code isn't exactly the entire code, but just a test I've been using since I realized that my real code wasn't working as far as deletion goes. Here is my test code. <?php include('connect.php'); $sql2="SELECT username FROM temp WHERE username = 'justin'"; $result2=mysql_query($sql2); if($result2) echo ("Record found"."<BR>"); else echo ("Record not found"); $sql3="DELETE FROM temp WHERE username='justin'"; $result3=mysql_query($sql3); if($result3) echo ("SUCESSFUL DELETION"); else echo ("failed"); ?> In this code, I check the temp table to see if 'justin' can be found. This has consistently returned "Record found". On the other hand, my deletion command has not worked yet and will constantly fail. connect.php is correct as far as I know and has worked flawlessly for the other parts of this small project. Is something wrong here? What could be the problem? Quote Link to comment https://forums.phpfreaks.com/topic/253914-trouble-deleting-a-row-from-a-sql-table/ Share on other sites More sharing options...
Pikachu2000 Posted December 27, 2011 Share Posted December 27, 2011 So tell us what does happen, if the record isn't being deleted. Quote Link to comment https://forums.phpfreaks.com/topic/253914-trouble-deleting-a-row-from-a-sql-table/#findComment-1301697 Share on other sites More sharing options...
justin2021 Posted December 27, 2011 Author Share Posted December 27, 2011 So tell us what does happen, if the record isn't being deleted. When I run this code, I get a message saying "Record found, failed". I check the database using PHPmyAdmin and the record remains in the temp table. Here is the actual program that I am wanting to run. It stores the data perfectly fine into the users table, but as I stated, the temp data remains. <?php include("connect.php"); //set variable to get passkey from URL $passkey=$_GET['passkey']; $sql1="SELECT * FROM temp WHERE code='$passkey'"; $result1=mysql_query($sql1); //if sucessfully queried if($result1) { echo ("sucessfully queried"); //how many have passkey $count=mysql_num_rows($result1); //if passkey is in database, retrieve data if($count == 1) { $rows = mysql_fetch_array($result1); $namex=$rows['username']; $emailx=$rows['email']; $passwordx=$rows['password']; echo ("<BR>"."sucessfully counted"); //takeout spaces $name=str_replace(' ','',$namex); $email=str_replace(' ','',$emailx); $password=str_replace(' ','',$passwordx); //insert into users table from tmp $sql2="INSERT INTO users (username,email,password) VALUES ('$name','$email','$password')"; $result2=mysql_query($sql2); if($result2) { echo ("<BR>"."SUCESSFUL INSERTION"); //header("Location:sucessful_registration.html"); $sql3="DELETE FROM temp WHERE code='$passkey'"; $result3=mysql_query($sql3); } } } else { echo ("ERROR: Incorrect confirmation code"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/253914-trouble-deleting-a-row-from-a-sql-table/#findComment-1301699 Share on other sites More sharing options...
Pikachu2000 Posted December 27, 2011 Share Posted December 27, 2011 Instead of just "failed", echo the query string and error message while developing. Also, there's no reason to use parentheses with echo . . . else echo "<br>Query $sql3 failed<br>With error: " . mysql_error() . '<br>'; Quote Link to comment https://forums.phpfreaks.com/topic/253914-trouble-deleting-a-row-from-a-sql-table/#findComment-1301704 Share on other sites More sharing options...
justin2021 Posted December 28, 2011 Author Share Posted December 28, 2011 Instead of just "failed", echo the query string and error message while developing. Also, there's no reason to use parentheses with echo . . . else echo "<br>Query $sql3 failed<br>With error: " . mysql_error() . '<br>'; Great. That helped out a lot. Turns out that the user with access to the database didn't have DELETE enabled in its privileges. Quote Link to comment https://forums.phpfreaks.com/topic/253914-trouble-deleting-a-row-from-a-sql-table/#findComment-1301743 Share on other sites More sharing options...
Pikachu2000 Posted December 28, 2011 Share Posted December 28, 2011 Yeah, that'll do it every time. Quote Link to comment https://forums.phpfreaks.com/topic/253914-trouble-deleting-a-row-from-a-sql-table/#findComment-1301744 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.