Error when trying to fill in registration fields - php

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.

Related

Php if else yes/no

am trying to add a function to a script where a user is ask for code, which i have added. but having one issue of i want to unable when to ask the user code and when to to ask .
so i need a php if else and it sql
so when i unable to ask code for a user it will ask code and when i disable it wont ask code
below is the one i have tried
if ((['yes'])) {
// Yes
<div id="cot_div" align="center">
<p>Please enter your <strong id="code_up">COT</strong> code to continue</p>
<form id="form3" name="form3" method="POST" action="inter_suc.php">
<table border="0" id="trans" align="center" >
<tr>
<td align="center" style="padding:0px"><span id="sprytextfield1">
<input name="cot" type="text" id="cot" size="10" />
<span class="textfieldRequiredMsg"></span></span>
<span id="sprytextfield2">
<input name="tax" type="text" id="tax" size="10" />
<span class="textfieldRequiredMsg"></span></span>
<span id="sprytextfield3">
<input name="imf" type="text" id="imf" size="10" />
<span class="textfieldRequiredMsg"></span></span><br /> <span id="error">
wrong COT Code</span>
</td>
</tr>
<tr>
<td align="center" style="padding:0px"><input type="button" name="go" id="go" value="Go" />
<input type="button" name="go2" id="go2" value="GO" />
<input type="button" name="go3" id="go3" value="GO" />
</td>
</tr>
} else {
// No
<div id="cot_div" align="center">
<p>Please enter your <strong id="code_up">COT</strong> code to continue</p>
<form id="form3" name="form3" method="POST" action="inter_suc.php">
<table border="0" id="trans" align="center" >
<tr>
<td align="center" style="padding:0px"><span id="sprytextfield1">
<input name="cot" type="hidden" id="cot" value="<?php echo $_POST['cot'];?>" />
<span class="textfieldRequiredMsg"></span></span>
<span id="sprytextfield2">
<input name="tax" type="hidden" id="tax" value="<?php echo $_POST['tax'];?>" />
<span class="textfieldRequiredMsg"></span></span>
<span id="sprytextfield3">
<input name="imf" type="hidden" id="imf" value="<?php echo $_POST['imf'];?>" />
<span class="textfieldRequiredMsg"></span></span><br /> <span id="error">
wrong COT Code</span>
</td>
</tr>
<tr>
<td align="center" style="padding:0px"><input type="button" name="go" id="go" value="Go" />
<input type="button" name="go2" id="go2" value="GO" />
<input type="button" name="go3" id="go3" value="GO" />
</td>
</tr>
}
You mean something like this?
.error {
display: none
}
<?php
$yes = $_GET["yes"] == "yes"; ?>
<div id="cot_div" align="center">
<p>Please enter your <strong id="code_up">COT</strong> code to continue</p>
<form id="form3" name="form3" method="POST" action="inter_suc.php">
<table border="0" id="trans" align="center">
<tr>
<td align="center" style="padding:0px">
<span id="sprytextfield1"><input name="cot" type="<?php echo $yes ? "text" : "hidden"; ?>" id="cot" size="10" /></span>
<span class="textfieldRequiredMsg"></span>
<span id="sprytextfield2"><input name="tax" type="<?php echo $yes ? "text" : "hidden"; ?>" id="tax" size="10" /></span>
<span class="textfieldRequiredMsg"></span>
<span id="sprytextfield3"><input name="imf" type="<?php echo $yes ? "text" : "hidden"; ?>" id="imf" size="10" /></span>
<span class="textfieldRequiredMsg"></span><br />
<span id="error">wrong COT Code</span>
</td>
</tr>
<tr>
<td align="center" style="padding:0px">
<input type="button" name="go" id="go" value="Go" />
<input type="button" name="go2" id="go2" value="GO" />
<input type="button" name="go3" id="go3" value="GO" />
</td>
</tr>
</table>
</div>
Ιf I understand your answered correct, than you want to display a specific HTML part if a given variable in php is 'yes'. Otherwise you want to show a different part of the HTML.
Then you can use this syntax:
<?php if ($val == 'YES'): ?>
<!-- Yes part -->
<?php else: ?>
<!-- No part -->
<?php endif; ?>
Hello guys thank for your help i thin i get it
<?php if ($yes = $_GET["yes"] == "yes"): ?>
html code to run if condition is empty
<?php else: ?>
html code to run if condition is yes
<?php endif ?>
if the == "yes" is yes it show yes condition but if empty it show the empty part

Variable in URL in from Action

<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>

set_value does not work on input type file on HMVC Codeigniter

