By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,200 Members | 1,584 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,200 IT Pros & Developers. It's quick & easy.

deleting distinct from database

P: 7
Hi all,
New to this forum, so to start 'A big hello to you all'.

My question:
I have a drop down menu that is created from the username in my database but is distinct:

<td><class="tdText"><strong><?php echo $lang['admin']['adminusers']['show_emptysessions'];?></strong></td>
<td align="right">
<?
$query= mysql_query("SELECT DISTINCT username FROM CubeCart_admin_sessions");
echo "<form action=removebyname.php method=POST><select name=users>";
while ($r = mysql_fetch_array($query))
{
$user = $r["username"];
echo "<option value=$user>$user</option>";
}
echo "</select>";
?>
<INPUT TYPE=submit NAME=users VALUE="Go!">
</form>



Then my removebyname.php file:

mysql_connect($glob['dbhost'],$glob['dbusername'],$glob['dbpassword']);
@mysql_select_db($glob['dbdatabase']) or die( "Unable to select database");

// DETERMINE WHICH RECORDS TO DELETE
$query="SELECT loginid FROM CubeCart_admin_sessions WHERE username='$user'";
mysql_query($query);

//SHOW WHICH RECORDS TO DELETE
$query="SELECT * FROM CubeCart_admin_sessions WHERE loginid='$user'";
mysql_query($query);

//DELETE CHOSEN USER RECORD
$query="DELETE FROM CubeCart_admin_sessions WHERE loginid='$user'";
mysql_query($query);

//DELETE THE ID COLUMN
$query="ALTER TABLE CubeCart_admin_sessions DROP COLUMN loginId";
mysql_query($query);

//RECREATE THE ID COLUMN STARTING FROM ONE
$query="ALTER TABLE CubeCart_admin_sessions ADD COLUMN loginId INT NOT NULL AUTO_INCREMENT PRIMARY KEY";
mysql_query($query);

//PRINT SUCCESS STATEMENT TO SCREEN
echo "All records relating to $user have been purged successfully";

mysql_close();
?>

<META HTTP-EQUIV="refresh" content="0;URL=sessions.php">


The distinct drop down works fine in my session.php file and locates the removebyname.php file but just prints the success message (minus the varaible i set) returns to the session.php but nothing is deleted.

Any ideas my friends ??????
And thanks for reading.

Jon
Sep 14 '06 #1
Share this Question
Share on Google+
4 Replies


ronverdonk
Expert 2.5K+
P: 4,258
How do you know if a mysql statement is executed successfully? You just assume that it is! Set your errors on and investigate the result of each MySql statement. Then you can pinpoint where it went wrong.

Ronald :cool:
Sep 15 '06 #2

P: 7
To be honest, I dont even think the $user isn't being passed to the removebyname.php file?????

I tried echoing $user at the very top of the removebyname.php and...Nothing!!!!!

It gives me the distinct usernames from my login database okay in dropdown ???

Jon
Sep 16 '06 #3

P: 1
To be honest, I dont even think the $user isn't being passed to the removebyname.php file?????

I tried echoing $user at the very top of the removebyname.php and...Nothing!!!!!

It gives me the distinct usernames from my login database okay in dropdown ???

Jon
think your better off with: $_POST['user'] , try googleing for $_GET, $_POST, $_COOKIE, $_SESSION, you will learn alot from it...
Sep 21 '06 #4

P: 7
Thanks for the help.
It was the Get method I needed.
Thaks again
Sep 22 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.