This is my first project with PHP and till this point I can't say I've done horribly bad. How would I go about passing a variable to a custom function through a link? I'll post my code so you can see what I mean. Also, if you see anything that's an amateur thing to do let me know, the only way I can better myself is with criticism.
The link inside the table should send the ID to the remove_from_DB(). When I tested it, it removed everything in the DB.
<?php
//setting DB variables
$host = "localhost";
$user = "xxxxx";
$pass = "xxxxx";
$dbase = "test";
$conn = mysql_connect($host,$user,$pass) or die("Could not connect");
$db = mysql_select_db($dbase);
$query = mysql_query("SELECT * FROM phones");
echo "<table border='1' cellpadding='1' cellspacing='1'>";
echo "<tr><td>ID</td><td>Name</td><td>Phone</td><td>Notes</td></tr>";
while( $row = mysql_fetch_array($query)){
echo "<tr><td>ID: " .$row['ID']. "</td><td>" .$row['name']. "</td><td> " .$row['phone']. "</td><td>" .stripslashes($row['notes']). "</td><td><a href='" .remove_from_DB($row['ID']). "'>Remove?</a></td></tr>";
}
echo "</table>";
?>
<?php
function remove_from_DB(){
echo $id;
//setting DB variables
$host = "localhost";
$user = "xxxxx";
$pass = "xxxxx";
$dbase = "test";
$sql = "DELETE FROM phones WHERE ID=$id";
//connecting to & setting the DB
$conn = mysql_connect($host,$user,$pass) or die("Could not connect");
$db = mysql_select_db($dbase);
//removing data
mysql_query($sql);
mysql_close($conn);
}
?>