如何在PHP中修复未定义的变量 [英] How to fix a undefined variable in PHP
本文介绍了如何在PHP中修复未定义的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我试图在我的数据库中插入和显示图像,但在插入文件中我收到此错误
是无论如何,我可以解决这个问题。有人能指出我的方向。我不是要求任何人做这个任务只是寻找一些解释和一些解决方案。这是错误
注意:未定义的变量: C中的img_id :\ wamp64 \过网址 15 <\\ _ spanana_itec244 \\\ npp \ upload.php
这就是我的尝试。
我尝试了什么:
< pre > <? php
session_start();
if(isset($ _ POST [' submit']))
{
$ db_host = ' localhost';
$ db_username = ' root';
$ db_password = ;
$ con = mysqli_connect($ db_host,$ db_username,$ db_password)或 die(mysqli_connect_error());
mysqli_select_db($ con,' food')或 die(mysqli_error($ con));
$ sql = SELECT * FROM tbl_images WHERE img_id ='$ img_id';
$ result = mysqli_query($ con,$ sql)或 die( 错误: .mysqli_error($ con));
$ rowcount = mysqli_num_rows($ result);
if($ rowcount> = 1)
{
echo < script type = \text / javascript \;
alert('files not uploaded');
window。 location = \login.html \;
< / script>;
}
其他
{
// < span class =code-comment>将图像插入表中
$ sql = INSERT INTO tbl_images
VALUES('img_id','name','image');
if(mysqli_query($ con,$ sql))
{
mysqli_close($ con);
header( location:dashboard.php);
}
其他
{
echo 插入图像时出错;
}
}
}
?>
解决方案
_POST [' submit']))
{
db_host = ' localhost';
db_username = ' root';
hi
I am trying to insert and display images in my database but in the insert file I am getting this error
is there anyway that i can fix this. can some one point me in the direction. i am not asking no one to do this assignment just looking for some explaining and some resolution to it. this is the error
Notice: Undefined variable: img_id in C:\wamp64\www\luana_itec244\php\upload.php on line 15
this is what I have tried.
What I have tried:
<pre><?php
session_start();
if(isset($_POST['submit']))
{
$db_host='localhost';
$db_username='root';
$db_password="";
$con=mysqli_connect($db_host,$db_username,$db_password) or die(mysqli_connect_error());
mysqli_select_db($con, 'food') or die(mysqli_error($con));
$sql="SELECT * FROM tbl_images WHERE img_id='$img_id'";
$result=mysqli_query($con, $sql) or die("Error:" .mysqli_error($con));
$rowcount=mysqli_num_rows($result);
if($rowcount >=1)
{
echo"<script type=\"text/javascript\";
alert('files not uploaded');
window.location=\"login.html\";
</script>";
}
else
{
//insert images into table
$sql = "INSERT INTO tbl_images
VALUES('img_id','name','image')";
if(mysqli_query($con, $sql))
{
mysqli_close($con);
header("location:dashboard.php");
}
else
{
echo "Error inserting images";
}
}
}
?>
解决方案
_POST['submit'])) {
db_host='localhost';
db_username='root';
这篇关于如何在PHP中修复未定义的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文