gpt4 book ai didi

php - html 中的奇怪 PHP

转载 作者:行者123 更新时间:2023-11-28 17:59:46 24 4
gpt4 key购买 nike

我已经写了一些 html 代码,一旦我试图在其中放置一些 PHP,这个符号下面的任何东西 ?> 都不会出现!!!我有一些图片和文字,除非我将其放在上面,否则它们不会出现。我正在使用 Bootstrap 2.3 和 phpMyAdmin 4.10 编写。所有语言。感谢您提前抽出时间。

到目前为止,这是我的代码:

<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="bootstrap/css/bootstrap.css">
<link type="text/css" rel="stylesheet" href="bootstrap/css/myStyle.css">
<title>OJRA - Registration</title>
</head>
<body>
<div style="width:400px; height:400px; border-radius:5px; background-color:#aaa; margin-left:100px;">
<form action="" method="post" style="margin-left:20px;">
<h6>Username</h6>
<input type="text" name="username" placeholder="Your Username">
<h6>Password</h6>
<input type="password" name="usrPassowrd" placeholder="Your password">
<h6>Email</h6>
<input type="email" name="usrEmail" placeholder="Your Email"><br>
<input class = "btn btn-default" type="submit" value = "Register">
</form>

</div>
<div style="width:400px; height:400px; border-radius:5px; background-color:#aaa; margin-left:100px;">
<form action="" method="post" style="margin-left:20px;">
<h6>Username:</h6> <input type="text" name="username" placeholder="Your username">
<h6>Password:</h6> <input type="password" name="usrPassowrd" placeholder="Your password">
<input class = "btn btn-default" type="submit" value="Sign in">
</form>
<?php
define('INCLUDE_CHECK',true);

require 'connect.php';


$username = $_POST['username'];
if($username == "")
{
die("cannot go empty");
header("location:index.php");
exit;
}
$password = $_POST['usrPassword'];
$email = $_POST['usrEmail'];

$query = "insert into tz_members values('$username', '$password', '$email')";
mysql_query($query) or die(mysql_error());


?>
</div>
<img src="sexymotivation.jpg" style="margin-top:-800px; margin-right:10px;" class="pull-right">
</body>
</html>

最佳答案

已经概述了一些确实有意义的事情(作为答案),但是我在您的输入中发现了一些打字错误,这些错误会阻止您的表单正常工作,另外还有一些其他要点。

以下是我的一些建议:

首先,这(在 2 个实例中)有一个拼写错误 name="usrPassowrd" 应该读作 name="usrPassword" 以配合您现有的 $password = $_POST['usrPassword'];

正如我在原始评论中所述:

评论 #1: die("cannot go empty"); header("location:index.php"); exit; 您的 header 不会执行任何操作,因为它DIE() 并且将停止运行。

评论#2:我怀疑发生的事情是,因为您将整个代码放在一个大块中,并且如果不满足某些条件......它仍然需要继续前进。现在,我建议您将条件语句包裹在您的 PHP 中....

例如 if(isset($_POST['submit'])){//PHP } 然后将其添加到您的提交按钮 name="submit" - -- 我还建议您将表单和 PHP/SQL 完全分开,并使用我已经概述的相同条件语句将其提交到另一个页面。

如果您绝对想在一个页面中执行所有操作,请尝试以下操作:

注意:我从user3009875's借用了img src也回答一下。

(重写)

<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="bootstrap/css/bootstrap.css">
<link type="text/css" rel="stylesheet" href="bootstrap/css/myStyle.css">
<title>OJRA - Registration</title>
</head>
<body>
<div style="width:400px; height:400px; border-radius:5px; background-color:#aaa; margin-left:100px;">
<form action="" method="post" style="margin-left:20px;">
<h6>Username</h6>
<input type="text" name="username" placeholder="Your Username">
<h6>Password</h6>
<input type="password" name="usrPassword" placeholder="Your password">
<h6>Email</h6>
<input type="email" name="usrEmail" placeholder="Your Email"><br>
<input class = "btn btn-default" type="submit" value = "Register">
</form>

</div>
<div style="width:400px; height:400px; border-radius:5px; background-color:#aaa; margin-left:100px;">
<form action="" method="post" style="margin-left:20px;">
<h6>Username:</h6> <input type="text" name="username" placeholder="Your username">
<h6>Password:</h6> <input type="password" name="usrPassword" placeholder="Your password">
<input class = "btn btn-default" name="submit" type="submit" value="Sign in">
</form>

<?php
// this below, will prevent a premature execution of code
if(isset($_POST['submit'])){

define('INCLUDE_CHECK',true);

require 'connect.php';

$username = $_POST['username'];
if($username == "")
{
die("cannot go empty");
// header("location:index.php"); // commented out
exit;
}
$password = $_POST['usrPassword'];
$email = $_POST['usrEmail'];

$query = "insert into tz_members values('$username', '$password', '$email')";
mysql_query($query) or die(mysql_error());

} // end brace for if(isset($_POST['submit']))

?>
</div>
<!-- commented out original img src -->
<!--
<img src="sexymotivation.jpg" style="margin-top:-800px; margin-right:10px;" class="pull-right">
-->

<!-- new img src by user3009875 in an answer given -->
<img src="sexymotivation.jpg" style="margin-top:100px; margin-right:10px;" class="pull-right">
</body>
</html>

关于php - html 中的奇怪 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20694100/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com