Wednesday 9 January 2019

mysql - How to solve Notice: Undefined index: id in C:xampphtdocsinvmgtmanufactured_goodschange.php on line 21




I have a problem with my PHP code saying that "Notice: Undefined index" I am sure its very simple, since I am a beginner i am not getting well what is wrong exactly so please help me.



Here's the code





$id=$_GET['id'];


$query=mysql_query("select * from manuf where id='$id' ")or die(mysql_error());
$row=mysql_fetch_array($query);

?>


































Answer



You are not getting value of $id=$_GET['id'];



And you are using it (before it gets initialised).



Use php's in built isset() function to check whether the variable is
defied or not.




So, please update the line to:



$id = isset($_GET['id']) ? $_GET['id'] : '';

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...