Dan Lewis
Member
Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
|
i have a table and i need the user to be able to click delete and it deletes the row. I have no idea on this
code:
$query_roles_assigned = mysql_query ("
SELECT distinct USER_NAME, ROLE
FROM FOX_MASTER_ROLE_OF_USERS
ORDER BY USER_NAME
");
if(mysql_error())
{
echo mysql_error() ."<br>\n";
}
echo "<table><tr><td>";
echo "<tr><td colspan=3><br>ROLES ASSIGNED<br>---<br></td></tr>";
while($role_assigned = mysql_fetch_array($query_roles_assigned,MYSQL_BOTH))
{
echo "<tr>";
echo "<td width=250>" . $role_assigned[0] . "</td><td width=250>" . $role_assigned[1] . "</td><td width>[DELETE]</td>";
echo "</tr>";
}
|
will_doyle
Banned
Registered: 25th Nov 08
Location: Exeter
User status: Offline
|
you will have more luck posting this on
www.webdesignerforum.co.uk
www.designerstalk.com
www.webdevforums.com
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
Write a script that accepts the id of what needs deleting, and make the link send the script the id
I feel a bit sick at the security aspects of this though ...
|
Sam
Moderator Premium Member
Registered: 24th Dec 99
Location: West Midlands
User status: Offline
|
DROP distinct
That should do it...
Seriously, as Laney says delete the row based on the ID.
|
Dan Lewis
Member
Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
|
its all an internal system for a oracle roll out. arnt really bothered about security.
So i will need to create a new colum in the table for ID's or do i use the array as the ID?
|
Sam
Moderator Premium Member
Registered: 24th Dec 99
Location: West Midlands
User status: Offline
|
Well in MySQL (and I think any DB really) you should have an "id" column which is set to auto increment, and also set as your primary key. Stops you having problems when you come across rows with duplicate data in, as the id column is unique.
[Edited on 03-02-2009 by Sam]
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
quote: Originally posted by Dan Lewis
its all an internal system for a oracle roll out. arnt really bothered about security.
So i will need to create a new colum in the table for ID's or do i use the array as the ID?
Switch it all to OOP and it'd be 10x easier too.
Yeah, you need a unique identifier for each row.
|
Dan Lewis
Member
Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
|
Right i have given each new record a new identifier. for when something is created in the tabel but i cant get it too delete!
code:
$query_roles_assigned = mysql_query ("
SELECT distinct USER_NAME, ROLE, ID
FROM FOX_MASTER_ROLE_OF_USERS
ORDER BY USER_NAME
");
if(mysql_error())
{
echo mysql_error() ."<br>\n";
}
echo "<table><tr><td>";
echo "<tr><td colspan=3><br>ROLES ASSIGNED<br>---<br></td></tr>";
while($role_assigned = mysql_fetch_array($query_roles_assigned))
{
echo "<tr>";
echo "<td width=250>" . $role_assigned[0] . "</td><td width=250>" . $role_assigned[1] . "</td>
<td width><a href='delete.php?id=$role_assigned[2]'>DELETE</a></td>"; echo "</tr>";
}
echo "</td></tr></table>";
?>
then delete.php
code:
<? include("header.inc.php"); ?>
<?
$sql = "DELETE FROM FOX_MASTER_ROLES_OF_USERS WHERE ID='$role_assigned[2]";
$result = mysql_query($sql);
echo "Row deleted!";
?>
Really starting to annoy me now
[Edited on 03-02-2009 by Dan Lewis]
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
code:
<?php
include("header.inc.php");
$id = $_GET['id'];
$sql = "DELETE FROM FOX_MASTER_ROLES_OF_USERS WHERE ID=$id";
$result = mysql_query($sql);
echo "Row deleted!";
?>
I feel ashamed to have written that in a public forum
Then call delete.php?id=id_to_delete
ie: <a href="/delete.php?id=1">[DELETE]</a>
Just promise me you're gonna at least write in SOME sort of variable cleaning
[Edited on 03-02-2009 by Laney]
[Edited on 03-02-2009 by Laney]
|
Dan Lewis
Member
Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
|
That isnt working.
This is the deleting link;
code: <td width><a href='delete.php?id=$role_assigned[2]'>DELETE</a></td>"; echo "</tr>";
so it is taking the ID out the table and you can see the link change when you hover over it. But as soon as you go to the delete.php it wont do anything. If i put in the code Where ID=2 it deletes that row. but everything else i have tried wont work.
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
quote: Originally posted by Dan Lewis
That isnt working.
This is the deleting link;
code: <td width><a href='delete.php?id=$role_assigned[2]'>DELETE</a></td>"; echo "</tr>";
so it is taking the ID out the table and you can see the link change when you hover over it. But as soon as you go to the delete.php it wont do anything. If i put in the code Where ID=2 it deletes that row. but everything else i have tried wont work.
Is it actually connecting to the DB?
Echo out based on $result?
|
Dan Lewis
Member
Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
|
After i have clicked the link it goes to
http://*.*.*.*/FOX/delete.php?id=2
It connects to the database as i can see all the tables and data already on that page.
|
Dan Lewis
Member
Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
|
Like this and on each delete it changes the id which is ok. I just cant get it to pass the data to delete.php with the id=* that it needs to delete
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
$_GET['id'] ?
|
Dan Lewis
Member
Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
|
Well i have changed it a bit now to try a diffent way:
code:
<?php
$query = "SELECT USER_NAME, ROLE, ID FROM FOX_MASTER_ROLE_OF_USERS";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row['USER_NAME']. " - ". $row['ROLE']. " - ". $row['ID']. "<a href='delete.php?id=$row[ID]'>[DELETE]</a>" ;
echo "<br />";
}
?>
Thats the query
code:
<? include("header.inc.php");?>
<?php
$ID = $_GET['id'];
$SQL = "DELETE FROM FOX_MASTER_ROLES_OF_USERS WHERE ID=".$ID;
?>
Thats the delete.php
When i echo the delete.php you can see it gets the values. but it wont delete
|
Dan Lewis
Member
Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
|
when i echo every line the delete.php page i get this
6DELETE FROM FOX_MASTER_ROLES_OF_USERS WHERE ID=6
so it is pulling the correct data but not deleting out the table
[Edited on 03-02-2009 by Dan Lewis]
|
James_DT
Member
Registered: 9th Apr 04
Location: Cambridgeshire
User status: Offline
|
If you echo $result from delete.php, what does it contain?
|
Dan Lewis
Member
Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
|
when i add echo $results to the delete.php page nothing gets added..
|
James_DT
Member
Registered: 9th Apr 04
Location: Cambridgeshire
User status: Offline
|
Try
code:
WHERE ID='".$ID."'";
|
Dan Lewis
Member
Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
|
That wont even bring the data across when i echo it.
|
James_DT
Member
Registered: 9th Apr 04
Location: Cambridgeshire
User status: Offline
|
Yeah, scrap it, it's been a couple of years since I last touched PHP.
What else is in delete.php?
|
Dan Lewis
Member
Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
|
code: <? include("header.inc.php");?>
<?php
$ID = $_GET['id'];
$SQL = "DELETE FROM FOX_MASTER_ROLES_OF_USERS WHERE ID=".$ID;
?>
thats everything in delete.php and if i put echo on the start it shows its getting the correct value. but not deleting it out the table
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
Are you doing mysql_query($sql) still?
If not, its not actually doing anything with the query.
|
James_DT
Member
Registered: 9th Apr 04
Location: Cambridgeshire
User status: Offline
|
Yeah, that's what I was getting at.
You'll need to actually run the query.
|
Dan Lewis
Member
Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
|
sorted it now just doing the tables on it now. Thanks for your help
|