0

我正在将一些文件上传到数据库,我想要一个 PHP 表单,可以在输入序列码时检索有问题的文件。我在数据库中有两个条目,但我的 PHP 表单一直将其返回为 0 行。我感谢提供的任何帮助。再次感谢大家的帮助,让我尝试加入了解php的行列。

表单总是返回:“未找到数据。请检查您的序列码以确保您没有输入错误。如果代码正确,请向网站管理员发送电子邮件以获得进一步的帮助”,就好像没有行一样。

<?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">&nbsp;</p>
<p align="center"><span class="headingText"><img alt="legendmaker - makes legends: banner" width="728" height="90" /></span></p>
<p align="center">&nbsp;</p>
<div align="center" class="headingText">Enter Your Serial Code Below To Continue Your Adventure!</div>

<p>&nbsp;</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>&nbsp;</p>
<p class="headingText">&nbsp;</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>&nbsp;</p>

不要介意HTML,非常感谢您的帮助。我都搞混了!

4

2 回答 2

1
$query = "SELECT story,video FROM `storycodes` WHERE `code` = 'code'";

你在哪里引用你的变量 $code 在这一行?....

提示 -$标志很重要...

于 2013-02-07T03:17:41.927 回答
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."'";
于 2013-02-07T03:21:36.743 回答