When putting a display links into a function it all of a sudden shoots up errors ...
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in test/links.php
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in test/links.php
and after taking out the function and just putting in the stuff normally and taking up alot of space it works fine... so my question is does mysql stuff not work properly within a function and if so how can I make something LIKE a function where the mysql still works or how can I still make a function so that it is useable with this script... the database connection works just fine it is within the config.php file and had no problems.
<?php
// database connection
require("config.php");
// display link function
function displaylinks() {
$result = mysql_query("SELECT * FROM links", $db);
echo "<table>";
echo "<tr><td><b>ID</b></td><td><b>Name</b></td><td><b>Description</b></td><td><b>URL</b></td></tr>";
while($myrow = mysql_fetch_array($result)) {
echo "<tr><td>";
echo $myrow["id"];
echo "</td><td>";
echo $myrow["name"];
echo "</td><td>";
echo $myrow["description"];
echo "</td><td>";
echo $myrow["url"];
echo "</td></tr>";
}
echo "</table>";
}
// actual page
if ($_GET['submit'] == addlink) {
$name = $_POST['name'];
$description = $_POST['description'];
$url = $_POST['url'];
$sql = "INSERT INTO links (name, description, url) VALUES ('$name', '$discription', '$url')";
$result = mysql_query($sql);
echo "Thank you! Information entered.";
displaylinks();
} else {
displaylinks();
echo "<br /><br />";
echo "<p>add new link</p>";
echo "<form method=post action=links.php?submit=addlink>";
echo "Name:<input type=Text name=name><br />";
echo "Description:<input type=Text name=description><br />";
echo "URL:<input type=Text name=url><br />";
echo "<input type=Submit name=submit value=\"New Link\">";
echo "</form>";
}
?>