GG123
June 23, 2014, 8:11am
1
Hi, help please.
Why am i getting error message
"Notice: Uninitialized string offset: 14001 in C:\xampp\htdocs\Assi\detailspage.php on line 18
Notice: Uninitialized string offset: 1 in C:\xampp\htdocs\Assi\detailspage.php on line 18
ID#:
Notice: Uninitialized string offset: 14001 in C:\xampp\htdocs\Assi\detailspage.php on line 19
Notice: Uninitialized string offset: 2 in C:\xampp\htdocs\Assi\detailspage.php on line 19
Name:
Notice: Uninitialized string offset: 14001 in C:\xampp\htdocs\Assi\detailspage.php on line 20
Details page:
<html>
<head>
<title>Animal Rescue: Details Page </title>
</head>
<body>
<center>
<?php
$num= $_GET[‘id’];
$id=array(
array(“/assi/popi.jpg”,14001,“Popi”,“Shih Tzu”,“Male”, “8yrs 1mth”, “HDB Approved”),
array(“/assi/meow.jpg”,14002,“Meow”,“Local”,“Male”, “4yrs 2mth”, “HDB Approved”),
array(“/assi/muffin.jpg”,14003,“Muffin”,“Local”,“Male”, “5yrs”, “HDB Approved”),
array(“/assi/tabbi.jpg”,14004,“Tabbi”,“Local”,“Male”, “8yrs”, “HDB Approved”),
);
{
echo "<img width='500' height='500' scr=".$id=[$num][0]."> <br/>";
[U]echo "ID#: " . $id[$num][1] . "<br/>";[/U]
[U]echo "Name: " . $id[$num][2] . "<br/>";
echo "Breed: " . $id[$num][3] . "<br/>";[/U]
}
?>
</center>
</body>
</html>
It is the following:
.$id=[$num][0].
You are accidentally performing assignment for $id.
I think you meant to use
.$id[$num][0].
GG123
June 23, 2014, 12:04pm
3
i tried. Same error.
i edited my code but it is still not working.
Error:
Fatal error: Cannot use isset() on the result of an expression (you can use “null !== expression” instead) in C:\xampp\htdocs\Assi\detailspage.php on line 48
Details page:
<html>
<head>
<title>Animal Rescue: Details Page </title>
</head>
<body>
<center>
<?php
$id=isset($_GET['id'])? $_GET['id']: '';
$data= array(
'14001'=>array(
'image' =>'<img src="/assi/popi.jpg" alt="Popi" width="200" height="320" border="0" </img>',
'id'=>'14001',
'Name'=>'Popi',
'Breed'=>'Shih Tzu',
'Gender'=>'Male',
'Age'=>'8yrs 1mth',
'Adopt Condition'=>'HDB Approved'),
'14002'=>array(
'image' =>'<img src="/assi/meow.jpg" alt="Meow" width="200" height="320" border="0" </img>',
'id'=>'14002',
'Name'=>'Meow',
'Breed'=>'Local',
'Gender'=>'Male',
'Age'=>'4yrs 2mth',
'Adopt Condition'=>'HDB Approved'),
'14003'=>array(
'image' =>'<img src="/assi/muffin.jpg" alt="Muffin" width="200" height="320" border="0" </img>',
'id'=>'14003',
'Name'=>'Muffin',
'Breed'=>'Local',
'Gender'=>'Male',
'Age'=>'5yrs',
'Adopt Condition'=>'HDB Approved'),
'14004'=>array(
'image' =>'<img src="/assi/tabbi.jpg" alt="Tabbi" width="200" height="320" border="0" </img>',
'id'=>'14004',
'Name'=>'Tabbi',
'Breed'=>'Local',
'Gender'=>'Male',
'Age'=>'8yrs',
'Adopt Condition'=>'HDB Approved'));
[U]if(isset($id || $id){[/U]
echo "{$data[$id]['image']}"};
?>
</center>
</body>
</html>
As cpradio pointed out, having the = sign is the only major error in the code. The other would be to make sure GET[‘id’] is set and then assign to the variable and use as the key to grab record and wrap those sections in that condition like so.
<html>
<head>
<title>Animal Rescue: Details Page </title>
</head>
<body>
<center>
<?php
$id=array(
array("/assi/popi.jpg",14001,"Popi","Shih Tzu","Male", "8yrs 1mth", "HDB Approved"),
array("/assi/meow.jpg",14002,"Meow","Local","Male", "4yrs 2mth", "HDB Approved"),
array("/assi/muffin.jpg",14003,"Muffin","Local","Male", "5yrs", "HDB Approved"),
array("/assi/tabbi.jpg",14004,"Tabbi","Local","Male", "8yrs", "HDB Approved"),
);
if(isset($_GET['id']) && array_key_exists($_GET['id'],$id)){
$num = $_GET['id'];
echo "<img width='500' height='500' scr=" . $id[$num][0] . "> <br/>";
echo "ID#: " . $id[$num][1] . "<br/>";
echo "Name: " . $id[$num][2] . "<br/>";
echo "Breed: " . $id[$num][3] . "<br/>";
}
?>
</center>
</body>
</html>
Your new error is this line:
if(isset($id || $id){
It should read:
if(isset($id){