我的本地主机上运行的PHP代码非常好,但是一旦我将页面上传到服务器就会有所不同,任何人都可以建议问题是什么
我不应该在其中添加这些代码的字段:<?=$firstname?>
这是我正在谈论的页面的链接:
[http://studentnet.kingston.ac.uk/k1003140/user1.php]
以下是代码:
<?php
session_start();
if(isset($_SESSION["username"])){
header("location: user1.php"+$u);
} else {
header ("location: index.php");
}
// see if the form has been completed
include_once("php_includes/check_login_status.php");
include_once("php_includes/db_conx.php");
// Initialize any variables that the page might echo
$u = "";
$firstname = "";
$surname = "";
$gender = "Male";
$country = "";
$weight = "";
$height = "";
if(isset($_GET["u"])){
$u = preg_replace('#[^a-z0-9]#i', '', $_GET['u']);
}
$sql = "SELECT * FROM users WHERE username='$u' AND activated='1' LIMIT 1";
$user_query = mysqli_query($db_conx, $sql);
// check if the user exists in the database
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
$firstname = $row["firstname"];
$surname = $row["surname"];
$weight = $row["weight"];
$height = $row["height"];
$email = $row["email"];
$gender = $row ["gender"];
}
if (isset($_POST['submit'])){
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$weight = $_POST['weight'];
$height = $_POST['height'];
$email = $_POST['email'];
$gender = $_POST['gender'];
mysql_connect ("studentnet","k1003140","k1003140"); mysql_select_db('db_k1003140');
// check if that user exist
$exists = mysql_query ("SELECT * FROM users WHERE firstname='" . $firstname . "'") or die ("query cant connect");
if (mysql_num_rows ($exists) != 0) {
// update the description in the database
mysql_query("UPDATE users SET firstname='$firstname', surname='$surname', weight='$weight', height='$height' WHERE firstname='$firstname'") or die ("update could not be applied");
echo "successful";
} else echo "the name does not exist";
}
?>
这是我的代码的PHP
<!DOCTYPE html>
<html>
<head>
<title>update MySql form</title>
</head>
<body>
<div id="pageMiddle">
<form action="user1.php" method="POST">
<div>
<p>First Name: <input type="text" name="firstname" id="firstname" value="<?=$firstname?>"></p>
<p>Surname: <input type="text" name="surname" id="surname" value="<?=$surname?>"></p>
<p>Weight: <input type="text" name="weight" id="weight" value="<?=$weight?>"></p>
<p>Height: <input type="text" name="height" id="height" value="<?=$height?>"></p>
<p> <input type="submit" name="submit" id="submit" value="Update Description"></p>
</div>
</form>
</body>
</html>
任何人都可以建议我如何让用户使用$ u而不是名字来编辑他们的详细信息,因为如果任何人有相同的名称将更改其他用户的详细信息,这也是安全的或任何人都可以更新任何人的详细信息。
答案 0 :(得分:1)
之前PHP 5.4用于打印的短语法运算符
<?= $var ?>
要求在php.ini中启用short_open_tag
问题很可能是因为你启用了short_open_tag(或者你的测试服务器上的php版本比现有版本更新。
如果编辑php.ini并确保将其设置为
short_open_tag = On
然后重新启动您的网络服务器,这应该可以解决您的问题
如果您无法编辑php.ini,那么也可以设置short_open_tag via the .htaccess file
答案 1 :(得分:0)
您需要检查以确保服务器上运行的PHP版本与本地开发计算机以及编译到本地PHP中的任何模块相比,因为这是开发中工作的最常见原因。不在生产中。
确认PHP版本后,可以尝试启用错误以查看错误。
答案 2 :(得分:0)
我已将变量<? =$firstname?>
更改为替代echo $firstname