Good day! I am building an online learning site, wherein every user has their own account and they can view their profile through the link of "my profile" whenever they click it. I have tried connecting it to log in but it goes directly to the profile page. This is my codes for instructor_profile.php, how can I connect the link(my profile) from the instructor's menu to profile page? Thank you.
<?php
mysql_connect("localhost", "root", "root");
mysql_select_db("db_elearning");
$idNumber = $_REQUEST['idNumber'];
$get = mysql_query("SELECT * FROM tbl_instructor WHERE idNumber = '$idNumber'");
$get2 = mysql_fetch_assoc($get);
$username = $get2['username'];
$password = $get2['password'];
$lastName = $get2['lastName'];
$firstName = $get2['firstName'];
$middleName = $get2['middleName'];
$location = $get2['location'];
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body,td,th {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 18px;
}
</style>
</head>
<body>
<p> </p>
<p> </p>
<p><br />
</p>
<form id="form1" name="form1" method="post" action="">
<p align="center"><strong>Instructor's profile</strong> </p>
<table border="0" width="30%" align="center">
<tr><td width="40%">
<label for="username">Username</label> </td> <td>
<input type="text" name="username" id="username" value="<?php echo $username;?>" />
</td> </tr>
<tr><td width="40%">
<label for="password">Password</label> </td> <td>
<input type="text" name="password" id="password" value="<?php echo $password;?>" />
</td> </tr>
<tr><td width="40%">
<label for="lastName">Last name</label> </td> <td>
<input type="text" name="lastName" id="lastName" value="<?php echo $lastName;?>" />
</td> </tr>
<tr><td width="40%">
<label for="firstName">First name</label> </td> <td>
<input type="text" name="firstName" id="firstName" value="<?php echo $firstName;?>" />
</td> </tr>
<tr><td width="40%">
<label for="middleName">Middle name</label> </td> <td>
<input type="text" name="middleName" id="middleName" value="<?php echo $middleName;?>" />
</td> </tr>
</td> </tr>
<tr><td width="40%">
<label for="location">Location</label> </td> <td>
<input type="text" name="location" id="location" value="<?php echo $location;?>" />
</td> </tr>
</table>
</form>
</body>
</html>
This is the instructor's log in, it just goes directly to the user's profile
<?php
$username = $_POST['username'];
$password = $_POST['password'];
if($username && $password){
mysql_connect("localhost", "root", "root") or die("Connection to server failed!");
mysql_select_db("db_elearning");
$query = mysql_query("SELECT * FROM tbl_instructor WHERE username ='$username'");
$numrows = mysql_num_rows($query);
if($numrows != 0){
while($row = mysql_fetch_assoc($query)){
$idNumber = $row['idNumber'];
$dbname = $row['username'];
$dbpassword = $row['password'];
}
if($username==$dbname){
if($password==$dbpassword){
header("location:instructor_frame.html");
if ($numrows ==1){
header("location:instructor_profile.php?idNumber=$idNumber");
}else{
echo "Your password is incorrect!";
}
}else{
echo "Your name is incorrect!";
}
}else{
echo "This name is not registered!";
}
}else{
echo "You have to type a name and password!";
}
}
?>
i will tell you how i would do it:
first of all, i will create a config.php and functions.php, which i will include in index.php,
here is my config.php:
<?php
$link = mysqli_connect($db_host,$db_user,$db_pass,$db_name);
// Check connection
if (!$link){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
here is my functions.php:
<?php
function getInstructorsProfileById($id){
global $link;
$sql = "SELECT * FROM 'tbl_instructor' WHERE 'idNumber' = '$idNumber'";
$res = mysqli_query($link,$sql);
$row=mysqli_fetch_assoc($res);
return $row;
}
?>
(Warning up in the code area i cant use the type of quotes i need, so be aware that on the table/column name, inside $sql, you have to use that type of quotes, on my keyboard is on the left of the key 1 it also has ~ if shift is pressed)
and my index.php page is:
<?php
include 'config.php';//necesarily the first
include 'function.php'; // so it would have the global $link variable to call
if(isset($_GET['idNumber'])){
$someVar = getInstructorsProfileById($_GET['idNumber']);
extract($someVar);
?>
<form id="form1" name="form1" method="post" action="">
<p align="center"><strong>Instructor's profile</strong> </p>
<table border="0" width="30%" align="center">
<tr><td width="40%">
<label for="username">Username</label> </td> <td>
<input type="text" name="username" id="username" value="<?php echo $username;?>" />
</td> </tr>
<tr><td width="40%">
<label for="password">Password</label> </td> <td>
<input type="text" name="password" id="password" value="<?php echo $password;?>" />
</td> </tr>
<tr><td width="40%">
<label for="lastName">Last name</label> </td> <td>
<input type="text" name="lastName" id="lastName" value="<?php echo $lastName;?>" />
</td> </tr>
<tr><td width="40%">
<label for="firstName">First name</label> </td> <td>
<input type="text" name="firstName" id="firstName" value="<?php echo $firstName;?>" />
</td> </tr>
<tr><td width="40%">
<label for="middleName">Middle name</label> </td> <td>
<input type="text" name="middleName" id="middleName" value="<?php echo $middleName;?>" />
</td> </tr>
</td> </tr>
<tr><td width="40%">
<label for="location">Location</label> </td> <td>
<input type="text" name="location" id="location" value="<?php echo $location;?>" />
</td> </tr>
</table>
</form>
<?php }else{
echo "some error if there is no number assigned";
}
?>
and the link to this page would be:
<?php $idNumber =7; // the number you know you need, example 7 ?>
My Profile
but this is not the best way, to have a better approach try and search the web for the words session_start(), $_SESSION in php syntax
Hope this helps
Related
I created this form with PHP and MySQL. Whenever I submit the form and click update button it is showing unsucess. I don't know what is going wrong and I need help finding the problem. I've attached the code below.
<?php
error_reporting(E_ALL & ~E_NOTICE);
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
$con = mysqli_connect("localhost","root","") or die("unable to connect");
mysqli_select_db($con,'studentdb');
if(isset($_GET['registernumber']))
$registernumber = html_entity_decode($_GET['registernumber']);
$query= "SELECT * FROM studenttble WHERE registernumber='$registernumber'";
$query_run = mysqli_query($con,$query);
while($row = mysqli_fetch_array($query_run, MYSQL_ASSOC))
{
$IID = $row['IID'];
$studentname = $row['studentname'];
$fathername = $row['fathername'];
$registernumber = $row['registernumber'];
$year = $row['$year'];
$dept = $row['$dept'];
$section = $row['section'];
$gender = $row['gender'];
$password = $row['password'];
$email = $row['email'];
$dob = $row['dob'];
$raddress = $row['raddress'];
$mnumber = $row['mnumber'];
}
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" id="form1" class="myform">
<table align="center">
<tr>
<td>
<input name="estudentname" type="text" id="studentname" class="wp-form-control wpcf7-text" value="<?php echo $studentname?>" />
</td>
</tr>
<br>
<tr>
<td>
<input name="efathername" type="text" id="fathername" class="wp-form-control wpcf7-text" value="<?php echo $fathername?>" />
</td>
</tr>
<tr>
<td>
<input type="hidden" name="registernumber" id="registernumber" class="wp-form-control wpcf7-text" value="<?php echo $registernumber?>" placeholder="Register Number" />
</td>
</tr>
<tr>
<td>
<input type="text" name="egender" id="gender" class="wp-form-control wpcf7-text" value="<?php echo $gender?>" />
</td>
</tr>
<tr>
<td><input type="text" name="eemail" type="email" id="email" class="wp-form-control wpcf7-text" value="<?php echo $email?>" />
</td>
</tr>
<tr>
<td>
<h3 class="table">Date Of Birth: <input type="text" name="edob" id="dob" type="date" class="dropdown-menu-left" value="<?php echo $dob?>" max="2017-02-08"/></td></tr>
</h3>
<tr>
<td> <input type="text" class="wp-form-control wpcf7-textarea" name="eraddress" cols="30" rows="10" value="<?php echo $raddress?>"></textarea>
</td>
</tr>
<tr>
<td> <input name="emnumber" type="text" id="mnumber" pattern="[789][0-9]{9}" class="wp-form-control wpcf7-text" max="10" value="<?php echo $mnumber?>" />
</td>
</tr>
<tr>
<td align="center">
<input type="submit" name="update" class="wpcf7-submit" value="update">
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['update']))
{
$con = mysqli_connect("localhost","root","") or die("unable to connect");
mysqli_select_db($con,'studentdb');
$estudentname = mysql_real_escape_string($_POST['estudentname']);
$efathername = mysql_real_escape_string($_POST['efathername']);
$egender = mysql_real_escape_string($_POST['egender']);
$eemail = mysql_real_escape_string($_POST['eemail']);
$edob = mysql_real_escape_string($_POST['edob']);
$eraddress = mysql_real_escape_string($_POST['eraddress']);
$emnumber = mysql_real_escape_string($_POST['emnumber']);
$targetid = mysqli_real_escape_string($_POST['registernumber']);
mysqli_select_db('studentdb');
$query = "UPDATE studenttble SET studentname ='$estudentname', fathername ='$efathername', gender ='$egender', email ='$eemail', dob ='$edob', raddress ='$eraddress', mnumber ='$emnumber' WHERE registernumber ='$targetid'";
$retval = mysqli_query( $query, $conn );
if($retval)
{
echo "sucess";
}
else
{
echo "unsucess";
}
}
?>
<body>
<?php
$domain = $_POST['domainname'];
?>
<form action="http://" "<?php print $domain; ?>:2083/login" method="POST">
<input type="hidden" name="login_theme" value="cpanel">
<table width="200" class="login" cellpadding="0" cellspacing="0">
<tr>
<td align="left"><b>Login</b></td>
<td> </td>
</tr>
<tr>
<td>Domain</td>
<td>
<input autocomplete="off" type="text" name="domainname" size="16">
</td>
</tr>
<tr>
<td>Username</td>
<td>
<input autocomplete="off" type="text" name="user" size="16">
</td>
</tr>
<tr class="row2">
<td>Password</td>
<td>
<input type="password" name="pass" size="16">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Login" class="input-button">
</td>
</tr>
</table>
</form>
</body>
I have this code on a basic php file. My goal is to have a centralised hub for cpanel users to login into.
They will input their domain name, username and password into the form, the form will take them to http://theirdomain.com/cpanel and log them in by passing the credentials through.
Only problem I am having is outputting the domain variable in the form's action to make it go there. Just getting 'about:blank'
EDIT: I have moved the redirect script over to a second file, and it seems to be redirecting to the domain fine now.
However, now the credentials won't pass through.
<form action="http://<?php echo $domain; ?>:2083/login" method="POST">
<!--form content-->
</form>
Ended up with this (probably not the cleanest, but it works)
index.php
<?php
$domain = $_POST['domainname'];
?>
<form action="cplogin.php" method="post">
Domain: <input type="text" name="domainname" size="50" /><br />
Username: <input type="text" name="user" size="50" /><br />
Password: <input type="password" name="pass" size="20" autocomplete="off" /><br />
<input type="submit" class="btn btn-red" name="login" value="Login" />
</form>
and cplogin.php
<?php
$domain = $_POST['domainname'];
if(!$_POST['login']) {
exit;
}
$user = $_POST['user'];
$pass = $_POST['pass'];
$port = "2083";
$port == "2083" || $port == "2083" ? $pre = "https://" : $pre = "https://";
?>
<body onLoad="setTimeout('document.forms[0].submit();',10)">
<form action="<?php echo "".$pre."".$domain.":".$port."/login/"; ?>" method="post">
<input type="hidden" name="user" value="<?php echo $user; ?>">
<input type="hidden" name="pass" value="<?php echo $pass; ?>">
</form>
I have already created database and table in it.But it is showing an error "input data failed"
the code of reg form is as follow
Code of form login2.php:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Form</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen, projection" />
</head>
<body>
<div id="div-regForm">
<div class="form-title" align ="center">VIDEO CHAT </div>
<br></br>
<div class="form-sub-title" align="center">If already registered</div>
<P align="center">
<td><input type="submit" class="blueButton" value="Sign in" align="right"/>
</P>
<br></br>
<div class="form-title">For New User</div>
<div class="form-title">Sign Up</div>
<div class="form-sub-title">It's free and anyone can join</div>
<form id="regForm" action="validate_login.php" method="post">
<table>
<tbody>
<tr>
<td><label for="fname">First Name:</label></td>
<td><div class="input-container">
<input name="fname" id="fname" type="text" />
</div></td>
</tr>
<tr>
<td><label for="lname">Last Name:</label></td>
<td><div class="input-container">
<input name="lname" id="lname" type="text" />
</div></td>
</tr>
<tr>
<td><label for="email">Your Email:</label></td>
<td><div class="input-container">
<input name="email" id="email" type="text" />
</div></td>
</tr>
<tr>
<td><label for="npass">New Password:</label></td>
<td><div class="input-container">
<input name="npass" id="npass" type="password" />
</div></td>
</tr>
<tr>
<td><label for="cpass">Confirm Password:</label></td>
<td><div class="input-container">
<input name="cpass" id="cpass" type="password" />
</div></td>
</tr>
<tr>
<td><label for="sex-select">I am:</label></td>
<td>
<div class="input-container">
<select name="sex-select" id="sex-select">
<option value="0">Select Sex:</option>
<option value="1">Female</option>
<option value="2">Male</option>
</select>
</div>
</td>
</tr>
<td>
<div class="input-container">
<tr>
<td> </td>
<td><input type="submit" class="greenButton" value="Sign Up" value="Sent" />
<img id="loading" src="img/ajax-loader.gif" alt="working.." />
</td>
</tr>
</tbody>
</table>
</form>
<div id="error">
</div>
</div>
</body>
</html>
to enter data in database code validate_login.php:
`
<?php
// Grab User submitted information
$db_host= "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "testdb";
#mysql_connect("$db_host", "$db_user", "$db_pass")
or die("Could not connect to MySQL server!");
/*#mysql_select_db("$db_name") or die("No DATABASE");
echo"hi how r u";*/
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$email = $_POST["email"];
$npass = $_POST["npass"];
$cpass = $_POST["cpass"];
$gender = $_POST["sex-select"];
// Select the database to use
#mysql_select_db("testdb")
or die("Could not select database!");
$order = "Insert INTO 'data_user'
(fname, lname, email, npass, cpass, sex-select)
VALUES
('$fname',
'$lname','$email','$npass', '$cpass','$gender')";
$result = mysql_query($order); //order executes
if($result){
echo("<br>Input data is succeed");
} else{
echo("<br>Input data is fail");
}
?>
tell me the solution asap
Step1:
Please change the column name as sex-select to sex_select
Step2:
And remove quotes in table name 'data_user' to data_user
So I created an edit profile page and everything went fine. But later on I wanted to use similar code to update another thing inside my database. Its a very odd bugg because when I add to many values that need to be update it refuse to work.
<?php
session_start();
if(isset($_POST['submit'])){
$Creator = $_SESSION['username'];
$dbName = $_POST['Name'];
$dbBase_damage = $_POST['Base_damage'];
$dbDamage = $_POST['Damage'];
$dbPellets = $_POST['Pellets'];
$dbAttackspeed = $_POST['Attackspeed'];
$dbRS = $_POST['RS(first)'];
$dbRS2 = $_POST['RS(consecutive)'];
$dbLoaded = $_POST['Loaded'];
$dbReserve = $_POST['Reserve'];
$dbCritical = $_POST['Critical'];
$dbAbility = $_POST['Ability'];
$dbPiece_set = $_POST['Piece_set'];
$dbBonus_set = $_POST['Bonus_set'];
$dbDescription = $_POST['Description'];
if ($dbName && $dbBase_damage && $dbDamage && $dbAttackspeed && $dbLoaded && $dbCritical) {
mysql_connect ("localhost", "root", "") or die ("Could not connect");
mysql_select_db("weapons") or die ("Could not connect to the database");
$wepquery = mysql_query("SELECT * FROM weapon WHERE Creator='$Creator' AND Name='$dbName'") or die ("The query could not be completed, please try again later!");
if (mysql_num_rows($wepquery) != 0) {
mysql_query ("
UPDATE weapon SET Base_Damage='$dbBase_damage', Damage='$dbDamage',
Pellets='$dbPellets', Attackspeed='$dbAttackspeed', RS(first)='$dbRS', RS(consecutive)='$dbRS2',
Loaded='$dbLoaded', Reserve='$dbReserve', Critical='$dbCritical', Ability='$dbAbility', Piece_set='$dbPiece_set',
Bonus_set='$dbBonus_set' Description='$dbDescription' WHERE Creator='$Creator' AND Name='$dbName'
") or die ("Could not update!");
echo "It just werks!";
}else echo ("That username could not be found!");
}else echo ("Something went wrong!");
}
?>
When I use this code I get an error that 'Base_Damage' is undefined index. But when I remove 'Base_Damage', it can not update at all. I have double checked the database and created 'weapon ideas' with it without problems. But for some reason when I reduce the amount of values that need to be update it works just fine. If you wonder about the "$Creator = $_SESSION['username'];", I get the Creator username depending on who is logged in from "nav.php"
My html code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1.0" />
<title>TF2 NUT</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<div id="Container">
<div id="header">
<h1>Welcome to TF2 NUT!</h1>
</div>
<div id="nav">
<?php
include_once "nav.php";
?>
</div>
<div id="Content">
<h2>Update your submissions</h2>
<form action="edit_sub.php" method="POST">
<table>
<tr>
<td>
Choose weapon to edit:
</td>
<td>
<input type="text" name="Name" id="Name" />
</td>
</tr>
<tr>
<td>
Base damage:
</td>
<td>
<input type="text" name="Base_damage" id="Base_damage" />
</td>
</tr>
<tr>
<td>
Damage:
</td>
<td>
<input type="text" name="Damage" id="Damage" />
</td>
</tr>
<tr>
<td>
Pellets:
</td>
<td>
<input type="text" name="Pellets" id="Pellets" />
</td>
</tr>
<tr>
<td>
Attackspeed:
</td>
<td>
<input type="text" name="Attackspeed" id="Attackspeed" />
</td>
</tr>
<tr>
<td>
Reload speed:
</td>
<td>
<input type="text" name="RS(first)" id="RS(first)" />
</td>
</tr>
<tr>
<td>
Reload(consecutive):
</td>
<td>
<input type="text" name="RS(consecutive)" id="RS(consecutive)" />
</td>
</tr>
<tr>
<td>
Loaded:
</td>
<td>
<input type="text" name="Loaded" id="Loaded" />
</td>
</tr>
<tr>
<td>
Reserve:
</td>
<td>
<input type="text" name="Reserve" id="Reserve" />
</td>
</tr>
<tr>
<td>
Critical:
</td>
<td>
<input type="text" name="Critical" id="Critical" />
</td>
</tr>
<tr>
<td>
Ability:
</td>
<td>
<input type="text" name="Ability" id="Ability" />
</td>
</tr>
<tr>
<td>
Piece set:
</td>
<td>
<input type="text" name="Piece_set" id="Piece_set" />
</td>
</tr>
<tr>
<td>
Bonus set:
</td>
<td>
<input type="text" name="Bonus_set" id="Bonus_set" />
</td>
</tr>
</table>
Description:
<br />
<textarea style="resize: none;" rows="8" cols="40" id="Descripton" name="Description"></textarea>
<br />
<input type='submit' name="submit" value='Update' />
</form>
</div>
<div id="aside">
</div>
<div id="footer">
<h6>Responsible for the stuff on this site is Anton Magnusson</h6>
<h6>If I have done something wrong(I hope not ;_;) just contact me: anton_peace#hotmail.com</h6>
</div>
</div>
Anyone can help? :P
i guess your if statment is not readable and thats why you couldnt update
first your name name="Base_damage" ia not same as your variable index $dbBase_Damage = $_POST['Base_Damage'];
it should be
$dbBase_Damage = $_POST['Base_damage']; // with small d
try replave this also
if ($dbName && $dbBase_Damage && $dbDamage && $dbAttackspeed && $dbLoaded && $dbCritical)
edit:
in your query replace this
RS(first)='$dbRS', RS(consecutive)='$dbRS2'
by
`RS(first)`='$dbRS', `RS(consecutive)`='$dbRS2'
EDIT2:
please replace
or die ("Could not update!");
with
or die(mysql_error()); // like that you can see what error or what goes wrong.
EDIT3.
Bonus_set='$dbBonus_set' , Description=
^^//you missed coma here
I'm trying to create a login and registration system with PHP for a school assignment, but it's currently not really working...
The problem is it generates an error saying the fields are empty, even when you filled the fields in with data, so it shouldn't give this error.
The code:
<html>
<head>
<title>Music Database</title>
<link rel="stylesheet" href="layout.css" type="text/css" />
<?php
// Verbinden met de database //
include('connect.php');
// Registreer data verkrijgen en in variabelen zetten //
if(isset($_POST['r_submit'])){
$r_username = $_POST['r_username'];
$r_password = $_POST['r_password'];
$confirm_r_password = $_POST['confirm_r_password'];
$r_name = $_POST['r_name'];
$r_surname = $_POST['r_surname'];
$r_birth = $_POST['r_dateofbirth'];
$r_mail = $_POST['r_mail'];
}
?>
</head>
<body>
<div id="login">
<form name="login" action="login.php" method="post">
<p>Login: <input class="input" type="text" name="username" value="Username" />
<input id="password" type="password" name="password" value="Password" /></p>
<div><a class="link" href="register.php">Register here!</a></div>
<p align="center"><input class="submit" type="submit" name="login_submit" value="Submit" /></p>
</form>
</div>
<div id="header">
<a class="link" href="index.php">Music Database</a>
</div>
<div id="search">
<form name="search" action="search.php" method="post">
<p>Search for: <input class="input" type="text" name="search" value="<?php if(isset($_POST['search'])) print $_POST['search']; ?>" />
<input class="submit" type="submit" name="search_submit" value="Submit" /></p>
<p>Artist: <input type="checkbox" name="artistsearch" checked />
Album: <input type="checkbox" name="albumsearch" />
Song: <input type="checkbox" name="songsearch" />
Genre: <input type="checkbox" name="genresearch" /></p>
</form>
</div>
<div id="wrapper"><br /></div>
<div id="content">
<h1>Register down here please:</h1>
<table id="wrap_table">
<tr>
<td>
<div id="reg_content">
<div id="reg_form">
<form name="register_login" action="register.php" method="post">
<fieldset>
<legend>Login Data: </legend>
<table class="r_table">
<tr>
<td>Username<sup>*</sup>: </td>
<td><input class="input" type="text" name="r_username" value="<?php if(isset($r_username)){ print $_POST['r_username']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_username)){
echo "<td>Error: No Username has been entered!</td>";
}
}
?>
</tr>
<tr>
<td>Password<sup>*</sup>: </td>
<td><input class="input" type="password" name="r_password" value="<?php if(isset($r_password)){ print $_POST['r_password']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_password)){
echo "<td>Error: No Password has been entered!</td>";
}
}
?>
</tr>
<tr>
<td>Confirm Password<sup>*</sup>: </td>
<td><input class="input" type="password" name="confirm_r_password" value="<?php if(isset($confirm_r_password)){ print $_POST['confirm_r_password']; } ?>"/></td>
<?php
if(isset($confirm_password)){
if($confirm_r_password != $r_password){
echo "<td>Error: The passwords don't match!</td>";
}
}
?>
</tr>
</table>
</fieldset>
</form>
</div>
</td>
<td>
<div id="reg_form">
<form name="register_personal" action="register.php" method="post">
<fieldset>
<legend>Personal Data: </legend>
<table class="r_table_personal">
<tr>
<td>Name: </td>
<td><input class="input" type="text" name="r_name" value=""/></td>
</tr>
<tr>
<td>Surname: </td>
<td><input class="input" type="text" name="r_surname" value=""/></td>
</tr>
<tr>
<td>Date of Birth: </td>
<td><input class="input" type="text" name="r_dateofbirth" value=""/></td>
</tr>
<tr>
<td>E-mail<sup>*</sup>: </td>
<td><input class="input" type="text" name="r_mail" value="<?php if(isset($r_mail)){ print $_POST['r_mail']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_mail)){
echo "<td>Error: No E-mail has been entered!</td>";
}
}
?>
</tr>
</table>
</fieldset>
</form>
</div>
</div>
</td>
</tr>
<tr>
<td>Fields with an asterisk<sup>*</sup> are required for registry!
<div id="reg_content">
<form name="submit_registry" action="register.php" method="post">
<input class="submit" type="submit" name="r_submit" value="Submit!" />
</form>
</div>
</td>
</tr>
</table>
</div>
<div id="footerbreak"><br /></div>
<div id="footer"> © Jorik ter Molen & Camiel Collet, 2011.</div>
</body>
do you have your <form action="" method="post"> in there?
you can also debug your $_POST global to see whats happening (if data is hitting your script)
var_dump($_POST);
So you include the first "form" page in the second php file after the code right?
First of all in the PHP file you should add all the
if(isset($_POST['submit'])){
segments into one:
if(isset($_POST['submit'])){
$r_username = $_POST['r_username'];
$r_password = $_POST['r_password'];
$confirm_r_password = $_POST['confirm_r_password'];
$r_name = $_POST['r_name'];
$r_surname = $_POST['r_surname'];
$r_birth = $_POST['r_dateofbirth'];
$r_mail = $_POST['r_mail'];
}
Your problem is most probably in $_POST['submit'] since you have two checks, one for $_POST['submit'] and another for $_POST['r_submit']
Unless you send it both ways i suggest you change the PHP file to check for 'r_submit'
Update:
Try putting the form inside the register.php page so it looks like this:
<?php
if(isset($_POST['r_submit'])){
$r_username = $_POST['r_username'];
$r_password = $_POST['r_password'];
$confirm_r_password = $_POST['confirm_r_password'];
}
?>
<form action="register.php" method="post">
<td>Username<sup>*</sup>: </td>
<td><input class="input" type="text" name="r_username" value="<?php if(isset($r_username)){ print $_POST['r_username']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_username)){
echo "<td>Error: No Username has been entered!</td>";
}
}
?>
</tr>
<tr>
<td>Password<sup>*</sup>: </td>
<td><input class="input" type="password" name="r_password" value="<?php if(isset($r_password)){ print $_POST['r_password']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_password)){
echo "<td>Error: No Password has been entered!</td>";
}
}
?>
</tr>
<tr>
<td>Confirm Password<sup>*</sup>: </td>
<td><input class="input" type="password" name="confirm_r_password" value="<?php if(isset($confirm_r_password)){ print $_POST['confirm_r_password']; } ?>"/></td>
<?php
if(isset($confirm_password)){
if($confirm_r_password != $r_password){
echo "<td>Error: The passwords don't match!</td>";
}
}
?>
</tr>
<input name="r_submit" type="submit" value="Submit" />
</form>
Solution:
<html>
<head>
<title>Music Database</title>
<link rel="stylesheet" href="layout.css" type="text/css" />
<?php
// Verbinden met de database //
include('connect.php');
// Registreer data verkrijgen en in variabelen zetten //
if(isset($_POST['r_submit'])){
$r_username = $_POST['r_username'];
$r_password = $_POST['r_password'];
$confirm_r_password = $_POST['confirm_r_password'];
$r_name = $_POST['r_name'];
$r_surname = $_POST['r_surname'];
$r_birth = $_POST['r_dateofbirth'];
$r_mail = $_POST['r_mail'];
}
?>
</head>
<body>
<div id="login">
<form name="login" action="login.php" method="post">
<p>Login: <input class="input" type="text" name="username" value="Username" />
<input id="password" type="password" name="password" value="Password" /></p>
<div><a class="link" href="register.php">Register here!</a></div>
<p align="center"><input class="submit" type="submit" name="login_submit" value="Submit" /></p>
</form>
</div>
<div id="header">
<a class="link" href="index.php">Music Database</a>
</div>
<div id="search">
<form name="search" action="search.php" method="post">
<p>Search for: <input class="input" type="text" name="search" value="<?php if(isset($_POST['search'])) print $_POST['search']; ?>" />
<input class="submit" type="submit" name="search_submit" value="Submit" /></p>
<p>Artist: <input type="checkbox" name="artistsearch" checked />
Album: <input type="checkbox" name="albumsearch" />
Song: <input type="checkbox" name="songsearch" />
Genre: <input type="checkbox" name="genresearch" /></p>
</form>
</div>
<div id="wrapper"><br /></div>
<div id="content">
<h1>Register down here please:</h1>
<table id="wrap_table">
<tr>
<td>
<div id="reg_content">
<div id="reg_form">
<form name="register_login" action="register.php" method="post">
<fieldset>
<legend>Login Data: </legend>
<table class="r_table">
<tr>
<td>Username<sup>*</sup>: </td>
<td><input class="input" type="text" name="r_username" value="<?php if(isset($r_username)){ print $_POST['r_username']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_username)){
echo "<td>Error: No Username has been entered!</td>";
}
}
?>
</tr>
<tr>
<td>Password<sup>*</sup>: </td>
<td><input class="input" type="password" name="r_password" value="<?php if(isset($r_password)){ print $_POST['r_password']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_password)){
echo "<td>Error: No Password has been entered!</td>";
}
}
?>
</tr>
<tr>
<td>Confirm Password<sup>*</sup>: </td>
<td><input class="input" type="password" name="confirm_r_password" value="<?php if(isset($confirm_r_password)){ print $_POST['confirm_r_password']; } ?>"/></td>
<?php
if(isset($confirm_password)){
if($confirm_r_password != $r_password){
echo "<td>Error: The passwords don't match!</td>";
}
}
?>
</tr>
</table>
</fieldset>
</div>
</td>
<td>
<div id="reg_form">
<fieldset>
<legend>Personal Data: </legend>
<table class="r_table_personal">
<tr>
<td>Name: </td>
<td><input class="input" type="text" name="r_name" value=""/></td>
</tr>
<tr>
<td>Surname: </td>
<td><input class="input" type="text" name="r_surname" value=""/></td>
</tr>
<tr>
<td>Date of Birth: </td>
<td><input class="input" type="text" name="r_dateofbirth" value=""/></td>
</tr>
<tr>
<td>E-mail<sup>*</sup>: </td>
<td><input class="input" type="text" name="r_mail" value="<?php if(isset($r_mail)){ print $_POST['r_mail']; } ?>"/></td>
<?php
if(isset($_POST['r_submit'])){
if(!isset($r_mail)){
echo "<td>Error: No E-mail has been entered!</td>";
}
}
?>
</tr>
</table>
</fieldset>
</div>
</div>
</td>
</tr>
<tr>
<td>Fields with an asterisk<sup>*</sup> are required for registry!
<div id="reg_content">
<input class="submit" type="submit" name="r_submit" value="Submit!" />
</div>
</form>
</td>
</tr>
</table>
</div>
<div id="footerbreak"><br /></div>
<div id="footer"> © Jorik ter Molen & Camiel Collet, 2011.</div>
</body>
Around line 82 where you have the php check for the matching passwords, replace it with:
<?php
if(isset($_POST['r_submit'])){
if($confirm_r_password != $r_password)
{
echo "<td>Error: The passwords don't match!</td>";
}
}
?>
Although this is just a basic check and nothing secure since the user can leave both passwords empty and they still match.