Jump to content

Deleting entry from DB


stelthius

Recommended Posts

Hi guys,

 

Ok here is my problem, i have a script that pulls a list of my servers from the database, were im struggling is being able to remove a server from the DB by the page, what i want to do it now were the tables are is add another cell which will house the delete button at the end of each row of server info, im just struggling on how to do it as im new to php, Any help is greatly appretiated.

 

 

<?php
include("servers/config.php");

print '<b><font face="Verdana" size="2"><center>Currently 
				Active Servers</center><br></font></b><div align="center">
					<table border="0" cellpadding="3" cellspacing="0" width="100%">
						<tr>
							<td height="19" bgcolor="#5376B5">
							<font face="Verdana" size="2" color="#FFFFFF">
							<b>Server IP</b></font></td>
							<td height="19" bgcolor="#5376B5"><b>
							<font face="Verdana" size="2" color="#FFFFFF">
							Server Name</font></b></td>
							<td height="19" bgcolor="#5376B5"><b>
							<font face="Verdana" size="2" color="#FFFFFF">
							VPSs</font></b></td>
							<td height="19" bgcolor="#5376B5"><b>
							<font face="Verdana" size="2" color="#FFFFFF">
							CPUs</font></b></td>
							<td height="19" bgcolor="#5376B5"><b>
							<font face="Verdana" size="2" color="#FFFFFF">
							RAM</font></b></td>
							<td height="19" bgcolor="#5376B5"><b>
							<font face="Verdana" size="2" color="#FFFFFF">
							Price</font></b></td>
							<td height="19" bgcolor="#5376B5"><b>
							<font face="Verdana" size="2" color="#FFFFFF">
							Connection</font></b></td>




						</tr>';

$query = "SELECT * FROM servers";
$result = mysql_query($query); 
while($r=mysql_fetch_array($result)){
$server_ip =$r['server_ip'];
        $server_name =$r['server_name'];
        $allowed_vps =$r['allowed_vps'];
$cpu =$r['cpu'];
$ram =$r['ram'];
$price =$r['price'];
$connection =$r['connection'];

echo "<tr>


							<td width='90' style='border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom: 1px dotted #808080; padding: 3px'>
							<font face='Verdana' size='1'>$server_ip</font></td>

							<td width='90' style='border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom: 1px dotted #808080; padding: 3px'>
							<font face='Verdana' size='1'>$server_name</font></td>

							<td width='50' style='border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom: 1px dotted #808080; padding: 3px'>
							<font face='Verdana' size='1'>$allowed_vps</font></td>

							<td width='40' style='border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom: 1px dotted #808080; padding: 3px'>
							<font face='Verdana' size='1'>$cpu</font></td>

							<td width='40' style='border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom: 1px dotted #808080; padding: 3px'>
							<font face='Verdana' size='1'>$ram</font></td>

							<td width='40' style='border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom: 1px dotted #808080; padding: 3px'>
							<font face='Verdana' size='1'>$price</font></td>

							<td width='40' style='border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom: 1px dotted #808080; padding: 3px'>
							<font face='Verdana' size='1'>$connection</font></td>
						</tr>";
}
print '</table>';
?>

 

Kindest Regards Rick.

Link to comment
Share on other sites

well i was thinking that but the information that is entered into the database is all the same near anough the only thing that would define one row from the other is the ID

 

Example :

 

id server_ip     server_name allowed_vps cpu ram price connection

36  00.00.00.00  test            35            8  8GB  $289  test

34 00.00.00.00 test             15           4 2GB $139 test

 

So basicly in the table on the web page it shows like this

 

Example :

 

Server IP    Server Name    VPSs    CPUs    RAM    Price    Connection

00.00.00.00 test             35     8             8GB   $289      test

00.00.00.00 test             15     4            2GB   $139      test

 

So my problem is adding the function into the table that will remove a certain ID so say my table once finished looked like this below

 

Example :

 

Server IP    Server Name    VPSs    CPUs    RAM    Price    Connection   remove ?

00.00.00.00 test             35     8             8GB   $289      test             Del

00.00.00.00 test             15     4            2GB   $139      test             Del

 

i would click Del on the top account and it would remove only that top account nothing else, i dont know if this makes sense but its the best way i can explain it right now.

 

Regards Rick.

Link to comment
Share on other sites

Well, you could use a list of checkboxes to select which one you delete by giving each box a higher value than the last...

If you don't like checkboxes and want buttons all in one form you can name each of the submit buttons the same but with different values and then use something like this..

 

<?

if ($_POST['delete']) {

mysql_query('delete from mytable where id = \''.$_POST['delete'].'\'');

}

?>

 

HTH

 

Link to comment
Share on other sites

Hi,

 

 

I'd personaly prefer to use buttons but then again i want it all working automaticly by this i mean me not having to change values of the buttons when a new server is added to the list,

 

Your reply was very interesting tho sparked an idea :P

 

 

Regards Rick.

Link to comment
Share on other sites

[...]

<?
if ($_POST['delete']) {
mysql_query('delete from mytable where id = \''.$_POST['delete'].'\'');
}
?>

[...]

 

This is a good example of MySQL Injection

This should be more like:

 

<?php
        $delete_id = mysql_real_escape_string($_POST['delete']);
        mysql_query('DELETE FROM `mytable` where `id` = \''.$delete_id.'\' LIMIT 1');
?>

 

--

jelly

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.