I am trying to learn some MySQL database.
The tutorial (unfortunately is in polish language so I am not gonna link it here) explains me how to make a database on hosting site. It tells me to create base with 3 lines. And then I should be able to edit these lines or delete through website. I am trying to figure out what's wrong with my code, could you help?
<meta charset="utf-8">
<?
$sql = mysql_connect("localhost","lazyorr","aq12wsxx");
mysql_select_db("nwwnd");
$wynik = mysql_query("select id,link from menu order by id");
while ($w = mysql_fetch_row($wynik))
{
echo $w[1]." - ";
echo "<A HREF=\"pobieranie.php?p=e&id=$w[0]\">edytuj</A> ";
echo "<A HREF=\"pobieranie.php?p=u&id=$w[0]\">usuń</A><BR>";
}
if ($_GET["p"] == "u") {
mysql_query("DELETE from menu where id = ".$_GET["id"]);
}
if ($_GET["p"] == "e") {
$wynik = mysql_query("select * from menu where id =".$_GET["id"]);
$w = mysql_fetch_row($wynik);
echo "<FORM METHOD=\"post\" ACTION=\"pobieranie.php\">";
echo "<INPUT TYPE=\"text\" NAME=\"link\" VALUE=\"$w[1]\"><BR>";
echo "<TEXTAREA NAME=\"tresc\">$w[2]</TEXTAREA><BR>";
echo "<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$w[0]\"><BR>";
echo "<INPUT TYPE=\"submit\" VALUE=\"edytuj\">";
echo "</FORM>";
}
if ($_POST["link"] != "" && $_POST["tresc"] != "") {
echo "<BR>Zaktualizowano.";
mysql_query("UPDATE menu SET link =".$_POST["link"]."',tresc ='".$_POST["tresc"]."' where id =".$_POST["id"]);
}
mysql_close($sql);
?>
If you would like to see the website go here
My table name: menu It contains three lines ID - (int(3)) Link - (varchar(100)) Tresc - (text)
(int(3)) contains AUTO_INCREMENT function
Table
ID Link Tresc
1 Link 1 Link 1
2 Link 2 Link 2
3 Link 3 Link 3
mysql_queryis severely misguided. It's been such a blight on PHP that it was removed in PHP 7. If possible, use PDO. If not, escape everything usingmysql_real_escape_stringto avoid injection bugs. Nothing your professor says will ever change the fact that this won't work in a current version of PHP. For up-to-date recommendations see PHP the Right Way.