Jump to content

delete multiple rows without checkboxes


headmine

Recommended Posts

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]
<?php
require_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]
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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]
<?php
require_once("../Connections/con_php.php");
?>
<?php
mysql_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]
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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]
<?php
require_once("../Connections/con_php.php");
?>
<?php
mysql_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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.