注意:试图在第24行的/var/www/html/ech/user/actions/punish.php中获取非对象的属


Notice: Trying to get property of non-object in /var/www/html/ech/user/actions/punish.php on line 24

所以我有一个游戏服务器,我正在编写一个名为Echelon的php脚本,该脚本允许我与我的游戏服务器数据库交互,以查看有关玩家的所有信息等。我正试图编写一个惩罚玩家的表单,并将惩罚数据发布到数据库中,但在发布表单时遇到了这个错误注意:试图在第24行的/var/www/html/ech/user/actions/punish.php中获取非对象的属性

这是我的代码,如有帮助,不胜感激:)

<?php
error_reporting(E_ALL); 
ini_set('display_errors', 1);
if (!empty($_POST["punishmenttype"])) {
$punishmenttype = $_POST['punishmenttype'];
$reason = $_POST['reason'];
$duration = $_POST['duration'];
$timescale = $_POST['timescale'];
$time = time();
if ($timescale == 'minutes') {
$duration = ($duration*60);
} elseif ($timescale == 'hours') {
$duration = ($duration*60*60);
} elseif ($timescale == 'days') {
$duration = ($duration*60*60*24);
} elseif ($timescale == 'weeks') {
$duration = ($duration*60*60*24*7); }
$timeexpire = ($time+$duration);
$sql = "INSERT INTO penalties (id, type, client_id, admin_id, duration, inactive, reason, data, time_add, time_edit, time_expire)
VALUES ('NULL', '$punishmenttype', '586', '$echelonid', '$duration', '0', '$reason', '', '$time', '$time', '$timeexpire')";
$result = mysql_query($query);
    echo "Error: " . $sql . "<br>" . $con->error;
}else{ }
?>
<div id="container" class="actionstabcontainer">
<h4 align=center>Punish User</h4>
<form  method="POST" align="center">
<select name="punishmenttype">
<option value="Notice">Notice</option>
<option value="Warning">Warning</option>
<option value="Tempban">Tempban</option>
</select>
<input type="text" name="duration" class="punishtextbox" style="width:55px" placeholder="Duration">
<select name="timescale">
<option value="minutes">Minutes</option>
<option value="hours">Hours</option>
<option value="days">Days</option>
<option value="weeks">Weeks</option>
</select>
<input type="text" name="reason" class="punishtextbox" style="width:140px" placeholder="Reason">
<input type="submit">
</form>
</div>

看起来您的$con没有定义,除非它以某种方式包含在其他地方。确保$con的定义和分配方式使其可访问此页面。

此外,您还可以在$sql变量中定义查询,而不是在calmysql_query($query)中定义查询。$query在哪里定义?