corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP help again


New Topic

New Poll
  <<  1    2  >> Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author PHP help again
Dan Lewis
Member

Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
3rd Feb 09 at 10:26   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 11:59   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 12:12   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 12:17   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 12:27   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 12:35   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 12:41   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 16:18   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 16:51   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 17:00   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 17:09   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 17:13   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 17:18   View User's Profile U2U Member Reply With Quote



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
3rd Feb 09 at 19:43   View User's Profile U2U Member Reply With Quote

$_GET['id'] ?
Dan Lewis
Member

Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
3rd Feb 09 at 19:50   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 19:51   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 20:03   View User's Profile U2U Member Reply With Quote

If you echo $result from delete.php, what does it contain?
Dan Lewis
Member

Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
3rd Feb 09 at 20:09   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 20:18   View User's Profile U2U Member Reply With Quote

Try
code:

WHERE ID='".$ID."'";

Dan Lewis
Member

Registered: 31st Jan 05
Location: Leicestershire
User status: Offline
3rd Feb 09 at 20:24   View User's Profile U2U Member Reply With Quote

That wont even bring the data across when i echo it.
James_DT
Member

Registered: 9th Apr 04
Location: Cambridgeshire
User status: Offline
3rd Feb 09 at 20:30   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 20:33   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 20:39   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 21:15   View User's Profile U2U Member Reply With Quote

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
3rd Feb 09 at 21:26   View User's Profile U2U Member Reply With Quote

sorted it now just doing the tables on it now. Thanks for your help

  <<  1    2  >>
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
Few Pics from the Pod (56K Warning) PaulW General Chat 12 1057
21st Feb 05 at 16:40
by Jambo
 
Dodgy HTML/PHP/Table problem liamC Geek Day 9 777
24th Jan 07 at 19:37
by liamC
 
phpbb index Tom J Geek Day 3 764
13th Feb 07 at 15:34
by Steve
 
PHP Template Help Laney Geek Day 14 860
17th Jul 07 at 19:26
by Ian
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP help again 28 database queries in 0.0175130 seconds