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:
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.
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
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.