How to give id to the TinyMCE Editor - php

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.

Related

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 >

Creating dynamic table using PHP

I'm trying to create a dynamic table using PHP but what I get is in each column of my table the array goes to the end and the next column is staring from the 0 to the end.
I tried to put if conditions and do some tricks to fix it but I couldn't.
this is the result I get for below code :
<?php
$query_formsearch = mysqli_query($con,"SELECT * FROM `forms` ");
$query_usr_prvlg = mysqli_query($con,"SELECT * FROM `profile` WHERE `id`='{$_SESSION["usr_id"]}' ");
$usr_access=mysqli_fetch_assoc($query_usr_prvlg);
$count=mysqli_num_rows($query_formsearch);
$i=0;
?>
<form action="" method="POST">
<table>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<?php while($forms_row = mysqli_fetch_assoc($query_formsearch))
{
$f_num="form_".$forms_row['num'];
?>
<tr>
<td>
<?php if(($usr_access[$f_num]=="1-1") || ($usr_access[$f_num]=="1-0")) ?>
<input class='styled-input_m' type="hidden" id="form-name" name ="form-name" value="<?php echo $forms_row['num']; ?>" />
<input class='styled-input_m' type="submit" id="sbmt-btn" name ="sbmt-btn" value="<?php echo $forms_row['name']; ?>" />
</td>
<td>
<?php if(($usr_access[$f_num]=="1-1") || ($usr_access[$f_num]=="1-0")) ?>
<input class='styled-input_m' type="hidden" id="form-name" name ="form-name" value="<?php echo $forms_row['num']; ?>" />
<input class='styled-input_m' type="submit" id="sbmt-btn" name ="sbmt-btn" value="<?php echo $forms_row['name']; ?>" />
</td>
<td>
<?php if(($usr_access[$f_num]=="1-1") || ($usr_access[$f_num]=="1-0")) ?>
<input class='styled-input_m' type="hidden" id="form-name" name ="form-name" value="<?php echo $forms_row['num']; ?>" />
<input class='styled-input_m' type="submit" id="sbmt-btn" name ="sbmt-btn" value="<?php echo $forms_row['name']; ?>" />
</td>
</tr>
<?php
}
?>
</table>
</form>

Pass multiple values of same data field through POST

I'm trying to pass multiple values from same parameters of a form using POST, but can't figure out how to proceed. I've used bootstrap css such that I can add multiple products. And I want to process the data of multiple orders by passing the values using POST method.
On clicking 'Add another' link, additional set of data field appear which enables recording of multiple transactions of a same user.
The code is as follows:
<div class="col-xs-5 col-lg-offset-3">
<form action="billingProceed.php" method="post" role="form">
<table id="itemElement">
<tr>
<td>
<select class="form-control">
<option class="form-control"> Customer Name</option>
<option class="form-control"> Customer ID</option>
</select>
</td>
<td><input type="text" name="<?php echo $data["name"]; ?>" class="form-control" /></td>
</tr>
<tr>
<td>
<select class="form-control">
<option class="form-control"> Item Name</option>
<option class="form-control"> Item ID</option>
</select>
</td>
<td ><input type="text" name="<?php echo $data["item"]; ?>" class="form-control" /></td>
</tr>
<tr>
<td style="float:right;">Quantity
</td>
<td><input type="text" name="<?php echo $data["quantity"]; ?>" class="form-control" /></td>
</tr>
<tr>
<td style="float:right;">Price
</td>
<td><input type="text" name="<?php echo $data["price"]; ?>" class="form-control" /></td>
</tr>
<tr>
<td style="float:right;">Discount
</td>
<td><input type="text" name="<?php echo $data["discount"]; ?>" class="form-control" /></td>
</tr>
</table>
<input type="submit" value="Proceed" class="btn btn-primary" />
<p style="float:right;">Add another</p>
You can use an array name.
Example:
<input name="data['name'][1]">
<input name="data['name'][2]">
Firstly you should be aware of the name array, for input names.
HTML Example:
<form>
<a id="add_another" href="#">Add Another</a>
<table>
<tr class="product_item">
<td>
<input type="text" name="product[1][name]" value=""/>
</td>
<td>
<input type="text" name="product[1][item]" value=""/>
</td>
</tr>
<tr id="dummy">
<td>
<input type="text" name="product[0][name]" value=""/>
</td>
<td>
<input type="text" name="product[0][item]" value=""/>
</td>
</tr>
</table>
</form>
On POST, in your PHP script, you will access them as follows:
foreach($_POST['product'] as $product)
{
$name = $product['name'];
$item = $product['item'];
}
Shoot for the JS
//You'll always start with one product row.
var productCount = 1;
$('#add_another').click(function() {
var dummyproduct = $('#dummy').clone();
//Increment Product count
productCount += 1;
//Rename all inputs
dummyproduct.find('input[name^="product[0]"]').each(function(){
$(this).attr('name',$(this).attr('name').replace('product[0]','product['+productCount +']'));
});
//Remove Id from cloned dummy
dummyproduct.removeAttr('id').addClass('product_item');
//Insert row before Dummy
dummyproduct.insertBefore('#dummy');
});

