about contact form - php

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

Related

Getting no matching results for query mysql php [duplicate]

This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 7 years ago.
I am trying to find matching results to my query in my database and put it in the table form I made, however I get no matching results back. I ran my query in phpmyadmin and got the desired output. I used var_dump on my $result variable and get the following: resource(4) of type (mysql result). here is my code:
<?php
function renderSearchForm($search, $search_by, $search_by, $error){
?>
<!DOCTYPE HTML5>
<head>
<title>Search Query</title>
</head>
<body>
<?php
//display errors
if($error != ''){
echo '<div style="padding:4px; border:1px solid red; color:red;">' . $error . '</div>';
}
?>
<form action="" method="post">
<div>
<p>Search For:</p>
<strong>Name: *</strong> <input type="text" name="search" value="<?php echo $search; ?>" /><br/>
<p>Search by:</p>
<input type="radio" name="search_by"
<?php if (isset($search_by) && $search_by=="firstname") echo "checked";?>
value="firstname"/>Firstname*
<input type="radio" name="search_by"
<?php if (isset($search_by) && $search_by=="surname") echo "checked";?>
value="surname"/>Surname*
<br><br>
<input type="submit" name="submit" value="Submit">
<p>* required</p>
</div>
</form>
</body>
</html>
<?php
}
//connect to db
include('connect_db.php');
//check if submitted
if (isset($_POST['submit'])) {
$search = mysql_real_escape_string(htmlspecialchars($_POST['search']));
$search_by = mysql_real_escape_string(htmlspecialchars($_POST['search_by']));
//check if search is empty
if (empty($_POST["search"])) {
$error = "Error: Name is required";
//error, display form
renderSearchForm($search, $search_by, $search_by, $error);
}
elseif
// check if name only contains letters and whitespace
(!preg_match("/^[a-zA-Z ]*$/",$search)) {
$error = "Error: Only letters and white space allowed";
//error, display form
renderSearchForm($search, $search_by, $search_by, $error);
}
//check if radio button selected
elseif (empty($_POST["search_by"])) {
$error = "Error: Search_by is required";
//error, display form
renderSearchForm($search, $search_by, $search_by, $error);
}else{
//save data
$query = "SELECT * FROM members WHERE '$search_by' LIKE '%$search%'";
$result = mysql_query($query)
or die(mysql_error());
var_dump($result);
//display data from db
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>Firstname</th> <th>Surname</th> <th>Telephone</th> <th>Cell</th> <th>Address</th> <th></th> <th></th> </tr>";
//loop through results of db and display in table
while ($row = mysql_fetch_array($result)) {
//echo contents in table
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['surname'] . "</td>";
echo "<td>" . $row['telephone'] . "</td>";
echo "<td>" . $row['cellphone'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td><a href='edit.php?id=" . $row['id'] . "'>Edit</a></td>";
echo "<td><a href='delete.php?id=" . $row['id'] . "'>Delete</a></td>";
echo "</tr>";
}
echo "</table>";
//This counts the number or results
$anymatches=mysql_num_rows($result);
if ($anymatches == 0) {
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
//And we remind them what they searched for
echo "<b>Searched For:</b> " .$search. "<b> In: </b>" .$search_by;
}
}else{
//if form not submitted, display form
renderSearchForm('','','','');
}
?>
You need to remove the single quotes between $search_by. Try this:
"SELECT * FROM members WHERE $search_by LIKE '%$search%'"

Characters not displaying after space form MySQL resultset

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

MySQLi Update Record via Form loaded from PHP and SQL. Database wont update

I am required to create a drop down box which gathers the records from a database to populate the drop down. When one of the values is selected, a form is to be displayed which contains the data relating to the value selected.
The form is to have the function of showing the selected data, but also to update the record in the database when filled out and Submit.
I have created a php file to try and accomplish this, but Im getting errors such as undefined index and unknown column.
I am only new to PHP so this is a big task for me. Could someone have a look at my code and inform me if there are any errors.
Ive been trying to piece code together here and there from the net but its been tricky trying to get it all to work.
I am not getting any errors now after some tweaking, but the record wont update. I get a 'record updated successfully' message but the record isn't updated.
I am pretty sure the lack of a record update is coming down to the ID not getting collected properly via the $q=$row["BearId"] but if I use $q=$_GET["q"] I get nothing but errors. I am not completely positive this is the problem though, that is why Im asking the question here.
I would appreciate any help that you can give. Ive gotten so far with this thing and yet I cant get it to update the record.
EDIT: I have pinpointed the problem down to the id in
$sql = "UPDATE //snip WHERE BearId = '$q'";
$q=$row["BearId"];
If I manually change BearId to equal '1' then the record is updated.
updatebears.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>Update Bears</title>
<script>
function showUser(str)
{
if (str=="")
{
document.getElementById("result").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("result").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getvalues.php?q="+str,true);
xmlhttp.send();
}
</script>
<style>
// style elements
</style>
</head>
<body>
<h1>Update Bears</h1>
Select a Bear:
<br />
<select name="bears" onchange="showUser(this.value)">
<option value="">Select a BearId</option>
<?php
$query = "SELECT * FROM bears";
$mysqli = new mysqli('localhost','User','123','bears');
$result = $mysqli->query($query);
while($row = $result->fetch_assoc())
echo '<option value="'.$row["BearId"].'">'.$row["BearId"].'</option>';
?>
</select>
<br />
<?php
$q=$row["BearId"];
$mysqli = new mysqli('localhost','User','123','bears');
$sql = "SELECT * FROM bears WHERE BearId='".$q."'";
if(array_key_exists('_submit_check', $_POST))
{
$weight = $_POST['Weight'];
$sex = $_POST['Sex'];
$type = $_POST['Type'];
$colour = $_POST['Colour'];
$breed = $_POST['BreedId'];
$sql = "UPDATE bears SET Weight = '$weight', Sex = '$sex', Type = '$type', Colour = '$colour', Breed = '$breed' WHERE BearId = '$q'";
if($mysqli->query($sql) === TRUE)
{
echo 'Record updated successfully<br />';
}
else
{
echo $sql.'<br />' . $mysqli->error;
}
$mysqli->close();
}
?>
<br />
<div id="result"></div>
<br />
Click here to Visit Task 2 (Insert Bears) | Click here to Visit Task 3 (Display Bears)
</body>
</html>
getvalues.php
<?php
$q=$_GET["q"];
$mysqli = new mysqli('localhost','User','123','bears');
$sql = "SELECT * FROM bears WHERE BearId='".$q."'";
if($stmt = $mysqli->prepare($sql))
{
$stmt->execute();
$stmt->bind_result($BearId, $Weight, $Sex, $Type, $Colour, $Breed);
while ($stmt->fetch())
{
echo "<form method='post' name='form1' onsubmit='return validateForm()' action='updatebears.php'>";
echo "<p>";
echo "<label for='BreedId'>BreedId:</label>";
echo "<br />";
echo "<select id='BreedId' name='BreedId' />";
echo "<option value='".$Breed."'>".$Breed."</option>";
echo "<option value='1'>1. Polar</option>";
echo "<option value='2'>2. Brown</option>";
echo "<option value='3'>3. Panda</option>";
echo "</select>";
echo "</p>";
echo "<p>";
echo "<label for='Weight'>Weight(kg):</label>";
echo "<br />";
echo "<input type='text' id='Weight' name='Weight' value='".$Weight."' />";
echo "</label>";
echo "</p>";
echo "<p>";
echo "Sex: ";
echo "<br />";
echo "<label for='M'>Male</label><input type='radio' id='M' value='M' name='Sex'";
if($Sex=='M') echo "checked";
echo "/>";
echo "<label for='F'>Female</label><input type='radio' id='F' value='F' name='Sex'";
if($Sex=='F') echo "checked";
echo "/>";
echo "</p>";
echo "<p>";
echo "<label for='Type'>Type:</label> ";
echo "<br />";
echo "<input type='text' id='Type' name='Type' maxlength='100' value='".$Type."' />";
echo "</p>";
echo "<p>";
echo "<label for='Colour'>Colour:</label>";
echo "<br />";
echo "<input type='text' id='Colour' name='Colour' maxlength='20' value='".$Colour."' />";
echo "</p>";
echo "<p>";
echo "<input type='submit' value='Submit' />";
echo "<input type='reset' value='Reset' />";
echo "<input type='hidden' name='_submit_check' value=1 />";
echo "</p>";
echo "</form>";
}
}
else
{
echo 'Unable to connect';
exit();
}
?>
Thanks for the help.
I believe what you need to do is create a hidden input type for the BearId within the getvalues.php file. That way when your form performs the post you can get the BearId from the post as opposed to trying to get it from the $row['BearId']. I'm fairly certain $row['BearId'] is not the same $row['BearId'] that the user selected when he first goes to the getvalues.php form. Have you tried printing $row['BearId'] to html to verify it's a legitimate value?
if(array_key_exists('_submit_check', $_POST))
{
$id = $_POST['BearId']
$weight = $_POST['Weight'];
$sex = $_POST['Sex'];
$type = $_POST['Type'];
$colour = $_POST['Colour'];
$breed = $_POST['BreedId'];
$sql = "UPDATE bears SET Weight = '$weight', Sex = '$sex', Type = '$type', Colour = '$colour', Breed = '$breed' WHERE BearId = '$id'";
if($mysqli->query($sql) === TRUE)
{
echo 'Record updated successfully<br />';
}
else
{
echo $sql.'<br />' . $mysqli->error;
}
$mysqli->close();
}
?>
<h1>getvalues.php</h1>
<?php
$q=$_GET["q"];
$mysqli = new mysqli('localhost','User','123','bears');
$sql = "SELECT * FROM bears WHERE BearId='".$q."'";
if($stmt = $mysqli->prepare($sql))
{
$stmt->execute();
$stmt->bind_result($BearId, $Weight, $Sex, $Type, $Colour, $Breed);
while ($stmt->fetch())
{
echo "<form method='post' name='form1' onsubmit='return validateForm()' action='updatebears.php'>";
echo <input type="hidden" name="BearId" value='".$q."'>
echo "<p>";
echo "<label for='BreedId'>BreedId:</label>";
echo "<br />";
echo "<select id='BreedId' name='BreedId' />";
echo "<option value='".$Breed."'>".$Breed."</option>";
echo "<option value='1'>1. Polar</option>";
echo "<option value='2'>2. Brown</option>";
echo "<option value='3'>3. Panda</option>";
echo "</select>";
echo "</p>";
echo "<p>";
echo "<label for='Weight'>Weight(kg):</label>";
echo "<br />";
echo "<input type='text' id='Weight' name='Weight' value='".$Weight."' />";
echo "</label>";
echo "</p>";
echo "<p>";
echo "Sex: ";
echo "<br />";
echo "<label for='M'>Male</label><input type='radio' id='M' value='M' name='Sex'";
if($Sex=='M') echo "checked";
echo "/>";
echo "<label for='F'>Female</label><input type='radio' id='F' value='F' name='Sex'";
if($Sex=='F') echo "checked";
echo "/>";
echo "</p>";
echo "<p>";
echo "<label for='Type'>Type:</label> ";
echo "<br />";
echo "<input type='text' id='Type' name='Type' maxlength='100' value='".$Type."' />";
echo "</p>";
echo "<p>";
echo "<label for='Colour'>Colour:</label>";
echo "<br />";
echo "<input type='text' id='Colour' name='Colour' maxlength='20' value='".$Colour."' />";
echo "</p>";
echo "<p>";
echo "<input type='submit' value='Submit' />";
echo "<input type='reset' value='Reset' />";
echo "<input type='hidden' name='_submit_check' value=1 />";
echo "</p>";
echo "</form>";
}
}
else
{
echo 'Unable to connect';
exit();
}

previously submitted form data disappears when new form is submitted

I have multiple forms on a single page and all gets redirected to same page when form is submitted but the previously submitted form values disappears when new form is submitted.
I tried using sessions didn't worked for me what else? please help
<script language="javascript">
function row(x,y){
//var len=document.forms[x].name.value;
if(x.value.length >=3)
{
//alert("Message form no> "+y+"will be submited");
document.forms[y].submit();
}
}
</script>
</head>
<body >
<center>
<h2>Database App</h2>
<table>
<tr>
<th><lable>Name :</label></th>
<th><label>E_Id :</label></th>
<th><label>Email :</label></th>
<th><label>Other Info :</label></th></tr>
<tr>
<?php
error_reporting(E_ALL ^ E_NOTICE);
// code check for name in database and if exists,displays in table row
//for($i=0;$i<150;$i++)
//{
//$E_id=array();
if($_POST){
$i = $_GET["uid"];
//echo "fhwefwej==".$i;
$x='name'.$i;
// echo 'dasvds'.$x;
if($_POST[$x])
{
$name = strtolower($_POST[$x]);
$E_id[$i] = "";
$Email[$i] = "";
$Otherinfo[$i] = "";
$con = mysql_connect('localhost','root','') or die("npt");
$db = mysql_select_db("trainee")or die("nptdff");
$query = "Select * from reguser where fname like '".$_POST[$x]."%'";
$result = mysql_query($query);
mysql_num_rows($result);
if(mysql_num_rows($result)>0)
{
while($row=mysql_fetch_array($result))
{
$str=$row['fname'];
$initials = strtolower(substr($str,0,3));
if($name == $initials)
{
//echo "exist"."<br>";
$E_id[$i]= $row['fname'];
$Email[$i]=$row['lastname'];
$Otherinfo[$i]=$row['address'];
break;
}
}
}
else
{
$msg[$i] = "no user with these initials";
}
mysql_close($con);
}
}
for($i=0;$i<150;$i++)
{
//session_start();
//echo session_name($i)."<br>";
echo "<form name='form$i' action='new2.php?uid=$i' method='post'>";
echo "<td><input type='text' name='name$i' id='name$i' onkeyup='row(this,$i);' /><br />";
echo "<span id='availability_status' >";
if($_POST[$x]){echo $msg[$i];}
echo "</span> </td>";
echo "<td><input type='text' name='E_id' id='E_id' value='";
if(isset($_POST[$x])){ echo $E_id[$i];}
echo "' disabled='disabled' />";
echo "</td>";
echo "<td><input type='text' name='email' id='email' value='$Email[$i]' disabled='disabled' />";
echo "</td>";
echo "<td><input type='text' name='otherinfo' id='otherinfo' value='$Otherinfo[$i]' disabled='disabled' />";
echo "</td></tr>";
echo " </form>";
}
//echo '<script language="javascript">document.getElementById(\'name0\').focus();</script>';
?>
</table>
</center>
</body>
</html>
Why don't you Use AJAX. It will help to keep you posed different form information in back-end
you can either store those information in database or in file.
It will be the best way.

My page is not loading right

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.

Categories