Jump to content

MySQL-PHP Database Record Problem.


ilkayivrendi
Go to solution Solved by Psycho,

Recommended Posts

Hello guys. I have a problem with signup form record in database. My code works good but only firstname input doesnt send it to database. Other all information shown up in database. Do you have any idea why it is not working?  

<?php // index.php

session_start();
require_once 'functions.php';

$userfirstname = $lastname = $email = $remember = $error = $username = $pass = $password1 = $password2 = $user = $birthday = $bdd = $bdm = $bdy = "";




$imgavatar = 'img/default_user_avatar.png';

$userstr = '(Guest)';
	if (isset($_SESSION['user']))
	{
		$user = $_SESSION['user'];
		$loggedin = TRUE;
		$userstr = " ($user)";
	}
	
else $loggedin = FALSE;

if ($loggedin){
	//redirect for profile page
}

	if(isset($_POST['username'])&&($_POST['first']) && ($_POST['lastname']) && ($_POST['email'])){
		
		$username = sanitizeString($_POST['username']);
		$password1 = sanitizeString($_POST['p']);
		$password2 = sanitizeString($_POST['p2']);
		$email = sanitizeString($_POST['email']);
		$userfirstname = sanitizeString($_POST['first']);
		$lastname = sanitizeString($_POST['lastname']);
		$bdd = sanitizeString($_POST['day']);
		$bdm = sanitizeString($_POST['month']);
		$bdy = sanitizeString($_POST['year']);
		$birthday = $bdd." / ".$bdm." / ".$bdy;
		
	if ( ($username == "") || ($email =="") || ($password1 =="") || ($password2 =="") || ($userfirstname = "") || ($lastname == ""))
		{
			$error = "You didn't give us enough information for Signup";
		}
		else
		{
			$result = queryMySQL("SELECT * FROM Members WHERE username='$username'");
		
			if($result->num_rows)
			{
				$error ="This Username is already exists";
			}
			else
			{ 
				queryMysql("INSERT INTO Members VALUES( '$userfirstname','$lastname','$email','$username','$password1','$birthday')");
				die("<h4>Account created</h4>Please Log in. Your first name is $userfirstname<br><br>");
				
			}
		}
	}

echo <<<_END
	<DOCTYPE html>
	<html>
		<head>
			<title>World. Your New World</title>
			<link rel='stylesheet' href='styles.css' type='text/css'>
			 <script type="text/javascript" src="javascript/javascript.js"></script>
		</head>
		<body class='home'>
		<div class='loginform'>
		<img id='imgavatar' src='$imgavatar'>
		<form method='post' action='index.php'>
		<input class = 'loginput' type='text' maxlength='16' name='user' value='$user' placeholder='Username'>
		<input class = 'loginput' type='password' maxlength='16' name='pass' value='$pass' placeholder='Password'>
		<h6 id='rememberme'><input type="checkbox" value="None" name="check" checked='checked' />Remember Me</h6>
		<span>$error<br></span>
		<input type='submit' value='Login'>
		</form>
		</div>
		
		<div class='signupform'>
		<h1 id='signhead'>Join Us!</h1>
		<p id='signhead'>It will be free and it will always be free!<br> Creat your own personal tree</p><br><br><br>
		
		<form method='POST' action='index.php'>
		<input class= 'loginput' type='text' maxlength='16' name='first' value='$userfirstname' placeholder='Name'>
		<input class= 'loginput' type='text' maxlength='16' name='lastname' value='$lastname' placeholder='Last Name'><br>
		<input class= 'loginput' type='email' maxlength='32'name='email' value='$email' placeholder='E-mail'>
		<input class= 'loginput' type='text' maxlength='16' name='username' value='$username' placeholder='Username' onBlur='checkUser(this)'><br>
		<input class= 'loginput' type='Password' maxlength='16' name='p' value='$password1' placeholder='Password'>
		<input class= 'loginput' type='Password' maxlength='16' name='p2' value='$password2' placeholder='Repeat Password'><br>
		
		<select name="month" onchange="call()"  value='$bdm'>
		<option value="0">-Month-</option>
		<option value="1">January</option>
		<option value="2">February</option>
		<option value="3">March</option>
		<option value="4">April</option>
		<option value="5">May</option>
		<option value="6">Jun</option> 
		<option value="7">July</option> 
		<option value="8">August</option>
		<option value="9">September</option> 
		<option value="10">October</option> 
		<option value="11">November</option> 
		<option value="12">December</option> 
		</select> 
		<select name="day" value='$bdd'>
		<option value="">-Day-</option>
		</select>
		<select name="year" onchange="call()" value='$bdy'>
		<option value="">-Year-</option>
		</select>
		$userfirstname $lastname 
		<input type='submit' value='Sign Up'>
		</form>
		</div>
		</body>
		</html>
_END;
		

?>
Link to comment
Share on other sites

  • Solution

If you were to add some debugging (such as testing variable values at different stages) I'm sure you would have found the problem. But, I'm too lazy right now to provide a tutorial on how you shoudl debug, so I'll just give the reason your code is not working. Well, not the reason so much, but the specific line of code that is the source of your problem.

 

 

if ( ($username == "") || ($email =="") || ($password1 =="") || ($password2 =="") || ($userfirstname = "") || ($lastname == ""))
Link to comment
Share on other sites

 

If you were to add some debugging (such as testing variable values at different stages) I'm sure you would have found the problem. But, I'm too lazy right now to provide a tutorial on how you shoudl debug, so I'll just give the reason your code is not working. Well, not the reason so much, but the specific line of code that is the source of your problem.

if ( ($username == "") || ($email =="") || ($password1 =="") || ($password2 =="") || ($userfirstname = "") || ($lastname == ""))

Thank you. Yesterday i figure out it by myself. I am wiring all code by notepad++ so sometimes debuging is such a problem for me.Thank you for solution again.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.