我有一个用户注册或注册表格,以允许访问我网站的客人成为注册会员。该表单由名字、姓氏、电子邮件等组成,该操作在提交时转到 process_reg.php。
然后将信息插入到 sql 表“ptb_registrations”中。但它还没有工作,因为我试图从 cookie 会话中随机生成一个带有表单的新用户 ID。我不确定我所做的是否正确。人们可以请纠正我的错误或指出我正确的方向。谢谢。
这是我的 process_reg.php 脚本:
<?php
require_once("session.php");
require_once("functions.php");
require('_config/connection.php');
?>
<?php
session_start();
include '_config/connection.php';
function get_user_id() {
global $connection;
global $email;
$query = "SELECT *
FROM ptb_registrations
WHERE email = \"$email\"
";
$user_id_set = mysql_query($query, $connection);
confirm_query($user_id_set);
return $user_id_set;
}
?>
<?php
$user_id_set = get_user_id();
while ($user_id = mysql_fetch_array($user_id_set)) {
$cookie1 = "{$user_id["id"]}";
setcookie("ptb_registrations", $cookie1, time()+3600); /* expire in 1 hour */
}
?>
<?
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$display_name = $_POST['display_name'];
$date_of_birth = $_POST['date_of_birth'];
$contact_number = $_POST['contact_number'];
$station = $_POST['station'];
$hobbies = $_POST['hobbies'];
$gender = $_POST['gender'];
$password = $_POST['password'];
$result = mysql_query("SELECT first_name FROM ptb_registrations WHERE id=".$cookie1['user_id']."");
$result = mysql_query("SELECT last_name FROM ptb_registrations WHERE id=".$cookie1['user_id']."");
$result = mysql_query("SELECT display_name FROM ptb_registrations WHERE id=".$cookie1['user_id']."");
$result = mysql_query("SELECT email FROM ptb_registrations WHERE id=".$cookie1['user_id']."");
$result = mysql_query("SELECT contact_number FROM ptb_registrations WHERE id=".$cookie1['user_id']."");
$result = mysql_query("SELECT date_of_birth FROM ptb_registrations WHERE id=".$cookie1['user_id']."");
$result = mysql_query("SELECT hobbies FROM ptb_registrations WHERE id=".$cookie1['user_id']."");
$result = mysql_query("SELECT station FROM ptb_registrations WHERE id=".$cookie1['user_id']."");
$result = mysql_query("SELECT gender FROM ptb_registrations WHERE id=".$cookie1['user_id']."");
$result = mysql_query("SELECT password FROM ptb_registrations WHERE id=".$cookie1['user_id']."");
if(!$result)
{
echo "The username you entered does not exist";
}
else
if($email!= mysql_result($result, 0))
{
echo "";
$sql=mysql_query("INSERT ptb_registrations SET first_name='$first_name' WHERE id=".$cookie1['user_id']."");
$sql=mysql_query("INSERT ptb_registrations SET last_name='$last_name' WHERE id=".$cookie1['user_id']."");
$sql=mysql_query("INSERT ptb_registrations SET display_name='$display_name' WHERE id=".$cookie1['user_id']."");
$sql=mysql_query("INSERT ptb_registrations SET email='$email' WHERE id=".$cookie1['user_id']."");
$sql=mysql_query("INSERT ptb_registrations SET contact_number='$contact_number' WHERE id=".$cookie1['user_id']."");
$sql=mysql_query("INSERT ptb_registrations SET date_of_birth='$date_of_birth' WHERE id=".$cookie1['user_id']."");
$sql=mysql_query("INSERT ptb_registrations SET hobbies='$hobbies' WHERE id=".$cookie1['user_id']."");
$sql=mysql_query("INSERT ptb_registrations SET station='$station' WHERE id=".$cookie1['user_id']."");
$sql=mysql_query("INSERT ptb_registrations SET gender='$gender' WHERE id=".$cookie1['user_id']."");
$sql=mysql_query("INSERT ptb_registrations SET password='$password' WHERE id=".$cookie1['user_id']."");
}
if($sql)
{
echo "<div class=\"infobox-profile\"> <strong>Thank You</strong> - We have received your registration details.</div>";
}
else
{
echo "<div class=\"infobox-profile\"> <strong>Oooops!</strong> - Something went wrong. <a href=\"../edit_contact_number.php\">Click here</a> to try again.</div>";
}
?>
<? ob_flush(); ?>
<style>
.infobox-profile {
background-color: #e1e0f7;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #181469;
padding-top: 20px;
padding-right: 10px;
padding-bottom: 20px;
padding-left: 70px;
margin-bottom: 20px;
background-image: url(../img/icons/info-icon.png);
background-repeat: no-repeat;
background-position: 15px center;
border-top-width: 1px;
border-top-style: solid;
border-top-color: #8f8fdb;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-right-color: #8f8fdb;
border-bottom-color: #8f8fdb;
border-left-color: #8f8fdb;
border-radius: 4px;
width: 385px;
margin-left:8px;
}
</style>