Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php echo'd表中的超链接问题_Php_Hyperlink_Echo - Fatal编程技术网

php echo'd表中的超链接问题

php echo'd表中的超链接问题,php,hyperlink,echo,Php,Hyperlink,Echo,我的代码有问题,希望有人能帮忙 我尝试使用php echo调用信息,以表格形式显示信息,除了无法识别$id的链接外,它也可以工作。如果我不将其放入表格形式,它可以工作,但在美学上并不吸引人 如有任何建议,将不胜感激 <?php session_start(); if(!isset($_SESSION['name'])){ header("location: ../index.php"); exit(); } // Script Error Reporting error_repor

我的代码有问题,希望有人能帮忙

我尝试使用php echo调用信息,以表格形式显示信息,除了无法识别$id的链接外,它也可以工作。如果我不将其放入表格形式,它可以工作,但在美学上并不吸引人

如有任何建议,将不胜感激

<?php
session_start();
if(!isset($_SESSION['name'])){
    header("location: ../index.php");
exit();
}
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
include_once("../scripts/connect.php");
// Delete Item Question to Admin, and Delete Product if they choose
if (isset($_GET['deleteid'])) {
echo 'Do you really want to delete messages with ID of ' . $_GET['deleteid'] .'? <a     href="admin_messages.php?yesdelete=' . $_GET['deleteid'] . '">Yes</a> | <a href="admin_messages.php">No</a>';
exit();
}
if (isset($_GET['yesdelete'])) {
    // delete from database
$id_to_delete = $_GET['yesdelete'];
$sql = mysql_query("DELETE FROM `mystore`.`messages` WHERE `messages`.`id` =     '$id_to_delete' LIMIT 1") or die (mysql_error());
}
$messages = "";
$sql = mysql_query("SELECT * FROM messages ORDER BY msg_date DESC LIMIT 20");
$count = mysql_num_rows($sql);
if($count > 0){
while($row = mysql_fetch_array($sql)){
    echo '<tr>';
    echo '<td>'.$row['msg_name'].'</td>';
    echo '<td>'.$row['msg_email'].'</td>';
    echo '<td>'.$row['msg_subject'].'</td>';
    echo '<td>'.$row['msg_date'].'</td>';
    echo '<td><a href="mailto: '.$row['msg_email'].'">Reply</a></td>';
    echo '<td><a href="admin_messages.php?deleteid=$id">Delete</a></td>';
    echo '</tr>';
}
}else{
$messages = "<b>There are no messages in the database at this moment</b>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Admin Messages</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="style/forms.css" media="screen">
<link rel="stylesheet" href="style/main.css" media="screen">
</head>
 <body>
    <div id="main_wrapper">
        <?php include_once("templates/tmp_header.php"); ?>
        <?php include_once("templates/tmp_nav.php"); ?>   
        <section id="main_content">
        <h2 class="page_title">Messages</h2>
        <br/>
        <table width="730" cellspacing="0" cellpadding="3" border="1">
            <tr>
                <td align="center" width="100">From</td>
                <td align="center" width="300">Email</td>
                <td align="center" width="300">Subject</td>
                <td align="center" width="100">Date</td>
                <td align="center" width="100">Actions</td
            ></tr>
            <?php echo $messages; ?>
        </table>
    </section>
    <?php include_once("templates/tmp_aside.php"); ?>
    <?php include_once("templates/tmp_footer.php"); ?>
</div>
请换衣服

echo '<td><a href="admin_messages.php?deleteid=$id">Delete</a></td>';


在打印变量时,主字符串必须用双引号括起来。

如果要在PHP中插入变量,需要使用双引号。echo“$id”将直接打印$id,而echo$id将打印变量的值。不过,我建议采取另一种办法。不要在不需要的地方使用PHP。没有必要如此频繁地使用echo

我会将循环的内容更改为:

?>
<tr>
  <td><?=$row['msg_name']?></td>
  <td><?=$row['msg_email']?></td>
  <td><?=$row['msg_subject']?></td>
  <td><?=$row['msg_date']?></td>
  <td><a href="mailto:<?=$row['msg_email']?>">Reply</a></td>
  <td><a href="admin_messages.php?deleteid=<?=$id?>">Delete</a></td>
</tr>
<?php
是PHP版本>=5.4.0的缩写。如果启用了short_open_标记,也可以在以前的版本中使用它

如评论中所述,您应该真正使用mysqli函数,因为mysql函数已被弃用。

注意-mysql函数已被弃用。请使用MYSQLI或PDO使用准备好的语句。
?>
<tr>
  <td><?=$row['msg_name']?></td>
  <td><?=$row['msg_email']?></td>
  <td><?=$row['msg_subject']?></td>
  <td><?=$row['msg_date']?></td>
  <td><a href="mailto:<?=$row['msg_email']?>">Reply</a></td>
  <td><a href="admin_messages.php?deleteid=<?=$id?>">Delete</a></td>
</tr>
<?php