【问题标题】:Trouble to link to a MySQL table无法链接到 MySQL 表
【发布时间】:2013-07-29 15:43:35
【问题描述】:

我有这段代码:

<?php
include('base.php');
?>

<?php
if(isset($_GET['MomentEvent']))
{
     $MomentEvent = intval($_GET['MomentEvent']);
     $dn = mysql_query('select TitreEvent, DescriptionEvent from users_event where  MomentEvent="'.$MomentEvent.'"');
     if(mysql_num_rows($dn)>0)
     {
             $dnn = mysql_fetch_array($dn);
             ?>

我的问题是从未建立到 users_event 表的链接,并且:

«Sorry TitreEvent not found»

消息总是在我的脸上弹出。我做错了什么?

编辑:完整代码

<?php
include('base.php');
?>

<?php
if(isset($_GET['MomentEvent']))
 {
     $MomentEvent = intval($_GET['MomentEvent']);
     $dn = mysql_query('select TitreEvent, DescriptionEvent from users_event where MomentEvent="'.$MomentEvent.'"');
     if(mysql_num_rows($dn)>0)
     {
             $dnn = mysql_fetch_array($dn);

 ?>
 This is the profile of "<?php echo htmlentities($dnn['TitreEvent']); ?>" :
 <table style="width:500px;">
     <tr>
     <td><?php
 if($dnn['avatar']!='')
{
     echo '<img src="'.htmlentities($dnn['avatar'], ENT_QUOTES, 'UTF-8').'" alt="Avatar"      style="max-width:100px;max-height:100px;" />';
}
 else
{
     echo 'This user dont have an avatar.';
 }
?></td>
     <td class="left"><h1><?php echo htmlentities($dnn['TitreEvent'], ENT_QUOTES, 'UTF-8'); ?   ></h1>
      Email: <?php echo htmlentities($dnn['DescriptionEvent'], ENT_QUOTES, 'UTF-8'); ?><br />
      </tr>
 </table>
 <?php
     }
     else
     {
             echo 'Sorry TitreEvent not found';
     }
 }
 else
 {
     echo 'The user ID is not defined.';
 }
 ?>
                      </body>
 </html>

【问题讨论】:

  • 好像你在这里遗漏了很多代码
  • 在这里粘贴你的错误
  • 第一个问题是,是否有任何错误(如果没有,您是否确定错误报告已开启)?二、$_GET['MomentEvent']设置了吗?
  • 是的,它设置在另一个页面上。
  • @freddy 好吧,这听起来像是你的问题。为了验证,它是在 URL 的查询字符串中设置的,例如 http://domain/somepage.php?MomentEvent=15,还是您在其他页面上执行 $_GET['MomentEvent'] = 15; 之类的操作?

标签: php mysql hyperlink


【解决方案1】:

您的引号混合和匹配的方式太多了。试试这个

$dn = mysql_query("select TitreEvent, DescriptionEvent from users_event where  MomentEvent=$MomentEvent ");

【讨论】:

  • 看起来你的问题是你用单引号打开,然后用双引号关闭。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-08-29
  • 1970-01-01
  • 2023-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多