how to put delete button?

Discussion in 'PHP' started by spider05906, May 18, 2011.

  1. #1
    Hi all
    as i start im soooooo noobie in php (as much as html) and i want to learn them so badly, so dont mind of you see BIG errors in coding.

    i made a small "website" but i needed to put a delete button for a row of data but i don't know how, so i'm wondering if someone can help me:

    
    <?php
    	include ("config.php");
    	mysql_connect("$host", "$user", "$pass") or die(mysql_error());
    	mysql_select_db("$db") or die(mysql_error());
    
    	$result = mysql_query("SELECT name, url, admin_url, admin_name FROM urls");
    	echo '<table class="imagetable">
    	<tr>
    	<th>Website</th>
    	<th>Admin Page</th>
    	</tr>';
    	while($row = mysql_fetch_array($result))
    		{
    		echo '<tr>';
    		echo '<td><a href="' . $row['url'] . '">' . $row['name'] . '</a></td>'; echo '<td><a href="' . $row['admin_url'] . '" target="_blank">' . $row['admin_name'] . '</a></td>';
    		DELETE CODE SHOULD GO HERE
    		echo '</tr>';
    		}
    	echo '</table>';
    ?>
    
    PHP:

     
    Solved! View solution.
    spider05906, May 18, 2011 IP
  2. zerokvl

    zerokvl Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #2
    After i see, you want to make a button for all the rows, and if you want to delete one, you need the button.
    Well, there you need to create a link like delete.php?url=url ( i think all urls are unique ).
    In delete php you must do the things.

    $url = $_GET['url'];
    $delete = mysql_query("DELETE from urls WHERE url = $url") or die(mysql_error());
    echo"row deleted";

    Hope it helps you.
     
    zerokvl, May 18, 2011 IP
  3. spider05906

    spider05906 Member

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #3
    please bear with me as i'm so noobie ;-)
    what code should go exactly
    
    echo '<tr>';
    		echo '<td><a href="' . $row['url'] . '">' . $row['name'] . '</a></td>';
    		echo '<td><a href="' . $row['admin_url'] . '" target="_blank">' . $row['admin_name'] . '</a></td>';
    		echo '<td>WHAT SHOULD BE HERE';
    		echo '</tr>';
    
    PHP:
    i've done the delete.php already as you posted
     
    spider05906, May 18, 2011 IP
  4. #4
    echo '<tr>';
    echo '<td><a href="' . $row['url'] . '">' . $row['name'] . '</a></td>';
    echo '<td><a href="' . $row['admin_url'] . '" target="_blank">' . $row['admin_name'] . '</a></td>';
    echo '<td><a href="/delete.php?url='.$row['url'].'" title="Delete '.$row['url'].'">Delete '.$row['url'].'"</a> ';
    echo '</tr>';
    Now create a file called delete.php and put the code from my first post.
    This will be something like this:
    If you have the url digitalpoint.com into a row, the link will be delete.php?url=digitalpoint.com, and when you press it will go into delete.php and there will delete the url digitalpoint.com from your database.
     
    zerokvl, May 18, 2011 IP
  5. spider05906

    spider05906 Member

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #5
    thanks zerokvl, it really worked. i owe you man ;-)
     
    spider05906, May 18, 2011 IP