PHP Use select value to search and display result to textbox

My Selectbox Items from aircraft table
<select name="selectaircraft">
<option id="0">-- Select Aircraft -- </option>
<?php
require("dbc.php");
$getallaircraft = mysql_query("SELECT * FROM aircrafttable");
while($viewallaircraft = mysql_fetch_array($getallaircraft)){
?>
<option id="<?php echo $viewallaircraft['ID']; ?>">
<?php echo $viewallaircraft['aircraft'] ?> </option>
<?php } ?>
</select>
hi guys im trying to use the the value of selectaircraft to search and display the result to textbox.. here is my code so far
<?php
require("dbc.php");
$getallconfig = mysql_query("SELECT * FROM aircrafttable WHERE aircraft LIKE 'PR200'");
while($viewallconfig= mysql_fetch_array($getallconfig)){
?>
<input type="text" name="aconfig "value="<?php echo $viewallconfig['config']; ?>" />
<?php } ?>
As you can see, I only put PR200 to search, my question is how can i use the select value instead? I also want the search query to happen everytime i click the select box.
guys can some1 help me? i know how to code this in VB6 it will be like this
assume : select name or in VB6 combobox = selectbox
Private Sub Combo3_Click()
adodc1.recorsource ="Select * from aircrafttable where aircraft = " & selectbox & "'"
adodc1.refresh
Text1.Text = Adodc1.Recordset("aircraft")
everytime i click combo/selectbox the query will perform and give different answer to textbox.
i dont know how to do this in PHP pls help!
Edited Added all codes
<form action="addrecord.php" method="post" >
<table border=1>
<tr><td bgcolor="#999999">
<strong>Area:</strong> </td>
<td>
<input type="text" required="required" name="aarea" size=10 /><br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Aircraft:</strong></td>
<td>
<form method="post" action="aircraft.php">
<select name="selectaircraft" onchange="this.form.submit();">
<option id="0">Aircraft</option>
<?php
require("dbc.php");
$getallaircraft = mysql_query("SELECT * FROM aircrafttable");
while($viewallaircraft = mysql_fetch_array($getallaircraft)){
?>
<option id="<?php echo $viewallaircraft['ID']; ?>">
<?php
echo $viewallaircraft['aircraft'] ?> </option>
<?php } ?>
</select>
<?php
require("dbc.php");
if(isset($_POST)){
$takeaircraft = mysql_real_escape_string($_POST['selectaircraft']);
{
?>
<input type="text" name="aaircraft" size=3 value="<?php echo $takeaircraft; ?>" />
<?php }
}?>
</form>
</td></tr>
<tr><td bgcolor="#999999">
<strong>Flight:</strong> </td>
<td><input type="text" name="aflight" size=10 /><br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Configuration:</strong> </td>
<td>
<?php
require("dbc.php");
if(isset($_POST)){
$selectaircraft = mysql_real_escape_string($_POST['selectaircraft']);
$getallconfig = mysql_query("SELECT * FROM aircrafttable WHERE aircraft LIKE '".$selectaircraft."'");
while($viewallconfig= mysql_fetch_array($getallconfig)){
?>
<input type="text" name="aconfig" value="<?php echo $viewallconfig['config']; ?>" />
<?php }
}?>
<br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Month:</strong> </td>
<td>
<select name="amonth">
<option value="na">Month</option>
<option value="January">January</option>
</select>
</td></tr>
<tr><td bgcolor="#999999">
<strong>Frequency:</strong> </td>
<td><span style="font-size:11px; font-weight:bolder" >
Mon<input type="checkbox" id='check1' onClick='checkmon()'>
<input type="hidden" id="txt1" name="hiddenmon" value="n/a">
Tue<input type="checkbox" id='check2' onClick='checktue()'>
<input type="hidden" id="txt2" name="hiddentue" value="n/a">
Wed<input type="checkbox" id='check3' onClick='checkwed()'>
<input type="hidden" id="txt3" name="hiddenwed" value="n/a">
Thu<input type="checkbox" id='check4' onClick='checkthu()'>
<input type="hidden" id="txt4" name="hiddenthu" value="n/a">
Fri<input type="checkbox" id='check5' onClick='checkfri()'>
<input type="hidden" id="txt5" name="hiddenfri" value="n/a">
Sat<input type="checkbox" id='check6' onClick='checksat()'>
<input type="hidden" id="txt6" name="hiddensat" value="n/a">
Sun<input type="checkbox" id='check7' onClick='checksun()'>
<input type="hidden" id="txt7" name="hiddensun" value="n/a">
</span>
<br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Menu:</strong> </td>
<td><input type="text" name="amenu" size=10 /><br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Cycle:</strong> </td>
<td>
<select name="acycle">
<option value="na">Cycle</option>
<option value="Cycle 1">Cycle 1</option>
</select>
<tr><td bgcolor="#999999">
<strong>Items:</strong> </td>
<td>
<select name="aitem">
<option value="na">Items</option>
</select>
<tr><td bgcolor="#999999">
<strong>STD Time:</strong> </td>
<td><input type="text" name="astdtime" size=5 /><br /></td></tr>
<tr><td bgcolor="#999999">
<strong>Quantity:</strong> </td>
<td><input type="text" name="aqty" size=5 /><br /></td></tr>
<tr>
<td colspan="2" align="right" bgcolor="#999999">
<input type='submit' name="add" value="Add Records" />
</td>
</tr>
</table>
</form>
trigger submit on change of select box as below
<form action="path/to/your/query/file.php" method="post"> //if query in same page leave your action blank
<select name="selectaircraft" onchange="this.form.submi();">
<option id="0">-- Select Aircraft -- </option>
<?php
require("dbc.php");
$selected_aircraft=isset($_POST['selectaircraft'])?$_POST['selectaircraft']:"";
$getallaircraft = mysql_query("SELECT * FROM aircrafttable");
while($viewallaircraft = mysql_fetch_array($getallaircraft)){
$selectstr="";
if($selected_aircraft==$viewallaircraft['aircraft'] ){
$selectstr="selected='selected'";
}
?>
<option id="<?php echo $viewallaircraft['ID']; ?>" <?php echo $selectstr ?> >
<?php
echo $viewallaircraft['aircraft'] ?> </option>
<?php } ?>
</select>
</form>
and change you query as below:
<?php
require("dbc.php");
if(isset($_POST)){
$selectaircraft = mysql_real_escape_string($_POST['selectaircraft']);
$getallconfig = mysql_query("SELECT * FROM aircrafttable WHERE aircraft LIKE '{ $selectaircraft}'");
while($viewallconfig= mysql_fetch_array($getallconfig)){
?>
<input type="text" name="aconfig "value="<?php echo $viewallconfig['config']; ?>" />
<?php }
}?>
Update updated code to maintain state of select box.
Try like this;
$aircraft = mysql_real_escape_string($_POST['selectaircraft']); //or $_GET
$getallconfig = mysql_query("SELECT * FROM aircrafttable WHERE aircraft LIKE '".$aircraft."'");
You can keep the select box(1st) inside a form , on change submit the form to the next page .
And get the POST/GET value , and use it for select query for searching.

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