我在这里看到很多类似的问题,但与我所经历的完全不同。
我的网站上有一个简单的联系页面,它适用于桌面版本,但是当我使用 jQuery mobile 设置移动版本时,它只是在页面发布时返回未定义。
下面是 php.ini 后面的表格。
<html>
<head>
<title>John's Website | Contact Me</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery.mobile-1.1.0.min.js"></script>
<script type="text/javascript" src="../js/menu.js"></script>
<LINK REL="SHORTCUT ICON" HREF="../favicon.ico">
</head>
<body>
<div data-role="page">
<h2>Fill out the form below to contact me.</h2>
<form action="contact.php" method="post">
<label for="firstName">First Name:</label>
<input type="text" id="firstName" name="firstName" size="40" /><br />
<label for="lastName">Last Name:</label>
<input type="text" id="lastName" name="lastName" size="40" /><br />
<label for="userEmail">Your Email:</label>
<input type="text" id="userEmail" name="userEmail" size="40" /><br />
<label for="message">Message:</label>
<textarea id="message" name="message" cols="30" rows="5"></textarea><br />
<input data-role="none" type="submit" value="Submit"></input>
<input data-role="none" type="reset" value="Reset"></input>
</form>
</div>
</body>
</html>
和 PHP
<?php
$host="localhost"; // Host name
$username="Idont"; // Mysql username
$password="thinkso"; // Mysql password
$db_name="john"; // Database name
$tbl_name="contact"; // Table name
//connect
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
//gather vars and sanitize input
$first_name = htmlentities($_POST['firstName']);
$last_name = htmlentities($_POST['lastName']);
$email = htmlentities($_POST['userEmail']);
$message = htmlentities($_POST['message']);
$date_stamp = date("Y-m-d h:i:s");
$first_name = mysql_real_escape_string($_POST['firstName']);
$last_name = mysql_real_escape_string($_POST['lastName']);
$email = mysql_real_escape_string($_POST['userEmail']);
$message = mysql_real_escape_string($_POST['message']);
if(empty($_POST['firstName']) && empty($_POST['lastName']) &&
empty($_POST['userEmail']) && empty($_POST['message'])){
echo 'You did not fill out all fields. Please go back and enter all info.';
}
//write contents to db.
$sql = "INSERT INTO $tbl_name (firstName, lastName, email, date, message)
VALUES ('$first_name', '$last_name', '$email', '$date_stamp', '$message')";
if(mysql_query($sql)){
$content = "Your message has been sent. /n Click <a href="index.php">here</a> to go
back to the home page.";
} else {
$content = mysql_error() . $date_stamp . 'Unable to send your message. Try again
later.';
}
?>
<html>
<head>
<title>John's Website | Contact Me</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery.mobile-1.1.0.min.js"></script>
<LINK href="../js/jquery.mobile-1.1.0.min.css" rel="stylesheet" type="text/css">
<LINK REL="SHORTCUT ICON" HREF="../favicon.ico">
</head>
<body>
<div data-role="page">
<div data-role="header">its loaded</div>
<div data-role="content"><?php echo $content; ?></div>
</div>
</body>
</html>
我计划使用 PDO 和更多 OO 样式重新编写代码,但页面应该可以工作。这也是我第一次使用 JQM,所以我认为我因此而遗漏了一些东西。