-1

I am getting json data. I decode that data and echo inside the table. I am using url to pass the arrays from the selected row. My problem is, there is a variable which is don't have value always. how can i put condition when i have value i want to pass

here is my code

echo '<td ><a href="sessiondetails.php?'.htmlentities(http_build_query(array('docname'=>$key['DocName'],'HosName'=>$key['HosName'],'HosCode'=>$key['HosCode'],'SpecialitionID'=>$key['SpecializationId'],'DoctorNo'=>$key['DoctorNo'],'day'=>$key['AppDay'],'date'=>$key['AppDate'],'SpecName'=>$key['SpecName'],'town'=>$key['HosTown'],'DoctorNotes'=>$key['DoctorNotes'])),ENT_QUOTES | ENT_HTML401 | ENT_SUBSTITUTE | ENT_DISALLOWED,'UTF-8',true).'">More>></a></font></td></tr>';

this is my error msg when is don't have value

"Undefined index: DoctorNotes"

I don,t have any idea how to solve this.

I am using get method to get the value

$DoctorNotes=$_GET ['DoctorNotes'];

2 Answers2

0

check isset before using $_GET

if(isset($_GET['DoctorNotes']))
{
   $DoctorNotes=$_GET['DoctorNotes'];
} else {
   $DoctorNotes="";
}

Or

$DoctorNotes= isset($_GET['DoctorNotes'])?$_GET['DoctorNotes']:""; 
shubham715
  • 3,324
  • 1
  • 17
  • 27
0

Just check if the value is set, and if it not, set the value of $doctorNotes manually and assign it null value, else use the $_GET value.

if(!isset($_GET['DoctorNotes'])) {
  $doctorNotes = "";
} else {
  $doctorNotes = $_GET['DoctorNotes'];
}
The Law
  • 344
  • 3
  • 20