Php if else yes/no - php

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

Related

There's a "1" at the left side of the site. I do not know where it came from

<form id="frmContact" method="POST" action="Pass2.php">
<p color="red" class="validate_msg"><font color="red">Please fix the errors below!</font></p>
<input type="hidden" name="id" value="<?php echo (isset($gresult) ? $gresult["id"] : ''); ?>" />
<table>
<tr>
<td>
<label for="regname">Applicant Name: </label><span class="val_regname"></span>
</td>
<td>
<input type="text" name="name"
value="<?php echo (isset($gresult) ? $gresult["name"] : ''); ?>"
id="name" class="txt-fld"/>
</td>
</tr>
<tr>
<td>
<label for="prices">prices: </label><span class="val_prices"></span>
</td>
<td>
<input type="text" name="prices"
value="<?php echo (isset($gresult) ? $gresult["prices"] : ''); ?>"
id="prices" class="txt-fld"/>
</td>
</tr>
<tr>
<td>
<label for="day">day #: </label><span class="val_day"></span>
</td>
<td>
<input type="text" name="day"
value="<?php echo (isset($gresult) ? $gresult["day"] : ''); ?>"
class="txt-fld"/>
</td>
</tr>
<tr>
<td>
<label for="slot">slot : </label><span class="val_slot"></span>
</td>
<td>
<input type="text" name="slot"
value="<?php echo (isset($gresult) ? $gresult["slot"] : ''); ?>"
class="txt-fld"/>
</td>
</tr>
<tr>
<td>
<label for="flag">Secondary School: </label><span class="val_flag"></span>
</td>
<td>
<input type="text" name="flag"
value="<?php echo (isset($gresult) ? $gresult["flag"] : ''); ?>"
class="txt-fld"/>
</td>
</tr>
</table>
<input type="hidden" name="action_type" value="<?php echo (isset($gresult) ? 'edit' : 'add');?>"/>
<div style="text-align: center; padding-top: 30px;">
<input class="btn" type="submit" name="save" id="save" value="Save" />
<input class="btn" type="submit" name="save" id="cancel" value="Cancel"
onclick=" return GotoHome();"/><br>
<br>
</div>
</form>
There's a "1" at the left side of the site. I do not know where it came from. The "1" only appear when I update. Can anyone help me find where the "1" came from?
You have likely put a 1 somewhere in your code outside of a PHP tag, or you have echo'd out a boolean value. First do a search through your own code for 1, otherwise look for any strings before <?php or random echo calls.

Why does my php 'else' displays both at once?

I have this php code which determines if the user has already voted or not.
$row_content['Vote_Who'] contains a list of all users who have previously voted, and is formatted like "User_1 User_2 User_3"
$_SESSION['Username'] is the current username of the user who is signed in. Yes this works, as I have called it elsewhere on the page.
<?php if(strpos($row_content['Vote_Who'], $_SESSION['Username']) !== false){?>
<input type="button" value="Thanks for voting!">
<?php }
else{ ?>
<input type="submit" value="<?php echo $row_content['Votes']?>: Vote Up! ▲" width="75px">
<input type="hidden" name="MM_update" value="vote">
<?php } ?>
But when I see the result in the web browser, both the buttons are displayed at once.
How can I fix that?
Thanks in advance.
UPDATE: Image that proves both buttons display at the same time
UPDATE:
Full code section:
<?php
if ($totalRows_content > 0){
do {?>
<table width="100%">
<tr>
<td width="75px" height="75px" align="right">
<img src="<?php echo $row_content['User_Pic']?>" width="50px" height="50px">
<br />
<?php echo $row_content['Author']?>
</td>
<td colspan="2">
<h2>
<?php echo $row_content['Title']?>
</h2>
</td>
</tr>
<tr>
<td>
</td>
<td style="vertical-align:top">
<h3>
<?php echo $row_content['Content']?>
<br />
<br />
</h3>
</td>
<td width="150px" style="vertical-align:top">
<img src="<?php echo $row_content['Picture']?>" style="max-width:150px; max-height:100px">
<h3>
<?php echo $row_content['Published']?>
</h3>
<br />
<?php if(isset ($_SESSION['Username'])){?>
<form method="POST" action="<?php echo $editFormAction; ?>" name="vote">
<input type="text" hidden="hidden" name="ID" value="<?php echo $row_content['ID']?>">
<input type="text" hidden="hidden" name="votes_up" value="<?php echo ($row_content['Votes'] + 1)?>">
<?php if(strpos($row_content['Vote_Who'], $_SESSION['Username']) !== false){?>
<input type="button" value="Thanks for voting!">
<?php }
else{ ?>
<input type="submit" value="<?php echo $row_content['Votes']?>: Vote Up! ▲" width="75px">
<input type="hidden" name="MM_update" value="vote">
<?php } ?>
</form>
<a href="comments.php?ID=<?php echo $row_content['ID']?>">
<input type="button" value="See Comments">
</a>
<?php }
else{?>
<?php echo $row_content['Votes']?> Votes - You must be signed in to vote
<?php }?>
</td>
</tr>
</table>
<?php }while ($row_content = mysql_fetch_assoc($content));}
else{?>
there is nothing
<?php }
?>
The problem was where I'd used the operator of
!==
when what I should have used was
!=
Example:
strpos($row_content['Vote_Who'], $_SESSION['Username']) != false
Thanks to everyone who offered assistance with this issue.