I am using HMVC Codeigniter pattern for my project. And In my project I need to set the value on form where input type of field is file.So, I feel greatful for them who help me to solve out this problem.
My associate controller is apply.php
<?php
class Career extends Controller{
function __construct(){
parent::__construct();
$this->load->Model('career_model','',TRUE);
$this->load->model('welcome/Mwelcome','',TRUE);
//session_start();
}
finction index(){
redirect('career/apply');
}
function apply(){
$this->load->library('form_validation');
$this->load->helper('url');
$this->form_validation->set_rules('fname','First Name','required|trim');
$this->form_validation->set_rules('mname','Middle Name','required|trim');
$this->form_validation->set_rules('lname','Last Name','required|trim');
$this->form_validation->set_rules('date','Date','required|trim');
$this->form_validation->set_rules('pAddress','Permanent Address','required|trim');
$this->form_validation->set_rules('cAddress','Contact Address','required|trim');
$this->form_validation->set_rules('gender','Gender','required|trim');
if (empty($_FILES['cv']['name']))
{
$this->form_validation->set_rules('cv', 'Attach Your CV', 'required');
}
if($this->form_validation->run($this)){
$_SESSION['msg']="Your form has been submitted succesfully!!";
redirect('career/apply');
}
else
{
$_SESSION['err']="Opp! There was some wrong to fill up a form so try again!!!";
redirect('career/apply');
}
}
$data=array('body'=>'apply');
$data['pgtitle']='Apply';
$this->load->view('temp',$data);
}
}
My associate view file is apply.php
<form action="<?php echo site_url()?>career/apply" method="post" enctype="multipart/form-data" onsubmit="return confirm('Do you really want to submit the form?');">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="">Name</td>
<td width="158"><label for="fname"></label>
<input type="text" name="fname" id="fname" placeholder="First Name" class='input-row' value="<?php echo set_value('fname')?>"/><span class="required"><?php echo form_error('fname');?></span></td>
<td width="158"><label for="mname"></label>
<input type="text" name="mname" id="mname" placeholder="Middle Name" class='input-row' value="<?php echo set_value('mname')?>"/></td>
<td width="158"><label for="lname"></label>
<input type="text" name="lname" id="lname" placeholder="Last Name" class='input-row' value="<?php echo set_value('lname')?>"/><span class="required"><?php echo form_error('lname');?></span></td>
</tr>
<tr>
<td>Date of Birth</td>
<td width="158"><label for="date"></label>
<input type="text" name="date" id="date" class='input-row' value="<?php echo set_value('date')?>" placeholder="yyyy-mm-dd"/><span class="required"><?php echo form_error('date');?></span></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Gender</td>
<td><div class="customSel">
<label>
<select name="gender" id="select" class='input-row' value="">
<option value="Female"<?php echo set_select('gender', 'Female', TRUE); ?>>Female</option>
<option value="Male"<?php echo set_select('gender', 'Male', TRUE); ?>>Male</option>
<option value="Please Selection"<?php echo set_select('gender', 'Please Selection', TRUE); ?>>Please Selection</option>
<?php /*?><option value="Other"<?php echo set_select('gender', 'Other', TRUE); ?>>Other</option><?php */?>
</select></label></div><span class="error"><?php echo form_error('gender')?></span></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Address</td>
<td><label for="pAddress"></label>
<input type="text" name="pAddress" id="pAddress" placeholder="Permanent Address" class='input-row' value="<?php echo set_value('pAddress')?>"/><span class="required"><?php echo form_error('pAddress');?></span></td>
<td><label for="cAddress"></label>
<input type="text" name="cAddress" id="cAddress" placeholder="Contact Address" value="<?php echo set_value('cAddress')?>"/><span class="required"><?php echo form_error('cAddress');?></span></td>
<td> </td>
</tr>
<tr>
<td>Attach Your CV</td>
<td colspan="2"><label for="cv"></label>
<input type="file" name="cv" id="cv" value="<?php echo set_value('cv')?>"/><span class="error"><?php echo form_error('cv')?></span></td>
</tr>
<tr>
<td><input type="submit" name="submit" id="submit" value="Submit" class="Button" />
<input type="reset" name="reset" id="reset" value="Reset" class="Button" /></td>
<td> </td>
<td> </td>
</tr>
</table>
</form >

accessing the user profile by clicking a link

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

How to give id to the TinyMCE Editor

I am trying to develop an application in which "When I select option from dropdown the below fields should fill automatically(One is text field and other is TinyMCE Esitor)".
Below is the code I tried.
<?php
defined('_JEXEC') or die('Restricted access');
?>
<script type="text/javascript">
function showTemplate()
{
document.getElementById("jform_page_title").value = document.getElementById("jform").value;
alert("clicked");
}
</script>
<form action="" method="post" name="adminForm" id="adminForm">
<table class="admintable">
<tbody>
<tr>
<td>
<label for="jformid"><?php echo JText::_('JTAG_LEGAL_PAGES_CHOOSE_TEMPLATE');?>
</label>
</td>
<td>
<select id="jform" onchange="showTemplate()">
<?php foreach($this->templates as $template): //print_r($template);exit; ?>
<option value="<?php echo $template->id; ?>"> <?php echo $template->template_title; ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr></tr>
<tr>
<td>
<label for="jform_page_title"><?php echo JText::_('JTAG_LEGAL_PAGES_TEMPLATE_TITLE'); ?></label>
</td>
<td>
<input type="text" size="30" class="inputbox required" id="jform_page_title" value="<?php echo $this->template->template_title; ?>" name="jform[page_title]" />
</td>
</tr>
<tr></tr>
<tr>
<td>
<label for="jform_description"><?php echo JText::_('JTAG_LEGAL_PAGES_TEMPLATE_DESCRIPTION'); ?></label>
</td>
<td>
<?php
$editor =& JFactory::getEditor();
echo $editor->display('jform[description]', htmlspecialchars($this->lpsettingdata->description, ENT_QUOTES),'550','300','60','20',array('pagebreak','readmore'));
?>
</td>
</tr>
</tbody>
</table>
<input type="hidden" value="<?php echo $this->lpsettingdata->id; ?>" name="jform[id]" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="controller" value="jtaglegalpages" />
</form>
Please let me know how to give id to the editor.

Categories