0

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
4
  • 1
    I'd recommend finding a new tutorial that uses PDO or mysqli. mysql_* functions are removed in PHP7, deprecated in previous versions, and are horribly insecure. Commented Jan 10, 2017 at 17:26
  • as @aynber says, this is a horribly outdated tutorial. learn PDO Commented Jan 10, 2017 at 17:27
  • Well... this tutorial is recommended by my professor and he requires knowledge that it contains... But thank you for your advice Commented Jan 10, 2017 at 17:30
  • @JuliuszUrbańczyk As much as you probably have to pass your course, anyone recommending mysql_query is 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 using mysql_real_escape_string to 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. Commented Jan 10, 2017 at 18:17

1 Answer 1

1

Very first thing which you are missing is right php tag.

Next, check with you php version.

Newer version of php has deprecated mysql functions. Use mysqli or PDO instead. If you are using older version try installing ph5-mysql first.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.