I have been on this for hours on end. When I get one thing working something else doesn't work. Well now my page is not loading to the one it is suppose to. It is loading to the content page and not the form page.I have the home page in for the users to enter in there username and passowrd and if they dont have one then they can register on the form. I put all the forms on there. I don't know what I am doing wrong. Like I said I been working on this for hours. Can someone help me thanks.
Its not loading to the form it skips right over it to the content page. So if you click on register to the form you wont see it. It will go to the content page.
Here are my codes
This one is form page..
<?php
function FormDisplay($strMessage="**All fields are required!"){
echo "<p><strong>".$strMessage."</strong></p>\n";
echo "<form action=\"".$PHP_SELF."\" method=\"post\">\n";
echo "<table width=\"300\" cellpadding=\"2\" cellspacing=\"2\">\n";
echo "<tr>\n";
echo " <td><strong>Username:</strong></td>\n";
echo " <td><input type=\"text\" name=\"username\" value=\"". $_POST['username']."\"/> \n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>Password:</strong></td>\n";
echo " <td><input type=\"password\" name=\"password1\" />\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td nowrap=\"nowrap\"><strong>Repeat Password:</strong></td>\n";
echo " <td><input type=\"password\" name=\"password2\" /> \n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>First name:</strong></td>\n";
echo " <td><input type=\"text\" name=\"firstname\" value=\"". $_POST['firstname']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>Last name:</strong></td>\n";
echo " <td><input type=\"text\" name=\"lastname\" value=\"". $_POST['lastname']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>Email:</strong></td>\n";
echo " <td><input type=\"text\" name=\"email\" value=\"". $_POST['email']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>Address:</strong></td>\n";
echo " <td><input type=\"text\" name=\"address\" value=\"". $_POST['address']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>City:</strong></td>\n";
echo " <td><input type=\"text\" name=\"city\" value=\"". $_POST['city']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>State:</strong></td>\n";
echo " <td><input type=\"text\" name=\"state\" value=\"". $_POST['state']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>Zip:</strong></td>\n";
echo " <td><input type=\"text\" name=\"zip\" value=\"". $_POST['zip']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td><strong>Phone:</strong></td>\n";
echo " <td><input type=\"text\" name=\"phone\" value=\"". $_POST['phone']."\"/>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<tr>\n";
echo " <td> </td>\n";
echo " <td><input type=\"submit\" name=\"submit\" value=\"Sign up now!\". class=\"submit\" />\n";
echo "</tr>\n";
echo "<tr>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</form>\n";
}
if ($_POST['submit']!=""){
if ($_POST['username']==""||$_POST['password1']==""||$_POST['password2']==""||$_POST['firstname']==""||$_POST['lastname']==""||$_POST['address']==""||$_POST['email']==""||$_POST['city']==""||$_POST['state']==""||$_POST['zip']==""||$_POST['phone']=="");
$error=1;
}
else if ($_POST['password1']!=$_POST['password2']){
$error=2;
}
else{
$hostname="localhost";
$database="Contacts";
$mysql_login="Web_User";
$mysql_password="my1230";
if (!($db = mysql_connect($hostname, $mysql_login , $mysql_password))){
echo "error on connect";
}
else{
if (!(mysql_select_db($database,$db))){
echo mysql_error();
echo "<br>error on table connection";
}
else{
$SQL="Insert into tblUsers(username,password,firstname,lastname,email,address,city,state,zip, phone,signupDate)values)'".$_POST['username']."',PASSWORD('".$_POST['password1']."'),'".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['address']."','".$_POST['city']."','".$_POST['state']."','".$_POST['zip']."','".$_POST['phone']."',NOW())";
mysql_query($SQL);
if (is_numeric(mysql_insert_id())){
header("Location:member-content.php?name=".$_POST['username']);
}
else{
echo "Sorry, there was an error.Please try again ot contact the administrator";
}
mysql_close($db);//closeing out connection,done for now
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="style.css" type="text/css" >
<title>Members Only Framework::Signup page/title>
</head>
<body>
<hr />
<h2>Become a member of the coolest website on the net!</h2>
<hr />
<?php
if ($error==1){
FormDisplay("You did not enter all required fields");
}
elseif ($error==2){
FormDisplay("Your Passwords did not match");
}
else{
FormDisplay();
}
?>
</body>
</html>
This is the signin form:
<?php
include("config.php");
if ($_POST['username']==""|| $_POST['password']==""){
header("Location:member-home.php?mode=1");
}
else{
$hostname="localhost";
$database="contacts";
$mysql_login="Web_User";
$mysql_password="my1230";
if (!($db = mysql_connect($hostname, $mysql_login, $mysql_password))){
echo "error on connect";
}
else{
if (!(mysql_select_db($database,$db))){
echo mysql_error();
echo "<br>error on db connection";
}
}
$SQL="Select username from tblusers where username='".$_POST['username']."' AND password=PASSWORD('".$_POST['password']."')";
$resultSet=mysql_query($SQL);
if (mysql_num_rows($resultSet)>0){
$username=mysql_result($resultSet,0,"username");
header("Location:member-content.php?name=".$username);
}
else{
header("Location:member-home.php?mode=2");
}
}
?>
</body>
</html>
and this is the home:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" type="text/css">
<title>Members Only Framework::Login Page</title>
</head>
<body>
<hr />
<h3>Welcome Members!!</h3>
<hr />
<p>Not a member yet? Click here to join!</p>
<?php
if ($_GET['mode']==1){
echo "<p style=\"color:red;\"><strong>Please enter your username and password!</strong></p>";
}
else if ($_GET['mode']==2){
echo "<p style=\"color:red;\"><strong>Sorry, there is no user with that name!</strong></p>";
}
else if ($_GET['mode']==3){
$username=$_GET['username'];
echo "<p style=\"color:red;\"><strong>".$username.".please login using the username and password</strong></p>";
}
?>
<p>Current members enter your username and password:</p>
<form action="member-signin.php" method="post">
<table width="200" cellpadding="2" cellspacing="2">
<tr>
<td><strong>Username:</strong></td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td><strong>Password:</strong></td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Log in now!" class="submit" /></td>
</tr>
</table>
</form>
</body>
</html>
You have a misplaced semicolon in your member-form.php:
if ($_POST['username']==""||$_POST['password1']==""||$_POST['password2']==""||$_POST['firstname']==""||$_POST['lastname']==""||$_POST['address']==""||$_POST['email']==""||$_POST['city']==""||$_POST['state']==""||$_POST['zip']==""||$_POST['phone']=="");
so you need to replace it with opening curly bracket.
Related
I have a database table that I created from a .csv file. I used php to edit the content to match a new table on my database. I now need to INSERT that new table into the new database. I added form tags around the table and a submit button, and when I submit it I only get 1 or 2 random rows of the table. I am guessing that I might need a while or a for loop, but I cant figure out how to write it. Any assistance would be appreciated.
This is the code to post to the db
if(isset($_POST['submit'])){
$mr = $_POST['mr'];
$mrs = $_POST['mrs'];
$last_name = $_POST['last_name'];
$marital_status = $_POST['marital_status'];
$query = "INSERT INTO import_template(first_name, last_name, marital_status) VALUES('{$mr}', '{$last_name}', '{$marital_status}')";
$result = mysqli_query($connection, $query);
if(!$result){
die("QUERY FAILED " . mysqli_error($connection));
}
if(!$connection){
echo "We are NOT connected";
}
$query = "INSERT INTO import_template(first_name, last_name, marital_status) VALUES('{$mrs}', '{$last_name}', '{$marital_status}')";
$result = mysqli_query($connection, $query);
if(!$result){
die("QUERY FAILED " . mysqli_error($connection));
}
if(!$connection){
echo "We are NOT connected";
}
}
This is what the dynamic table looks like I only added the input to the first few to test, I haven't done the rest yet.
echo "<tr>";
echo "<td><input type='text' class='form-control' name='mr' value='$mr'></td>";
echo "<td><input type='text' class='form-control' name='last_name' value='$last_name'></td>";
echo "<td><input type='text' class='form-control' name='marital_status' value='$marital_status'></td>";
echo "<td>{$birthday}</td>";
echo "<td>Adult</td>";
echo "<td>{$anniversary}</td>";
echo "<td>{$mr_cell_phone}</td>";
echo "<td>{$home_phone}</td>";
echo "<td>{$mr_email}</td>";
echo "<td>{$street}</td>";
echo "<td>{$city}</td>";
echo "<td>{$state}</td>";
echo "<td>{$zip}</td>";
echo "<td></td>";
echo "</tr>";
echo "<tr>";
echo "<td><input type='text' class='form-control' name='mrs' value='$mrs'></td>";
echo "<td><input type='text' class='form-control' name='last_name' value='$last_name'></td>";
echo "<td><input type='text' class='form-control' name='marital_status' value='$marital_status'></td>";
echo "<td></td>";
echo "<td>Adult</td>";
echo "<td>{$anniversary}</td>";
echo "<td>{$mrs_cell_phone}</td>";
echo "<td></td>";
echo "<td>{$mrs_email}</td>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";
echo "</tr>";
You can do like this. I have taken three fields such as task,agent and note.You can add as per your table rows:
main.php
<form id="first" action="insert_values.php" method="post">
<table>
<tr>
<td>Task</td>
<td>
<input type="text" name="task">
</td>
</tr>
<tr>
<td>Agent</td>
<td>
<input type="text" name="agent">
</td>
</tr>
<tr>
<td>Note</td>
<td><input type="text" name="Note"></td>
</tr>
</table>
<input type="submit" value="save" name="save">
</form>
insert_values.php
<?php
error_reporting( error_reporting() & ~E_NOTICE );
session_start();
include 'connect.php';
$task=$_POST['task'];
$agent=$_POST['agent'];
$Note=$_POST['Note'];
$result=mysql_query("insert into table_name(task,agent,t_note) values('$task','$agent','$Note')");
if($result)
{
$msg="Insert Successfully!!";
echo "<script>alert('Insert Successfully');document.location='main.php'</script>";
?>
<?php
}
else
{
$errmsg=" Insert not success!!";
echo "<script>alert('Insert Not Successfully');document.location='main.php'</script>";
}
?>
I am making a simple attendance class system
I have this php code with radio buttons here.. now i put it in a table
I can only choose one radio button on the entire table instead of one radio button per registered account
<?php
session_start();
if(!isset($_SESSION["in"]))
{
header("Location: log.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Attendance</title>
</head>
<body>
<center>
<br />
<?php
echo "Today is " . date("m/d/Y") . "<br><br><br><br>";
?>
<?php
$conn= new mysqli("localhost", "root", "", "dbform");
$sql = "SELECT * FROM tblusers";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table width='1300' border='6'>
<tr>
<th width='100'>ID</th>
<th width='100'>Lastname</th>
<th width='100'>Firstname</th>
<th width='100'>Sex</th>
<th width='100'>Attendance</th>
</tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr> ";
echo "<td align='center'>2016" . $row['id'] . "</td>";
echo "<td align='center'>" . $row['lastname'] . "</td>";
echo "<td align='center'>" . $row['firstname'] . "</td>";
echo "<td align='center'>" . $row['sex'] . "</td>";
?>
<form method="post" action="Succes_Submit_Attendace.php" name="submit_attendance">
attendance =
<td align='center'> <label><input type="radio" name="attendance" value="present">Present</label>
<label><input type="radio" name="attendance" value="absent">Absent</label><br /><br />
<?php
$row['attendance'] ;
?> </td>
<?php
echo " </tr>";
}
echo "</table>";
}
else {
echo "0 results";
}
$conn->close();
?>
<br>
<br>
<input type="reset"> <input type="submit" value="Submit Attendance"></h4>
</form>
<div align="right">
<h3>Back</h2>
</div>
All the radio buttons are of same name so you need to group them by row id. Change the input type to below :
<label><input type="radio" name="attendance[<?php echo $row['id']; ?>]" value="present">Present</label>
<label><input type="radio" name="attendance[<?php echo $row['id']; ?>]" value="absent">Absent</label><br /> <br />
Also there are HTML errors in your code. Please fix them
<!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/
jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js">
</script>
<script>
$(document).ready(function() {
$(".datepicker").datepicker()
});
</script>
</head>
<body>
<?php
$status = $_POST['status'];
$driver_name= $_POST['driver_name'];
$from=date('y-m-d',strtotime($_POST['date_from']));
$to=date('y-m-d',strtotime($_POST['date_to']));
$conn = mysqli_connect('localhost', 'root', '', 'punbus') or
die("Database not connected" . mysqli_error());
if(isset($_POST['sub'])) {
foreach($status as $k=>$s){
$ins = "insert into driver_status(driver_name,status,date_from,date_to)
VALUES
('".$driver_name[$k]."','$s','".$from[$k]."','".$to[$k]."')";
$quer=mysqli_query($conn,$ins);
}
if($quer){
echo "Updated";
}else{
echo"NOT".mysqli_error($conn);
}
}
$sel = 'select Driver_name from driver_master';
$query = mysqli_query($conn, $sel);
echo "<form action='driver_status.php' method='post'>";
echo "<table cellpadding=5>";
echo "<tr>";
echo "<th>Driver Name</th>";
echo "<th>Status</th>";
echo "<th>From</th>";
echo "<th>To</th>";
echo "</tr>";
while($row=mysqli_fetch_assoc($query)){
echo "<tr><td>".$row['Driver_name']
."<input type=\"hidden\" name=\"driver_name[]\"
value=\"".$row['Driver_name']."\"/></td>";
$sel1='select d_status from status';
$query1=mysqli_query($conn,$sel1);
echo "<td><select name=\"status[]\">";
while($row1=mysqli_fetch_assoc($query1)){
echo "<option value=\"".$row1['d_status']."\">".$row1['d_status']."
</option>";
}
echo "</select></td>";
echo "<td>".'<input type="text" name="date_from[]" class="datepicker">'."</td>";
echo "<td>".'<input type="text" name="date_to[]" class="datepicker">'."</td>";
echo "</tr>";
}
echo "</table>";
echo '<input type="submit" name="sub" value="Update"/>';
echo "</form>";
?>
</body>
</html>
I want to store date to database from jquery datepicker. above is my code and error is Warning: strtotime() expects parameter 1 to be string, array given. Can i store date to database as array.Plz help.
Change Input name to :-
echo "<td>".'<input type="text" name="date_from" class="datepicker">'."</td>"; // remove []
echo "<td>".'<input type="text" name="date_to" class="datepicker">'."</td>"; // remove []
Use Dateformat like this
Try: date("Y-m-d") which uses the numeric equivalents.
#vove This is code-
<!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/
jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js">
</script>
<script>
$(document).ready(function() {
$(".datepicker").datepicker()
});
</script>
</head>
<body>
<?php
$status = $_POST['status'];
$driver_name= $_POST['driver_name'];
$from=date('y-m-d',strtotime($_POST['date_from']));
$to=date('y-m-d',strtotime($_POST['date_to']));
$conn = mysqli_connect('localhost', 'root', '', 'punbus') or
die("Database not connected" . mysqli_error());
if(isset($_POST['sub'])) {
$ins = "insert into driver_status(driver_name,status,date_from,date_to)
VALUES
('$driver_name','$s','$from','$to')";
$quer=mysqli_query($conn,$ins);
}
if($quer){
echo "Updated";
}else{
echo"NOT".mysqli_error($conn);
}
$sel = 'select Driver_name from driver_master';
$query = mysqli_query($conn, $sel);
echo "<form action='driver_status.php' method='post'>";
echo "<table cellpadding=5>";
echo "<tr>";
echo "<th>Driver Name</th>";
echo "<th>Status</th>";
echo "<th>From</th>";
echo "<th>To</th>";
echo "</tr>";
while($row=mysqli_fetch_assoc($query)){
echo "<tr><td>".$row['Driver_name']
."<input type=\"hidden\" name=\"driver_name\"
value=\"".$row['Driver_name']."\"/></td>";
$sel1='select d_status from status';
$query1=mysqli_query($conn,$sel1);
echo "<td><select name=\"status\">";
while($row1=mysqli_fetch_assoc($query1)){
echo "<option value=\"".$row1['d_status']."\">".$row1['d_status']."
</option>";
}
echo "</select></td>";
echo "<td>".'<input type="text" name="date_from" class="datepicker">'."</td>";
echo "<td>".'<input type="text" name="date_to" class="datepicker">'."</td>";
echo "</tr>";
}
echo "</table>";
echo '<input type="submit" name="sub" value="Update"/>';
echo "</form>";
?>
I am a fresher in PHP, I am trying to create a form which will be auto filled from the MySQL database. The form is getting created, and populated from the database data. But, in case the data contains a space in between, the characters after the space are not getting displayed.
The php page:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
// Check if we have parameters employeeId being passed to the script through the URL
if (isset($_GET["employeeId"])) {
$employeeId = $_GET["employeeId"];
//=============Data Display=================
$con=mysqli_connect("localhost","root","","employee_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT `employee_id` , `employee_name` , `employee_email` , `employee_mobile` , `employee_address`
FROM `employee_details`
WHERE `employee_id` =$employeeId");
echo "<h2>Edit Employee</h2><br/>
<form name='myForm' action='' onSubmit='return validateForm()' method='post'>";
while($row = mysqli_fetch_array($result))
{
echo "Employee Id: ". $row['employee_id'] ."<br/>";
echo "Employee Name: <input type='text' name='EmployeeName' value=". $row['employee_name'] ."><br/>";
echo "Employee Email: <input type='text' name='EmployeeEmail' value=". $row['employee_email'] ."><br/>";
echo "Employee Mobile: <input type='text' name='EmployeeMobile' value=". $row['employee_mobile'] ."><br/>";
echo "Employee Address: <Input type='text' name = 'product_name5' value=".$row['employee_address']."><br/>";
}
mysqli_close($con);
//=============Data Display=================
}
?>
</body>
</html>
Where am I going wrong? What should I do to get all the data including spaces in the textboxes?
Value attribute of inputs should be with quotes too:
value='" . $value . "'
In your case:
echo "Employee Name: <input type='text' name='EmployeeName' value='". $row['employee_name'] ."'><br/>";
echo "Employee Email: <input type='text' name='EmployeeEmail' value='". $row['employee_email'] ."'><br/>";
echo "Employee Mobile: <input type='text' name='EmployeeMobile' value='". $row['employee_mobile'] ."'><br/>";
echo "Employee Address: <Input type='text' name = 'product_name5' value='".$row['employee_address']."'><br/>";
If you are going to create link fetch from database like download link
use this type code
$result = mysqli_query($con,$sql);
//echo $ip."<br />";REGEXP
//echo $name."<br />";
echo "<table border=2px style='border-radius=20px;' align=center><tr>
<th>Document ID</th>
<th>Document Name Type</th>
<th>Download Documents</th>
</tr>";//<th>Project Document Type</th>
while($row = mysqli_fetch_array($result)) {
$path1=$row['FOLDERNAME'] .'/'. $row['FILENAME'] .'.'. $row['DOCTYPE'];
$path=str_replace(" ", '%20', $path1);
echo "<tr>";
echo "<td>" . $row['DocID'] . "</td>";
// echo "<td>" . $row['PROJDOCTYPE'] . "</td>";Thank you. Your Apple ID is now ready for use.
echo "<td>" . $row['DOCNAME'] . "</td>";
echo '<td><a href=Tender/'.$path.'>'.$row['DOCNAME'].'</a></td>';
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
Ok I am trying to get this form to where if someone skip something on the form it will come up and tell them. I am a newbie and I am not understanding on how to get that error to come up if someone dont enter the information. This is what I have
<?php
function showForm($strMessage){
echo "<h1>".$strMessage."</h1>";
echo " <p>Note: fields marked with '*' are required</p>\n";
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n";
echo "<table width=\"45%\" class=\"formtable\" cellpadding=\"3\" cellspacing=\"0\">\n";
echo " <tr>\n";
echo " <td><span id=\"rfvname\">* Name:</span></td>\n";
echo " <td><input type=\"text\" name=\"name\" value=\"".$_POST['name']."\" /></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td><span id=\"rfvemail\">* E-mail:</span></td>\n";
echo " <td><input type=\"text\" name=\"email\" value=\"".$_POST['emial']."\" /></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td><span id=\"rfvusername\">* Username:</span></td>\n";
echo " <td><input type=\"text\" name=\"username\" value=\"".$_POST['username']."\" /></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td><span id=\"rfvpword\">* Password:</span></td>\n";
echo " <td><input type=\"password\" name=\"pword\" value=\"".$_POST['pword']."\" /><br /><span style=\"font-size:9px;\"><em>(at least 4 chars) </em></span></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td><span id=\"rfvpword\">* Re-enter Password:</span></td>\n";
echo " <td><input type=\"text\" name=\"repword\" value=\"".$_POST['repword']."\" /></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td> </td>\n";
echo " <td><input type=\"submit\" value=\"Submit\" class=\"btnSubmit\" id=\"btnSubmit\" name=\"submit\" /></td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "</form>\n";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1 /DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Contact Form</title>
<style type="text/css">
body{
background-color:#FFBD40;
color:#000000;
font-size:100%;
font-family:Georgia,Verdana,"Times New Roman",sans-serif;
}
#container{
background:#FFF573;
width:800px;
margin:auto;
padding:5px 10px 5px 10px;
border:6px double #000000;
}
</style>
</head>
<body>
<div id="container">
<?php
if (isset($_POST['submit'])){
if (trim($_POST['name'])==""){
$strMessage="Please enter your name!";
showForm($strMessage);
}
elseif (strlen(trim($_POST['pword']))<=3){
$strMessage="Your password must be at least 4 characters long!";
showForm($strMessage);
}
else{
$strMessage="Thank you, your information has been submitted. Below is the information you sent:";
$strMessageBody.="Name: ".trim(stripslashes($_POST['name']))."<br />";
$strMessageBody.="E-mail: ".trim(stripslashes($_POST['email']))."<br />";
$strMessageBody.="UserName: ".trim(stripslashes($_POST['username']))."<br />";
$strMessageBody.="Password: ".trim(stripslashes($_POST['pword']))."<br />";
$strMessageBody.="Re-enter Password: ".trim(stripslashes($_POST['repword']))."<br />";
echo "<h1>".$strMessage."</h1>";
echo $strMessageBody;
}
}
else{
$strMessage= "Please fill out the form below to send your information:";
showForm($strMessage);
}
?>php
$$errors = array();
if (isset($_REQUEST["seen_already"])){
validate_data();
if(count($errors) ! = 0){
display_errors();
display_welcome();
} else {
display_welsome();
}
function validate_data()
{
global $errors;
if($_REQUEST["Name"]==""){
$errors[] = "<FONT COLOR='RED'>Please enter your first name</FONT>";
}
if($_REQUEST["E-mail"]==""){
$error[] = "<FONT COLOR='RED'>Please enter your E-Mail>/FONT>";
}
if($_REQUEST["UserName"]==""){
$errors[] = "<FONT COLOR='RED'>Please enter your Username</FONT>";
}
if($_REQUEST["Password"]==""){
$errors[] = "<FONT COLOR='RED'>Please enter your Password</FONT>";
}
if($_REQUEST["RE-enter Password"]==""){
$errors[] = "<FONT COLOR='RED'>Please re-enter your Password</FONT>";
}
}
function display_errors()
{
global $errors;
foreach($errors as $err){
echo $err, "<BR>";
}
}
function process_data()
</div>
</body>
</html>
Well the echo's and the " and \ is how I have to set this all up. So it is suppose to look like that. And all i am asking is if someone can help me understand how to do the error code. Not to do it for me but help me understand it. Is the code i already started on will it work or am I doing it all messed up. And thank to whoever is voting me down.I am just asking a simple question.
Your problem is this:
$_REQUEST["RE-enter Password"]
You used the textual label for the form fields. But your actual input field is called:
$_REQUEST["repword"]
Likewise for all the other fields. The $_REQUEST array holds the keys according to the name= attributes in the HTML form.
Something else: You can also simplify the form output. Instead of the many echos you should use a heredoc string to avoid the many " dquotes and \ backslash escapes:
echo <<<HTML
<h1>$strMessage</h1>
<p>Note: fields marked with '*' are required</p>
<form action="$_SERVER[PHP_SELF]" method="post">
<table ...
<td><span id="rfvname">* Name:</span></td>
<td><input type="text" name="name" value="$_POST[name]"></td>
...
HTML;
Also add $_POST = array_map("htmlentities", $_POST); before that (for simplicity/security).