PHP - Codeigniter not all form elements being sent to controller by post method

I have a form like the code below, when the submit button is clicked, not all elements of the form being sent to Codeigniter's controller, especially txtStartLocation and txtEndLocation. I clearly defined the names for both elements.
Here what I got when var_dump the post element
array(8) {
["txtStartDate"]=> string(10) "2015-09-29"
["txtEndDate"]=> string(10) "2015-09-30"
["txtStartTime"]=> string(4) "8:45"
["txtEndTime"]=> string(5) "14:45"
["txtStartLocation_Coordinates"]=> string(32) "(36.106965, -112.11299700000001)"
["txtEndLocation_Coordinates"]=> string(23) "(37.559152, 126.983967)"
["txtTotalDetail"]=> string(1) "0"
["txtNoOfDays"]=> string(1) "2" }`
Form View
<form name="frm_RRequest" id="frm_RRequest" action="<?php echo site_url('user/add_recommendation_request/'); ?>" method="post">
<tbody>
<tr>
<td class="col-left">Date</td>
<td class="col-middle"><input class="datepicker" type="text" name="txtStartDate" id="txtStartDate" class="datepicker" placeholder="Click to select a start date.."></td>
<td class="col-middle"><input class="datepicker" type="text" name="txtEndDate" id="txtEndDate" class="datepicker" placeholder="Click to select a end date.."></td>
<td class="col-right"><div class="error" id="error_date"> </div></td>
</tr>
<tr>
<td class="col-left">Travel time</td>
<td class="col-middle"><input type="text" class="ptTimeSelect input" name="txtStartTime" id="txtStartTime" placeholder="Click to select start time.." data-default-time="false"></td>
<td class="col-middle"><input type="text" class="ptTimeSelect input" name="txtEndTime" id="txtEndTime" placeholder="Click to select end time.." data-default-time="false"></td>
<td class="col-right"><div class="error" id="error_time"> </div></td>
</tr>
<tr>
<td class="col-left">Location</td>
<td class="col-middle-2"><input type="text" class="inputWithImge" name="txtStartLocation" id="txtStartLocation" onmouseover="display_text(this)" placeholder="Click the icon to select a start point"/><img src="<?php echo base_url('assets/images/search_icon.png'); ?>" class="location-icon" title="Click to show map" name="location-icon_start" value="StartLocation"/></td>
<td class="col-middle-2"><input type="text" class="inputWithImge" name="txtEndLocation" id="txtEndLocation" onmouseover="display_text(this)" placeholder="Click the icon to select a end point"/><img src="<?php echo base_url('assets/images/search_icon.png'); ?>" class="location-icon" title="Click to show map" name="location-icon_end" value="EndLocation" /></td>
<td class="col-right"><div class="error" id="error_location"> </div></td>
</tr>
</tbody>
</table>
</div>
<input type="hidden" name="txtStartLocation_Coordinates" id="txtStartLocation_Coordinates">
<input type="hidden" name="txtEndLocation_Coordinates" id="txtEndLocation_Coordinates">
<div><input type="button" class="button" id="btnGo" name="btnGo" value="Input detail" /> <span> << click this button if the travel time and location(s) are different for each day</span></div>
<div id="detail">
</div>
<input type="hidden" name="txtTotalDetail" id="txtTotalDetail">
<input type="hidden" name="txtNoOfDays" id="txtNoOfDays">
<div> </div>
<div><input type="button" id="btn_SaveDetail" name="btn_SaveDetail" class="button" value="Save" /></div>
</form>
Try to use open/close form like this:
<?php echo form_open("controller/function"); ?>
<?php echo form_close(); ?>
then change
<input type="button" id="btn_SaveDetail" name="btn_SaveDetail" class="button" value="Save" />
into
<input type="submit" id="btn_SaveDetail" name="btn_SaveDetail" class="button" value="Save" />

Codeigniter post variable with empty value

I have nine text boxes wrapped in a form but when post to codeigniter controller, there are two specific text boxes have no value but they actually have.
Anyone encountered this issue before ? what is actually wrong ?
Form
<form name="frm_RRequest" id="frm_RRequest" action="<?php echo site_url('user/add_recommendation_request/'); ?>" method="post">
<tbody>
<tr>
<td class="col-left">Date</td>
<td class="col-middle"><input class="datepicker" type="text" name="txtStartDate" id="txtStartDate" class="datepicker" placeholder="Click to select a start date.."></td>
<td class="col-middle"><input class="datepicker" type="text" name="txtEndDate" id="txtEndDate" class="datepicker" placeholder="Click to select a end date.."></td>
<td class="col-right"><div class="error" id="error_date"> </div></td>
</tr>
<tr>
<td class="col-left">Travel time</td>
<td class="col-middle"><input type="text" class="ptTimeSelect input" name="txtStartTime" id="txtStartTime" placeholder="Click to select start time.." data-default-time="false"></td>
<td class="col-middle"><input type="text" class="ptTimeSelect input" name="txtEndTime" id="txtEndTime" placeholder="Click to select end time.." data-default-time="false"></td>
<td class="col-right"><div class="error" id="error_time"> </div></td>
</tr>
<tr>
<td class="col-left">Location</td>
<td class="col-middle-2"><input type="text" class="inputWithImge" name="txtStartLocation" id="txtStartLocation" onmouseover="display_text(this)" placeholder="Click the icon to select a start point"/><img src="<?php echo base_url('assets/images/search_icon.png'); ?>" class="location-icon" title="Click to show map" name="location-icon_start" value="StartLocation"/></td>
<td class="col-middle-2"><input type="text" class="inputWithImge" name="txtEndLocation" id="txtEndLocation" onmouseover="display_text(this)" placeholder="Click the icon to select a end point"/><img src="<?php echo base_url('assets/images/search_icon.png'); ?>" class="location-icon" title="Click to show map" name="location-icon_end" value="EndLocation" /></td>
<td class="col-right"><div class="error" id="error_location"> </div></td>
</tr>
<input type="hidden" name="txtStartLocation_Coordinates" id="txtStartLocation_Coordinates">
<input type="hidden" name="txtEndLocation_Coordinates" id="txtEndLocation_Coordinates">
</tbody>
</table>
</div>
<div><input type="button" class="button" id="btnGo" name="btnGo" value="Input detail" /> <span> << click this button if the travel time and location(s) are different for each day</span></div>
<div id="detail">
</div>
<input type="hidden" name="txtTotalDetail" id="txtTotalDetail">
<input type="hidden" name="txtNoOfDays" id="txtNoOfDays">
<div> </div>
<div><input type="button" id="btn_SaveDetail" name="btn_SaveDetail" class="button" value="Save" /></div>
</form>
<script>
function display_text(obj){
var value = obj.value;
obj.title = value;
}
</script>
Controller :
$total_detail = $this->input->post("txtTotalDetail");
$noOfDays = $this->input->post("txtNoOfDays");
$userid = $this->session->userdata('id');
$start_date = $this->input->post("txtStartDate");
$end_date = $this->input->post("txtEndDate");
$start_time = $this->input->post("txtStartTime");
$end_time = $this->input->post("txtEndTime");
$start_location = $this->input->post("txtStartLocation");
$end_location = $this->input->post("txtEndLocation");
$start_location_coor = $this->input->post("txtStartLocation_Coordinates");
$end_location_coor = $this->input->post("txtEndLocation_Coordinates");
These two text boxes have no value :
$start_location = $this->input->post("txtStartLocation");
$end_location = $this->input->post("txtEndLocation");
It is possible you forgot to use $this->form_validation->set_rules() on those particular fields.
Put value in your input tag like
<input type="hidden" name="txtStartLocation_Coordinates" value ="<?php echo $this->input->post('txtStartLocation_Coordinates');?>" id="txtStartLocation_Coordinates">
<input type="hidden" name="txtEndLocation_Coordinates" value ="<?php echo $this->input->post('txtEndLocation_Coordinates');?>" id="txtEndLocation_Coordinates">
<script>
$(function(){
$('#txtStartLocation_Coordinates').val("your value");
$('#txtEndLocation_Coordinates').val("your value");
});
</script>

Error when trying to fill in registration fields

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.

Categories