我正在将一些文件上传到数据库,我希望有一个PHP表单,可以在输入序列代码时检索有问题的文件。我在数据库中有两个条目,但我的PHP表单一直将它返回为0行。我感谢任何提供的帮助。再次感谢帮助,因为我试图加入那些了解php的人的行列。
表单始终返回:“未找到数据。请检查您的序列号以确保您没有错误输入。如果代码正确,请发送电子邮件给网站管理员以获得进一步的帮助”,就像没有行一样。< / p>
<?php
if( $_POST )
{
$username="st*****";
$password="*****";
$con = mysqli_connect("storycodes.db.10339998.hostedresource.com",$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysqli_select_db($con, "storycodes");
$code = $_POST['codeInput'];
$code = mysqli_escape_string($con, htmlspecialchars($code)); //May not acually need htmlspecialchars
$query = "SELECT story,video FROM `storycodes` WHERE `code` = 'code'";
$result = mysqli_query($con, $query);
if (mysqli_num_rows($result))
{
$row = mysqli_fetch_assoc($result);
mysqli_free_result($result);
extract($row);
echo $story . $video;
}
else
{
echo "No Data Found. Please check your serial code to ensure that you have not incorrectly entered it. If the code is correct please email the website administrator for further assistance";
}
mysqli_close($con);
}
?>
数据库条目: 列是(如果这有帮助的话):代码,电子邮件,视频和故事
b2348-5dfae-73c0c-57685 s * * @ yahoo.com ../ story_files / story.txt
90a93-785e4-03cad-a18d5 w * @ * *。com ../video_files/story.txt ../ story_files / story.txt
代码正在通过此表单发布:
<link href="/CSS/CSS.css" rel="stylesheet" type="text/css">
<p align="center"><span class="linkText"><a href="/index.html">Home</a> <a href="/contact-us.php">Contact Us</a> <a href="/payments.html">Payments</a></span></p>
<p align="center"> </p>
<p align="center"><span class="headingText"><img alt="legendmaker - makes legends: banner" width="728" height="90" /></span></p>
<p align="center"> </p>
<div align="center" class="headingText">Enter Your Serial Code Below To Continue Your Adventure!</div>
<p> </p>
<form name="form1" method="post" action="/scripts/stories.php">
<label>
<div align="center"><span class="formText">Your Serial Code:
<input name="codeInput" type="text" id="codeInput" size="23" maxlength="23">
</span></div>
</label>
<div align="center"><span class="formText">
</span></div>
<span class="formText"><label>
<div align="center"><br>
</div>
</label>
</span>
<label>
<div align="center"><br>
<input type="submit" name="submit" id="submit" value="Submit">
</div>
</label>
</form>
<p> </p>
<p class="headingText"> </p>
<p align="center" class="headingText">Can't find your code?</p>
<p align="center" class="paragraphText">Request an email with your code below.</p>
<form name="form2" method="post" action="/scripts/code_request.php">
<label class="formText">
<div align="center">Email:
<input type="text" name="email" id="email">
</div>
</label>
<p align="center">
<label>
<input type="submit" name="submit2" id="submit2" value="Submit">
</label>
</p>
</form>
<p> </p>
永远不要关心HTML,非常感谢您的帮助。我搞砸了!
答案 0 :(得分:1)
$query = "SELECT story,video FROM `storycodes` WHERE `code` = 'code'";
你在哪里引用你的变量$ code?....
提示 - $
标志很重要......
答案 1 :(得分:1)
$query = "SELECT story,video FROM `storycodes` WHERE `code` = 'code'";
$
缺席。
试试这个:
$query = "SELECT story,video FROM `storycodes` WHERE `code` = '$code'";
或者这个:
$query = "SELECT story,video FROM `storycodes` WHERE `code` = '".$code."'";