Reputation: 13
Will someone PLEASE explain to me why I get an error saying that $new_cid is unidentified? It only happens when I use .= to append a value to the existing variable.
$dereg_course_student= mysql_query("SELECT * FROM course_student");
$new_cid;
while($row=mysql_fetch_assoc($dereg_course_student)){
$cid=explode(".",$row['cid']);
foreach($cid as $cids){
if($cids==$_GET['cid']){
unset($cids);}
if(isset($cids)){
$new_cid=$new_cid.".{$cids}";}
} mysql_query("UPDATE course_student SET cid={$new_cid} WHERE sno={row['sno']}");
}
Upvotes: 0
Views: 158
Reputation: 428
Because you are using $new_cid;
at the beginning and you aren't specifying what type of variable it should be. In php you don't have to declare variables you can just use $new_cid
in the loop whit no pre-defined value.
$dereg_course_student= mysql_query("SELECT * FROM course_student");
$new_cid='';
while($row=mysql_fetch_assoc($dereg_course_student)){
$cid=explode(".",$row['cid']);
foreach($cid as $cids){
if($cids==$_GET['cid']){
unset($cids);}
if(isset($cids)){
$new_cid.=$cids;}
} mysql_query("UPDATE course_student SET cid=$new_cid WHERE sno=row['sno']");
}
Try it like this.
Upvotes: 1
Reputation: 1162
I don't know that it would actually cause a problem, but I would try setting $new_cid to an empty string, before you try concat'ing with it. Like so:
$new_cid = "";
put that where you have "$new_cid;" right now.
Upvotes: 0