I've been working on code for student registration. I finished coding for my log in.
What I'm having a problem with is showing the user's profile: student fname, lname, program, gender and year level in textboxes. I'm using MySQL as my back end.
My code is like this:
<?php
// connects to the database
$mysqli = new mysqli("localhost", "root", "");
$query = 'SELECT fname, lname, program, gender, year FROM students WHERE fname = '.$_SESSION['myusername'];
$mysqli->query($query);
echo "<div align=\"center\">";
echo "<br />Your <b><i>Profile</i></b> is as follows:<br />";
echo "<b>First name:</b> ". $_POST['fname'];
echo "<br /><b>Last name:</b> ".$_POST['lname'];
echo "<br /><b>Program:</b> ".$_POST['program'];
echo "<br /><b>Year:</b> ".$_POST['year'];
echo "<br /><b>Gender:</b> ".$_POST['gender'];
echo "</div>";
?>
This is my code for mainstudent.php and checklogin.php.
Here you go:
<?php
session_start();
// connects to the database
$mysqli = new mysqli("localhost", "root", "");
$query = "SELECT fname, lname, program, gender, year FROM students WHERE fname = '".$_SESSION['myusername']."'";
if($result = $mysqli->query($query))
{
while($row = $result->fetch_assoc())
{
echo "<div align=\"center\">";
echo "<br />Your <b><i>Profile</i></b> is as follows:<br />";
echo "<b>First name:</b> ". $row['fname'];
echo "<br /><b>Last name:</b> ".$row['lname'];
echo "<br /><b>Program:</b> ".$row['program'];
echo "<br /><b>Year:</b> ".$row['year'];
echo "<br /><b>Gender:</b> ".$row['gender'];
echo "</div>"
}
$result->free();
}
else
{
echo "No results found";
}
?>
please add your password in session as well
Related
In my database and more specific in the table named portfolio a user with a speficic username can store more than one data. The columns of the database are id,username,portfolio and portfolio_description
and I want to echo in my web page all the data for this username for example username=nbourlai. Until now I can echo only the first row for each username what is the loop that i can use in order to echo as many time is the id number.
Below is the current result and i want to create Portfolio and Portfolio description to be displayed with the appropriate values as many time as the highest id number is for the specific user.
Here is my code...
$portfolio = queryMysql("SELECT portfolio,portfolio_description FROM portfolio WHERE username='nbourlai'");
$row = mysql_fetch_row($portfolio);
echo "<h2>Portfolio</h2>";
echo "Portfolio: ";
echo stripslashes($row[0]) . "<br/>Portfolio Description: ";
echo stripslashes($row[1]) . "<br clear=left /><br />";
Can you help me please?
Are you looking for while loop like this?
$portfolio = queryMysql("SELECT portfolio,portfolio_description FROM portfolio WHERE username='nbourlai'");
echo "<h2>Portfolio</h2>";
while($row = mysql_fetch_row($portfolio)){
echo "Portfolio: ";
echo stripslashes($row[0]) . "<br/>Portfolio Description: ";
echo stripslashes($row[1]) . "<br clear=left /><br />";
}
or, like this?
$portfolio = queryMysql("SELECT username,portfolio,portfolio_description FROM portfolio ORDER BY username");
$username = '';
while($row = mysql_fetch_row($portfolio)){
if($username != $row[0]){
echo "<h1>".$row[0]."</h1>";
echo "<h2>Portfolio</h2>";
echo "Portfolio: ";
echo stripslashes($row[1]) . "<br/>Portfolio Description: ";
echo stripslashes($row[2]) . "<br clear=left /><br />";
}else{
echo "Portfolio: ";
echo stripslashes($row[1]) . "<br/>Portfolio Description: ";
echo stripslashes($row[2]) . "<br clear=left /><br />";
}
$username = $row[0];
}
I have been trying to fix this code for the last 4 hours and cannot seem to get it to work. The $_SESSION variables are set when the user log's in (or creates an account) and are destroyed when logging out. Yet, when I submit a certain form, suddenly $_SESSION variables which were working before are throwing an undefined variable error. My apologies for the large amount of content, but in due diligence I've come to the conclusion I cannot find it myself and must ask someone for help.
Relevant code in the order a user's actions call the code.
<?php
include 'db_connect.php';
include 'functions.php';
session_start();
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$_SESSION['sessionInitialize'] = false;
// To protect mysqli injection (more detail about mysqli injection)
//$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$mypassword = md5(md5("SaLt".$mypassword."SaLt"));
$query = "SELECT * FROM secure_login.members WHERE username='" . $myusername . "' and password='" . $mypassword . "'";
$result = $mysqli->query($query) or die ($mysqli->error.__LINE__);
// If result matched $myusername and $mypassword, table row must be 1 row
if($result->num_rows == 1){
initializeSessionVariables();
// Register $myusername, $mypassword and redirect to file "acct.php"
$_SESSION['currentUser']=$_POST['myusername'];
//$_SESSION['mypassword']=$_POST['mypassword'];
header("location:myAcct.php");
}
else {
echo "Wrong Username or Password";
header("location:index.php");
}
$mysqli->close();
?>
The function for initializing relevant session variables for the user.
function initializeSessionVariables(){
$_SESSION['currentUser'] = $_SESSION['currentUser'];
$_SESSION['currentUserAcctId'] = "";
$_SESSION['currentUserSummonerId'] = "";
$_SESSION['currentUserLeagues'] = "";
$_SESSION['currentUserEmail'] = "";
$_SESSION['currentUserAvatarURL'] = "";
$_SESSION['currentUserSummName'] = "";
$_SESSION['currentUserRealName'] = "";
$_SESSION['currentUserBday'] = "";
$_SESSION['currentUserSecondEmail'] = "";
}
The account page.
<?php
$summonerName=$_SESSION['currentUser'];
echo "Current User: " . $_SESSION['currentUser'] . "<br>";
echo "<br>Current User \$summonerName: " . $summonerName;
//Create prepared statement.
$query = "SELECT * FROM `stats`.`summoners` WHERE `summoners`.`name`='" . $summonerName . "'";
$result = $mysqli->query($query) or die ($mysqli->error.__LINE__);
echo "<br>test<br><br>";
Print_r ($result);
//Run query if query object returned
if ($result->num_rows == 0){
echo "<h1>=0</h1>";
//Free the result so it can be used in the following functions
$result->free();
getSummonerData(); //defined in functions.php
injectSummonerData(); //defined in functions.php
$query = "SELECT * FROM `stats`.`summoners` WHERE name='" . $summonerName . "'";
$result = $mysqli->query($query) or die ($mysqli->error.__LINE__);
//Get associative array for $result
$row = $result->fetch_assoc();
$_SESSION['currentUserAcctId'] = $row['acctId'];
//Print data.
printf ("<h3>Summoner Name: %s\n <br> Summoner Level: %s\n <br> AcctID: %s\n <br> SummonerID: %s</h3>", $row['name'], $row['summonerLevel'], $row['acctId'], $row['summonerId']);
//Close result object
//$result->close();
echo "<br>";
//Close DB Connection
$mysqli->close();
}
else if($result->num_rows == 1){
echo "<h1>=1</h1>";
$row = $result->fetch_assoc();
$_SESSION['currentUserAcctId'] = $row['acctId'];
printf ("<h3>Summoner Name: %s\n <br> Summoner Level: %s\n <br> AcctID: %s\n <br> SummonerID: %s</h3>", $row['name'], $row['summonerLevel'], $row['acctId'], $row['summonerId']);
echo "<br><h4>This data is already in the database. Did nothing.</h4>";
}
echo "<br>" . $_SESSION['currentUserAcctId'];
?>
Profile.php
<p>Profile info</p>
<?php
displayProfileInformation($_SESSION['currentUser']);
?>
displayProfileInformation Function
function displayProfileInformation($currentUser){
include 'dbstat_connect.php';
$query = "SELECT * FROM `stats`.`userAccount` where `userAccount`.`profName` = '" . $currentUser ."'";
if ($result = $mysqli->query($query) or die ($mysqli->error.__LINE__)){
if ($result->num_rows == 1){
$row = $result->fetch_assoc();
echo "User Name: "; if(isset($currentUser)){echo $currentUser . "<br>";}
echo "Email: "; if(isset($row['email'])){echo $row['email'] . "<br>"; $_SESSION['currentUserEmail'] = $row['email'];}
echo "Avatar URL: "; if(isset($row['avatarURL'])){echo $row['avatarURL'] . "<br>"; $_SESSION['currentUserAvatarURL'] = $row['avatarURL'];}
echo "Summoner Name: "; if(isset($row['summName'])){echo $row['summName'] . "<br>"; $_SESSION['currentUserSummName'] = $row['summName'];}
echo "Real Name: "; if(isset($row['realName'])){echo $row['realName'] . "<br>"; $_SESSION['currentUserRealName'] = $row['realName'];}
echo "Birthdate: "; if(isset($row['bday'])){echo $row['bday'] . "<br>"; $_SESSION['currentUserBday'] = $row['bday'];}
echo "Secondary Email: "; if(isset($row['secondEmail'])){echo $row['secondEmail'] . "<br>"; $_SESSION['currentUserSecondEmail'] = $row['secondEmail'];}
echo "<br>Dafuq yo =1";
}
else if ($result->num_rows == 0){
echo "Dafuq yo =0";
echo "User Name: " . $currentUser . "<br>";
echo "Email: <br>";
echo "Avatar URL: <br>";
echo "Summoner Name: <br>";
echo "Real Name: <br>";
echo "Birthdate: <br>";
echo "Secondary Email: <br>";
echo "<h2>Enter what information you like by editing your profile below.</h2><br>";
}
else {
echo "Critical Error: Contact Admin.";
}
}
}
editProfile.php
Edit Profile
<?php editProfileInformationForm($_SESSION['currentUser']); ?>
editProfileInformationForm Function
function editProfileInformationForm($currentUser){
echo "<form action='processEditProfile.php' method='post'>";
echo "Profile Name: " . $_SESSION['currentUser'] . "<br>";
echo "Account ID: " . $_SESSION['currentUserAcctId'] . "<br>";
if (isset($_SESSION['currentUserEmail'])){
echo "Email: <input name='email' type='text' id='email' value='" . $_SESSION['currentUserEmail'] . "'/><br />";
}
else {
echo "Email: <input name='email' type='text' id='email' value=''/><br />";
}
if (isset($_SESSION['currentUserEmail'])){
echo "Secondary Email: <input name='secEmail' type='text' id='secEmail' value='" . $_SESSION['currentUserSecondEmail'] . "' /><br />";
}
else {
echo "Secondary Email: <input name=secEmail type='text' id=secEmail value=''/><br />";
}
if (isset($_SESSION['currentUserEmail'])){
echo "Real Name: <input name='realName' type='text' id='realName' value='" . $_SESSION['currentUserRealName'] . "' /><br />";
}
else {
echo "Real Name: <input name='realName' type='text' id='realName' value=''/><br />";
}
if (isset($_SESSION['currentUserAvatar'])){
echo "Avatar: <input name='avatar' type='text' id='avatar' value='" . $_SESSION['currentUserAvatarURL'] . "'/><br />";
}
else {
echo "Avatar: <input name='avatar' type='text' id='avatar' value=''/><br />";
}
if (isset($_SESSION['currentUserSummName'])){
echo "Summoner Name: <input name='summName' type='text' id='summName' value='" . $_SESSION['currentUserSummName'] . "'/><br />";
}
else {
echo "Summoner Name: <input name='summName' type='text' id='summName' value=''/><br />";
}
if (isset($_SESSION['currentUserBday'])){
echo "Birthday: <input name='bday' type='text' id='bday' value='" . $_SESSION['currentUserBday'] . "'/><br />";
}
else {
echo "Birthday: <input name='bday' type='text' id='bday' value=''/><br />";
}
echo "<small>(Bday Format~ YYYY-MM-DD)<small>";
echo "<input type='submit' name='submit' value='Submit'>";
echo "</form>";
}
Finally, this is where the error is thrown with the 2 $_SESSION variables. There doesn't seem to be any reason for this, thus why I've come to you all.
<?php
include 'dbstat_connect.php';
//include 'functions.php';
//echo $_SESSION['currentUser'] . "<br>";
//If stmt valid, prepare to insert profile info into `userAccount`
if ($stmt = $mysqli->prepare("INSERT INTO `stats`.`userAccount` values (". $_SESSION['currentUserAcctId'] . ", "
. $_SESSION['currentUser'] . ", ?, ?, ?, ?, ?, ?, NULL, NULL, NULL, NULL, NULL)")){
//Bind paramaters
if($stmt->bind_param('ssssss', $_POST['email'], $_POST['avatar'], $_POST['summName'],
$_POST['realName'], $_POST['bday'], $_POST['secEmail'])){
//Execute the query. If true, show proof. If false, display error.
if($stmt->execute()){
//Show proof of insertion
echo "<h4>Your data has been inserted.</h4>";
}
//Check if stmt returned an error.
else{
Print_r ($stmt->get_warnings());
}
//Close statement
$stmt->close();
}
//If $stmt statement returns an error, say so
else if(!$stmt){
printf ("Error: %s", $mysqli->error);
}
//Close DB Connection
$mysqli->close();
}
echo $_POST['email'];
?>
I really hope someone can help me. I've been stuck here for quite some time now.
Seems you forgot to call session_start(); in your last file ;)
$query = "SELECT * FROM secure_login.members WHERE username='" . $myusername . "' and password='" . $mypassword . "'";
this query is btw. unsafe and not protected against mysql-injections.
you should use the following:
$query = "SELECT * FROM secure_login.members WHERE username='" . $mysqli->real_escape_string($myusername) . "' and password='" . $mysqli->real_escape_string($mypassword) . "'";
On $myspassword the escape-function is probably unnecessary because this value is hashed.
Are you sure you have
session_start();
in all your files, related to this situation?
You MUST have it if you want to use $_SESSION variables through these pages.
I am working on an synonym/alias manager database where the user has the ability to store an association they feel is right. Say the user types in "rabbit" and no synonyms or aliases are found. The user then decides to associate "rabbit" with "bunny" and stores that into a database. Anytime any other user types in "bunny" the results for "rabbit" will appear. However, I am trying to implement a polling system asking the user if they feel the association is correct. If they think "bunny" fits "rabbit" then they vote yes, otherwise no. This is where I am stuck. As soon as I load the poll and press submit everything disappears and nothing gets sent to the database. Code is below:
$query = "SELECT * from searchtestdb where engname in ( SELECT synonyms.synonym FROM words LEFT JOIN synonyms ON synonyms.word_id = words.word_id WHERE word LIKE '%$searchBox%') "; // Query for animals in db
$query = mysql_query($query);
if(mysql_num_rows($query) == 0)
{
echo "<h2>Aliases: </h2>";
echo "Sorry, but we can not find an alias to match your query.";
echo "<br> ";
}
else
{
echo "<h2> Results using Alias: </h2>";
while($result = mysql_fetch_array($query))
{
$query2 = "SELECT * from searchtestdb where engname LIKE '%".$result['engname']."%';";
$result2 = mysql_query($query2);
while($row = mysql_fetch_array($result2))
{
print "<h4>Latin Name: </h4> ";
echo $row["latname"];
echo "<br> ";
print"<h4>English Name:</h4> ";
echo $row["engname"];
echo "<br>";
print "<h4> Species: </h4> ";
echo $row["spectype"];
print "<h4>Characteristics: </h4> ";
echo $row["charc1"];
echo "<br>";
echo $row["charc2"];
echo "<br>";
echo $row["charc3"];
echo "<br>";
}
}
$self = $_SERVER['PHP_SELF'];
print "<form method='post' action='$self' >\n";
print "<h4>Alias Association Correct? : </h4>";
print "<p>" .
"<input type='radio' name='vote' id='vote' value='1' /> \n" .
"Yes" .
"<input type='radio' name='vote' id='vote' value='2' /> \n" .
"No" .
"</p> \n" .
"<p>" .
"<input type='submit'name='submitVote' value='Submit' />" .
"\n </p> \n" .
"</form> \n" .
$vote=htmlentities($_POST['vote']);
echo $vote;
mysql_connect(----------------------) or die(mysql_error());
mysql_select_db("-----------") or die(mysql_error());
if($vote == 1)
{
mysql_query("INSERT INTO items(yes, uNo, word_id) VALUES ('0', '0', bunny');");
mysql_query("UPDATE items SET yes=yes+1 WHERE word_id='bunny';");
echo 'Thanks for voting Yes!';
}
if($vote == 2)
{ mysql_query("INSERT INTO items(word_id) VALUES ('".$result['engname']."'') ");
mysql_query("UPDATE items SET uNo=Uno+1 WHERE word_id='".$result['engname']."'");
echo "changos";
}
}
In a nutshell I made a small mistake:
$self = $_SERVER['PHP_SELF'];
should be
$self = $_SERVER['POST'];
Thanks Anyway.
I am inserting some form data into a sql database, but i want to insert an account type label aswell which is not part of the form data.
So basically the form data gets inserted into the database fine, but i also have a column in my database called 'account_type' which i want to insert the word 'member' into as standard.
Can i do this because i have tried by adding this to the code but it doesn't insert the 'member' into the account type.
Code i have tried adding:
<? $result = mysql_query("UPDATE ptb_registrations SET account_type=Member"); ?>
Rest of insert code for form data:
<?php
session_start();
// other php code here
$_SESSION['display_name'] = $_POST['display_name'];
$_SESSION['password'] = $_POST['password'];
?>
<?php ob_start(); ?>
<?php
session_start();
// GET ACCOUNT INFORMATION FROM FORM AND ASSIGN VARIABLES
$first_name = $_SESSION['first_name'];
$last_name = $_SESSION['last_name'];
$email = $_SESSION['email'];
$date_of_birth = $_SESSION['date_of_birth'];
$contact_number = $_SESSION['contact_number'];
$display_name = $_SESSION['display_name'];
$password = $_SESSION['password'];
?>
<?php
/*
// ECHO ACCOUNT INFORMATION
echo "<strong> Account Information: </strong>";
echo "<br />";
echo First Name: ";
echo "<br />";
echo $first_name;
echo "<br />";
echo "<br />";
echo "Last Name: ";
echo "<br />";
echo $last_name;
echo "<br />";
echo "<br />";
echo "Email: ";
echo "<br />";
echo $email;
echo "<br />";
echo "<br />";
echo "Password: ";
echo "<br />";
echo $password;
echo "<br />";
echo "<br />";
echo "date_of_birth: ";
echo "<br />";
echo $date_of_birth;
echo "<br />";
echo "<br />";
echo "Contact_number: ";
echo "<br />";
echo $contact_number;
echo "<br />";
echo "<br />";
echo "display_name: ";
echo "<br />";
echo $display_name;
echo "<br />";
echo "<br />";
*/
?>
<?php
////// SEND TO DATABASE
/////////////////////////////////////////////////////////
// Database Constants
define("DB_SERVER", "localhost");
define("DB_USER", "root");
define("DB_PASS", "");
define("DB_NAME", "playtime");
// 1. Create a database connection
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
die("Database connection failed: " . mysql_error());
}
// 2. Select a database to use
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
//////////////////////////////////////////////////////////////
$query="INSERT INTO ptb_registrations (ID,
first_name,
last_name,
email,
display_name,
date_of_birth,
contact_number,
password
)
VALUES('NULL',
'".$first_name."',
'".$last_name."',
'".$email."',
'".$display_name."',
'".$date_of_birth."',
'".$contact_number."',
'".$password."'
)";
mysql_query($query) or die ('Error updating database');
?>
<?
$result = mysql_query("UPDATE ptb_registrations SET account_type=Member");
?>
<?php
function confirm_query($result_set) {
if (!$result_set) {
die("Database query failed: " . mysql_error());
}
}
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 */
}
?>
<?php include ('includes/send_email/reg_email.php'); ?>
<? ob_flush(); ?>
Why not insert it at the same time as the registration?
$query="INSERT INTO ptb_registrations (ID,
first_name,
last_name,
email,
display_name,
date_of_birth,
contact_number,
password,
account_type
)
VALUES('NULL',
'{$first_name}',
'{$last_name}',
'{$email}',
'{$display_name}',
'{$date_of_birth}',
'{$contact_number}',
'{$password}',
'Member'
)";
The following
<? $result = mysql_query("UPDATE ptb_registrations SET account_type='Member'"); ?>
will result in making ALL account_type's equal to 'Member' when you dont have a where clause.
To answer you problem, it is most likely due to the fact you do not have single quotes around member in your update command, see my code.
i have a registration form for users to sign up to my site. all there details go to a mysql database like name etc.
When the information is recorded in the database i want on submit of the form for it to create a sequential user_id and store this along with the other details like name and age in the database.
What code would i need for this? sorry i am new to php.
I have tried using a cookie script like this but it won't create a user_id. instead all users in the database have a user_id of 0.
<?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 */
}
?>
Heres my complete code:
<? ob_start(); ?>
<?php
// GET ACCOUNT INFORMATION FROM FORM AND ASSIGN VARIABLES
$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'];
$age = $_POST['age'];
$password = $_POST['password'];
?>
<?php
/*
// ECHO ACCOUNT INFORMATION
echo "<strong> Account Information: </strong>";
echo "<br />";
echo First Name: ";
echo "<br />";
echo $first_name;
echo "<br />";
echo "<br />";
echo "Last Name: ";
echo "<br />";
echo $last_name;
echo "<br />";
echo "<br />";
echo "Email: ";
echo "<br />";
echo $email;
echo "<br />";
echo "<br />";
echo "Password: ";
echo "<br />";
echo $password;
echo "<br />";
echo "<br />";
echo "date_of_birth: ";
echo "<br />";
echo $date_of_birth;
echo "<br />";
echo "<br />";
echo "Contact_number: ";
echo "<br />";
echo $contact_number;
echo "<br />";
echo "<br />";
echo "display_name: ";
echo "<br />";
echo $display_name;
echo "<br />";
echo "<br />";
echo "station: ";
echo "<br />";
echo $station;
echo "<br />";
echo "<br />";
echo "hobbies: ";
echo "<br />";
echo $hobbies;
echo "<br />";
echo "<br />";
echo "age: ";
echo "<br />";
echo $age;
echo "<br />";
echo "<br />";
*/
?>
<?php
////// SEND TO DATABASE
/////////////////////////////////////////////////////////
// Database Constants
define("DB_SERVER", "");
define("DB_USER", "");
define("DB_PASS", "");
define("DB_NAME", "");
// 1. Create a database connection
$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
die("Database connection failed: " . mysql_error());
}
// 2. Select a database to use
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
//////////////////////////////////////////////////////////////
$query="INSERT INTO ptb_registrations (ID,
first_name,
last_name,
email,
display_name,
date_of_birth,
contact_number,
station,
hobbies,
age,
password
)
VALUES('NULL',
'".$first_name."',
'".$last_name."',
'".$email."',
'".$display_name."',
'".$date_of_birth."',
'".$contact_number."',
'".$station."',
'".$hobbies."',
'".$age."',
'".$password."'
)";
mysql_query($query) or die ('Error updating database');
?>
<?php
function confirm_query($result_set) {
if (!$result_set) {
die("Database query failed: " . mysql_error());
}
}
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 */
}
?>
<?php include ('send_email/reg_email.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PlaytimeBoys Registration</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="container">
<h1>Thanks for Registering!</h1>
<h2>Please check your email to confirm your account has been set-up.</h2>
<p> </p>
<p> </p>
<p> </p>
</div>
</body>
</html>
<? ob_flush(); ?>
You don't need to handle this on PHP.
It's better to do it on the MySQL side.
So, on your Users table, field user_id must be defined with property AUTO_INCREMENT.
This way, you don't need to specify user_id parameter when inserting to this table.
Instead, user_id will be generated by the database, as integer, increasing each time by 1.
Try this:
CREATE TABLE Users (
user_id int(11) NOT NULL auto_increment,
first_name varchar(50),
last_name varchar(50)
PRIMARY KEY (user_id)
) ENGINE=InnoDB
You just need to update your database to do so.
you can modify the user_id to be auto increment by running this query
ALTER TABLE `tablename` MODIFY `user_id` INT( 10 ) NOT NULL AUTO_INCREMENT
and when ever you insert entry into your database then specify user_id as null such as this
INSERT INTO 'tablename' (user_id, name, address) VALUES (null, name_value, address_value)