headmine Posted January 11, 2007 Share Posted January 11, 2007 What I am trying to do is delete multiple rows without using check boxes... here is the code as how i figured it would work... but im so stuck any one have any ideas?[code]<?phprequire_once("../Connections/con_php.php");?><?php$con1 = $_GET['usr'];$con2 = $_GET['login'];mysql_select_db($database_con_php, $con_php);$sql="DELETE FROM `table` WHERE `username` = '". $con1 . "' AND `login` = '". $con2 ."'";mysql_query($sql);mysql_close($con_php);?>[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 What is the problem? Check boxes are html and don't delete anything.You need to be allot clearer in your explination. Quote Link to comment Share on other sites More sharing options...
Draicone Posted January 11, 2007 Share Posted January 11, 2007 I'll assume the problem is that your SQL query does not match more than one row. You need to use an OR statement. For example:DELETE FROM `table` WHERE `username` = 'A' OR `username` = 'B' OR `username` = 'C';And so on. Quote Link to comment Share on other sites More sharing options...
headmine Posted January 11, 2007 Author Share Posted January 11, 2007 Let me try to explain.I have an online community. When a someone visits your page it tracks them into the database. It takes your user name their user name the time etc...Let's say your user name is "phpfreak" and their user name is "aspfreak". It shows you that aspfreak has visted your page 20 times. So you decided you want to delete all of aspfreak's visits to your page. You click the link "delete all of this users views". Instead of clicking delete for each record or using check boxes to check all 20.What I am trying to do is delete all the the records from aspfreak under phpfreaks profile. Since aspfreak may have visited other peoples profiles, I don't want to delete all of his views from the database just the ones from phpfreaks profile. So the $_GET['usr'] is your user name and the $_GET['login'] is their user name...I am assuming that you have too loop it somehow until the it deletes all of aspfreaks entries? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 12, 2007 Share Posted January 12, 2007 If that's all you have, then that will delete all of them. Have you tried it? Quote Link to comment Share on other sites More sharing options...
headmine Posted January 12, 2007 Author Share Posted January 12, 2007 I forgot to mention that you have to be logged in to view the page so looking at the code i'm thinking that I need to use a session variable?[code]<?phprequire_once("../Connections/con_php.php");?><?phpmysql_select_db($database_con_php, $con_php);mysql_query("DELETE FROM tracker WHERE `username` = '" . $_SESSION['MM_Username'] . "'AND `login` = '" . $_GET['delete'] ."'");mysql_close($con_php);header("Location: " . $_SERVER['HTTP_REFERER']);?>[/code] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 12, 2007 Share Posted January 12, 2007 ...have...you...tried...the...code...?what....happens...when....you....dooooo? Quote Link to comment Share on other sites More sharing options...
headmine Posted January 12, 2007 Author Share Posted January 12, 2007 [quote author=jesirose link=topic=122024.msg502765#msg502765 date=1168562029]...have...you...tried...the...code...?what....happens...when....you....dooooo?[/quote]it redirects me to the page I was view before but the that users records are still there Quote Link to comment Share on other sites More sharing options...
.josh Posted January 12, 2007 Share Posted January 12, 2007 seperate your string from your query call for easier debugging, and add some error reporting: [code]$sql = "delete from tracker where username = '{$_SESSION['MM_Username']}' and login = '{$_GET['delete']}'";echo $sql;$result = mysql_query($sql) or die(mysql_error());[/code]when you echo $sql you can see exactly what you are sending to the database. From that, you can see if it is sending what you are expecting it to send. Are the variables blank? etc..The mysql_error will report if there was an error, like a syntax error in your query, or maybe some connection error, etc...Also, I don't know what your table looks like, etc.. but:field name: "login"description: Other people who have viewed your page?That doesn't make any sense. Are you sure you are using the right field name? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 12, 2007 Share Posted January 12, 2007 Do this:$sql = "DELETE FROM tracker WHERE `username` = '" . $_SESSION['MM_Username'] . "'AND `login` = '" . $_GET['delete'] ."'";die($sql);What prints out? What you're expecting? Or not? Show us what that displays. Quote Link to comment Share on other sites More sharing options...
headmine Posted January 12, 2007 Author Share Posted January 12, 2007 Whoa... Never knew about that... Yea it wasn't pulling the "your" username it was going in blank so I make it put the username in a querysting and it delete's it now. thanks for showing that die thing... Im a noob when it comes to php.... Thanks alot everyone here is the finished code[code]<?phprequire_once("../Connections/con_php.php");?><?phpmysql_select_db($database_con_php, $con_php);mysql_query("DELETE FROM tracker WHERE username = '" . $_GET['usr'] . "' AND login = '" . $_GET['delete'] . "'");mysql_close($con_php);header("Location: " . $_SERVER['HTTP_REFERER']);?>[/code] Quote Link to comment Share on other sites More sharing options...
Draicone Posted January 13, 2007 Share Posted January 13, 2007 Easy enough. Oh yes, if you want to make your code look more graceful, use exit() instead of die() :-\ 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.