Hi, i am a newbie in php programming. I tried to solve my problem many hours, but without any results.
I want to create a href link with unique ID ( ID from db mysql ). After clicking this link you go to the ID info page …
index.php code:
In info.php there is no point querying all of the ‘dog’ table and then looping through to match just one id. Instead i would do a ‘where’ on the query
$result = mysql_query(" SELECT * FROM dog WHERE id = '$link' ");
you need to set the $link variable before that though
’ $link=$_GET[‘id’];’
But this is vulnerable to sql injection so you have to ‘sanitize’ the variable. You should really be using mysqli (note the ‘i’) over mysql but for your example you should at least do this
’ $link= mysql_real_escape_string($_GET[‘id’]);’
You then don’t need the while loop on the query. If you count the num of rows returned you can then do various things such as output a message if no result
For fear of repeating what has been said many times before, you really should not be using the mysql_ functions now as these have been out-of-date for a good many years. You should be using mysqli_ or PDO.
$result = mysql_query(" SELECT * FROM dog ");
mysql_close();
$row = mysql_fetch_array($result)
you run the query, then close the connection to the database, then try to retrieve the results. Lose the middle line.
There are plenty of tutorials around on converting from “old” mysql calls to the newer libraries, grab one and start working through it, and come back with any issues that you encounter.