PHP中未定义的变量 [英] Undefined variable in PHP
本文介绍了PHP中未定义的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是php的新手(它可能是一个愚蠢的问题)。我正在尝试创建一个CRUD应用程序。当我尝试获取值$ countryName时我收到错误
注意:未定义的变量:countryName
if(isset($ _ GET [edited])){
$ country = $ helper-> fetchCountry($ _ GET [ countryId]);
$ countryName = $ country [countryName];
$ helper-> updateCountry($ countryName);
helper :: redirect(?updated = 1);
}
< form action =method =post>
< div class =form-group>
< label>ÜlkeAdı< / label>
< input type =textclass =form-controlname =editName value =<?php echo $ countryName;?>> HERE
< / div>
< div class =form-groupalign =center>
< button class =btn btn-primaryname =btnEdit>编辑< / button>
< / div>
< / form>
这是我到目前为止所尝试的
我尝试了什么:
<?php
包括system / config.php;
包括system / helper.php;
$ conn = new baglanti();
$ helper = new helper();
?>
<!doctype html>
< html lang =en>
< head>
< / head>
< body>
<?php
$ data = $ helper-> fetchAllData();
if(isset($ _ POST [btnAdd])){
$ name = strip_tags($ _ POST [Name]);
$ helper-> addData($ name);
helper :: redirect(?inserted = 1);
}
if(isset($ _ GET [edited])){
$ country = $ helper-> fetchCountry($ _GET [ countryId]);
$ countryName = $ country [countryName];
$ helper-> updateCountry($ countryName);
helper :: redirect(?updated = 1);
}
?>
< div class =container>
< div class =row>
< div class =col-md-8>
< form action =method =post>
< div class =form-group>
< label>ÜlkeAdı< / label>
< input type =textclass =form-controlname =editNamevalue =<?php echo $ countryName;?>>
< / div>
< div class =form-groupalign =center>
< button class =btn btn-primaryname =btnEdit>编辑< / button>
< / div>
< / form>
< form action =method =post>
< div class =form-group>
< label>ÜlkeAdı< / label>
< input type =textclass =form-controlname =Name>
< / div>
< div class =form-groupalign =center>
< button class =btn btn-successname =btnAdd> Ekle< / button>
< / div>
< / form>
< / div>
< table class =table table-striped>
< tr>
< td>ÜlkeAdi< / td>
< td>Düzenle< / td>
< td> Sil< / td>
< / tr>
<?php
if(count($ data)> 0){
foreach($ data as $ key => $ value){
?>
< tr>
< td><?php echo $ value [countryName];?>< / td>
< td>< a href =?edited = 1& countryId =<?php echo $ value [countryId];?>>Düzenle< / a> < / TD>
< td>< a href =?deleted = 1& countryId =<?php echo $ value [countryId];?>> Sil< / a> < / TD>
< / tr>
<?php
}
}其他{
?>
< tr>
< div class =row>
< td colspan =3class =>无数据< / td>
< / div>
< / tr>
<?php
}
?>
< / table>
< / div>
< / div>
< / body>
< / html>
解决方案
countryName
通知:未定义变量:countryName
if(isset(
_GET [edited])){
国=
I am new to php and (Its probably a silly question ).I am trying to make a CRUD application.I am getting error when I try to get the value "$countryName"
Notice: Undefined variable: countryName
if(isset($_GET["edited"])){ $country=$helper->fetchCountry($_GET["countryId"]); $countryName=$country["countryName"]; $helper->updateCountry($countryName); helper::redirect("?updated=1"); }
<form action="" method="post"> <div class="form-group"> <label>Ülke Adı</label> <input type="text" class="form-control" name="editName" value="<?php echo $countryName;?>"> HERE </div> <div class="form-group" align="center"> <button class="btn btn-primary" name="btnEdit">Edit</button> </div> </form>
this what I have tried so far
What I have tried:
<?php include "system/config.php"; include "system/helper.php"; $conn=new baglanti(); $helper=new helper(); ?> <!doctype html> <html lang="en"> <head> </head> <body> <?php $data=$helper->fetchAllData(); if(isset($_POST["btnAdd"])){ $name=strip_tags($_POST["Name"]); $helper->addData($name); helper::redirect("?inserted=1"); } if(isset($_GET["edited"])){ $country=$helper->fetchCountry($_GET["countryId"]); $countryName=$country["countryName"]; $helper->updateCountry($countryName); helper::redirect("?updated=1"); } ?> <div class="container"> <div class="row"> <div class="col-md-8"> <form action="" method="post"> <div class="form-group"> <label>Ülke Adı</label> <input type="text" class="form-control" name="editName" value="<?php echo $countryName;?>"> </div> <div class="form-group" align="center"> <button class="btn btn-primary" name="btnEdit">Edit</button> </div> </form> <form action="" method="post"> <div class="form-group"> <label>Ülke Adı</label> <input type="text" class="form-control" name="Name"> </div> <div class="form-group" align="center"> <button class="btn btn-success" name="btnAdd">Ekle</button> </div> </form> </div> <table class="table table-striped"> <tr> <td>Ülke Adi</td> <td>Düzenle</td> <td>Sil</td> </tr> <?php if(count($data)>0){ foreach ($data as $key=>$value){ ?> <tr> <td><?php echo $value["countryName"] ;?></td> <td><a href="?edited=1&countryId=<?php echo $value["countryId"];?>">Düzenle</a> </td> <td><a href="?deleted=1&countryId=<?php echo $value["countryId"];?>">Sil</a> </td> </tr> <?php } }else{ ?> <tr> <div class="row"> <td colspan="3" class="">No Data</td> </div> </tr> <?php } ?> </table> </div> </div> </body> </html>
解决方案
countryName"
Notice: Undefined variable: countryNameif(isset(
_GET["edited"])){
country=
这篇关于PHP中未定义的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文