gpt4 book ai didi

php - 为什么我的PHP中的数据不会上传到我的sql服务器?

转载 作者:行者123 更新时间:2023-11-30 23:23:25 25 4
gpt4 key购买 nike

我已经开始用登录名(用户/通过/头像等)编写基于社区的网站。所有这些变量都存储在sql服务器上,因此我可以访问它们进行登录等。

我在Google各处浏览,代码看起来不错,并且电子邮件验证已发送。但是没有数据上传到我的sql数据库,因此无法创建用户。

我已经在下面包含了我网站的代码,出于安全原因删除了连接信息。为什么无法将数据写入数据库?任何帮助,将不胜感激。

register.php

 <?php require('top.php'); ?>

<div id="full">
<?php

$form = " <form action='register.php' method='post'>

<table cellspacing='10px'>
<tr>

<td></td>
<td>Required Feilds <font color='red'>*</font></td>

</tr>

<tr>

<td>First Name:</td>
<td><input type='text' name='firstname' class='textbox'><font color='red'>*</font></td>

</tr>
<tr>

<td>Last Name:</td>
<td><input type='text' name='lastname' class='textbox'><font color='red'>*</font></td>

</tr>
<tr>

<td>Username:</td>
<td><input type='text' name='username' class='textbox'><font color='red'>*</font></td>

</tr>
<tr>

<td>Email:</td>
<td><input type='text' name='email' class='textbox'><font color='red'>*</font></td>

</tr>
<tr>

<td>Password:</td>
<td><input type='password' name='password' class='textbox'><font color='red'>*</font></td>

</tr>
<tr>

<td>Confirm Password:</td>
<td><input type='password' name='repassword' class='textbox'><font color='red'>*</font></td>

</tr>
<tr>

<td>Avatar:</td>
<td><input type='file' name='avatar' > </td>

</tr>
<tr>

<td>Website Address:</td>
<td><input type='text' name='website' class='textbox'></td>

</tr>
<tr>

<td>YouTube Username:</td>
<td><input type='text' name='youtube' class='textbox'></td>

</tr>
<tr>

<td>Bio:</td>
<td><textarea name='bio' cols='35' rows='5' class='textbox'></textarea> </td>

</tr>
<tr>

<td></td>
<td><input type='submit' name='submitbtn' value='Register' class='button'></td>

</tr>
</table>

</form>";

if($_POST['submitbtn']) {

$firstname = strip_tags($_POST['firstname']);
$lastname = strip_tags($_POST['lastname']);
$username = strip_tags($_POST['username']);
$email = strip_tags($_POST['email']);
$password = strip_tags($_POST['password']);
$repassword = strip_tags($_POST['repassword']);
$website = strip_tags($_POST['website']);
$youtube = strip_tags($_POST['youtube']);
$bio = strip_tags($_POST['bio']);


$name = $_FILES['avatar']['name'];
$type = $_FILES['avatar']['type'];
$size = $_FILES['avatar']['size'];
$tmpname = $_FILES['avatar']['tmp_name'];
$ext = substr($name, strrpos($name, '.'));

if ($firstname && $lastname && $username && $email && $password && $repassword) {

if ($password == $repassword){

if ( strstr($email, "@") && strstr($email, ".") && strlen($email) >= 6) {

require('connect.php');

$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($query);
if ($numrows == 0) {

$query = mysql_query("SELECT * FROM users WHERE email='$email'");
$numrows = mysql_num_rows($query);
if ($numrows == 0) {

$pass = md5(md5($password));
$date =date("F d, Y");

if ($name) {

move_uploaded_file($tmpname, "avatars/$username.$ext");
$avatar = "$username.$ext";

}
else
$avatar = "avatars/defavatar.png";

$code = substr(md5(rand (1111111111, 99999999999999999)), 2, 25);

mysql_query("INSERT INTO users VALUES ('','$firstname','$lastname,'$username','$email','$pass','$avatatar','$bio','$website','$youtube','','0','$code','0','$date')");


$webmaster = "email@email.com";
$subject = "Activate Your Account";
$headers = "From: a person <$webmaster>";
$message = "Hello $firstname. Welcome to awebsite.com Below is a link for you to activate your account.\n\n Click Here to Activate Your Account: http://awebsite.netii.net/activate.php?code=$code";

mail ($email, $subject, $message, $headers);

echo "Thank You for registering. To access your account please activate your account by folowing the link sent to <b>$email</b>. If you do not see the email in your inbox, check your junk mail as it may have been filtered. If you are expeiriencing any problems please contact the site administrator at <a href='mailto:email@email.com'>email@email.com</a>";



}
else
echo "That email is already taken. $form";

}
else
echo "That username is already taken. $form";


}
else
echo "You did not enter a valid email. $form";

}
else
echo "Your Passwords did not match. $form";

}
else
echo "You did not fill in all the required feilds. $form";
}

else
echo "$form";


?>
</div>
<?php require('bottom.php');?>


</div>

</body>
</html>


Activate.php

 <?php $title = "Activate Your Account"; ?>
<?php require('top.php');?>

<div id="full">
<?php

$getcode =$_GET['code'];

$form = "<form action='activate.php' method='post'>
<table>
<tr>
<td>Activate Code:</td>
<td><input type='text' name='code' value='$getcode' size='30' </td>
</tr>
<tr>
<td>Username:</td>
<td><input type='text' name='username' </td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password' </td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='submitbtn' value='Activate'</td>
</tr>
</table>
</form>";

if ($_POST['submitbtn']) {
$code = strip_tags($_POST['code']);
$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);

if ($code && $username && $password) {

if (strlen($code) == 25) {

$pass = md5(md5($password));
require('connect.php');
$query = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$pass'");
$numrows = mysql_num_rows($query);
if ($numrows == 1) {

$row = mysql_fetch_assoc($query);
$dbcode = $row['code'];

if ($code == $dbcode) {

mysql_query("UPDATE users SET active='1' WHERE username='$username'");

echo "Your account has been activated. You may now login. Click<a href='login.php'>here</a> to login.";

}
else
echo"Your activation code was incorrect. $form";

}
else
echo "Your username or password are invalid. $form";

}
else
echo "You have not supplied a valid code. $form";

}
else
echo "You did not fill out the entire form. $form";
}
else
echo "$form";

?>
</div>
<?php require('bottom.php');?>


connect.php

<?php 

$server = "";
$dbuser = "";
$dbpass = "";
$database = "";

mysql_connect($server, $dbuser, $dbpass) or die("Unable to connect to $server");
mysql_select_db($database) or die( "Unable to select $database" );

?>

最佳答案

您的代码中有错别字。

首先,我们必须检查是否设置了提交请求,所以=> if($ _ POST ['submitbtn'])应该是,

if( isset($_POST['submitbtn']) ) {
...
}


更改代码并检查。

编辑

您可以重新格式化代码。检查所有不为空的变量,使用mysql转义而不是strip标签,并且不要对密码使用任何转义,仅使用hash(md5)。

        if (isset($_POST['submitbtn'])) {
$code = mysql_real_escape_string($_POST['code']);
$username = mysql_real_escape_string($_POST['username']);
$password = md5($_POST['password']);
$errors = array();

if (empty($code) || empty($username) || empty($password)) {
$errors[] = "You did not fill out the entire form." . $form;
} elseif(strlen($code) !== 25) {
$errors[] = "You have not supplied a valid code." . $form;
} else {
// further code...
}
} else {
echo $form;
}

关于php - 为什么我的PHP中的数据不会上传到我的sql服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14493128/

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