dongxibo2095 2014-06-24 04:13
浏览 9
已采纳

我的代码有什么问题? [关闭]

Please tell me my error.

The errors are:

Notice: Undefined variable: name in C:\wamp\www\3arabschool\admin\section_insert.php on line 10

Source code is here:

<?php
include("../config/config.php");


if(isset($_POST['name'])){ $name = addslashes($_POST['name']); }
if(isset($_POST['order_sec'])){ $order_sec = addslashes($_POST['order_sec']); }
if(isset($_POST['sub'])){ $sub = $_POST['sub']; }


if ($name == ""){   // this is line 10
echo "<div align='center'>please enter name<ahref='javascript:history.back(1)'>back</a></div>";
}else{
$query = @mysqli_query ($con,"INSERT INTO article_sec (name,sub,order_sec)VALUES ('$name','$sub','$order_sec')") or die ("error query");
echo "<p align='center'>done</p>";
echo "<META HTTP-EQUIV='refresh' CONTENT='1' URL='section.php'>";
}
?>
  • 写回答

3条回答 默认 最新

  • doushanmo7024 2014-06-24 04:17
    关注

    You are accessing a variable that isn't defined unless $_POST['name'] has been defined.

    Change the line

    if ($name == ""){
    

    to

    if (empty($name)) {
    

    PHP will check to see if the variable is set before trying to access it and see if it's empty using this function. See this doc for more info

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度