I am trying to create a Registration System using only PHP. This is an example of that. But I think I have done something wrong. I tried to find similar solution in StackOverFlow posts but didn't get any exact solution. It would be really get if someone would help me to find the error in my code below.
<?php
// POST HANDLER -->
if(isset($_POST['registerForm']))
{
conFunc(); // Connection Function
$userid = $_POST['userid'];
$name = $_POST['name'];
$getUserId = mysql_query("SELECT * FROM `user` WHERE `userid` = '".$userid."'");
$id = mysql_fetch_array($getUserId);
if($id)
{
echo "This User ID is Already Available on the System, Please Choose Something Else!";
}
else
{
$query = mysql_query("INSERT INTO `user` (`userid`, `name`");
if($query)
{
echo "A New User is Registered Successfully:<br /><br />";
echo "<b>User ID:</b> " . $userid . "<br />";
echo "<b>User Name:</b> " . $name . "<br />";
}
else
{
echo "There is an Error while Saving: " . mysql_error();
echo "<br />Please click on Create User from menu, and try again<br /><br />.";
}
}
exit;
}
// POST HANDLER -->
?>
<!-- FORM GOES BELOW -->
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="registerForm">
<table style="width: 100%">
<tr>
<td>User ID</td>
<td><input name="userid" type="text" style="width: 300px" /><br /></td>
</tr>
<tr>
<td>Name</td>
<td><input name="name" type="text" style="width: 300px" /><br /></td>
</tr>
<tr>
<td></td>
<td><input style="width: 130px; height: 30px" type="submit" name="submit" value="Register Now" /><br /></td>
</tr>
</table>
</form>
You have to check the submit button is set or not.
if(isset($_POST['registerForm']))
should be
if(isset($_POST['submit'])) {
// your php code
} else {
// your html code
}
registerform element is not treated as post element so check with submit button.
Try following code :
<?php
// POST HANDLER -->
if(isset($_POST['submit'])){
conFunc(); // Connection Function
$userid = $_POST['userid'];
$name = $_POST['name'];
$getUserId = mysql_query("SELECT * FROM `user` WHERE `userid` = '".$userid."'");
$id = mysql_fetch_array($getUserId);
if($id)
{
echo "This User ID is Already Available on the System, Please Choose Something Else!";
}
else
{
$query = mysql_query("INSERT INTO `user` (`userid`, `name`");
if($query)
{
echo "A New User is Registered Successfully:<br /><br />";
echo "<b>User ID:</b> " . $userid . "<br />";
echo "<b>User Name:</b> " . $name . "<br />";
}
else
{
echo "There is an Error while Saving: " . mysql_error();
echo "<br />Please click on Create User from menu, and try again<br /><br />.";
}
}
exit;
}else{
// POST HANDLER -->
?>
<!-- FORM GOES BELOW -->
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="registerForm">
<table style="width: 100%">
<tr>
<td>User ID</td>
<td><input name="userid" type="text" style="width: 300px" /><br /></td>
</tr>
<tr>
<td>Name</td>
<td><input name="name" type="text" style="width: 300px" /><br /></td>
</tr>
<tr>
<td></td>
<td><input style="width: 130px; height: 30px" type="submit" name="submit" value="Register Now" /><br /></td>
</tr>
</table>
</form>
<?php } ?>
Your script should be like
$getUserId = mysql_query("SELECT id FROM `user` WHERE `userid` = '".$userid."'");
because you are getting all the results and you need to retrive the id only and your form action should be your same page itself
you need to read about mysql queries http://php.net/manual/en/book.mysql.php
also check your insert query not any data values inserted.
<?php if(isset($_POST['submit']))
{
conFunc(); // Connection Function
$userid = $_POST['userid'];
$name = $_POST['name'];
$getUserId = mysql_query("SELECT * FROM user WHERE userid = '".$userid."'");
$id = mysql_fetch_array($getUserId);
if($id)
{
echo "This User ID is Already Available on the System, Please Choose Something Else!";
}
else
{
$query = mysql_query("INSERT INTO user(userid, name) values('" .$userid . "','" . $name . "')";
if($query)
{
echo "A New User is Registered Successfully:<br /><br />";
echo "<b>User ID:</b> " . $userid . "<br />";
echo "<b>User Name:</b> " . $name . "<br />";
}
else
{
echo "There is an Error while Saving: " . mysql_error();
echo "<br />Please click on Create User from menu, and try again<br /><br />.";
}
}
exit;
}
// POST HANDLER -->
?>
<!-- FORM GOES BELOW -->
<form action="" method="post" name="registerForm">
<table style="width: 100%">
<tr>
<td>User ID</td>
<td><input name="userid" type="text" style="width: 300px" /><br /></td>
</tr>
<tr>
<td>Name</td>
<td><input name="name" type="text" style="width: 300px" /><br /></td>
</tr>
<tr>
<td></td>
<td><input style="width: 130px; height: 30px" type="submit" name="submit" value="Register Now" /><br /></td>
</tr>
</table>
</form>
Related
I've been trying to solve this for awhile, and I'd appreciate it if someone can help me. Here is my problem.
Here is my code; it's simply view the content of a Job Table in the Database and perform a edition as needed, based on the selection. The checkbox is next to each job, and there is an update button at the end of the page to submit..
I'm getting an error updating it. Please help me.
<?php
session_start();
if( isset($_SESSION['username']) ){
include('../CIEcon.php');
echo "<form action= 'adminCleaning.php' method = 'post'>" ;
// when the user click update..
if(isset($_POST['update'])){
if( empty($_POST['Id']) || $_POST['Id'] == 0 ){
echo"<h4> please choose something to update </h4>";
echo"test(1): pass <br> ";
}else{
// comes here even though u dind't chhose, cause
// it set IDs next to each feild..
echo"!!....HERE....!! ";
}
}// end of update $_POAT[update]
$sql = "SELECT * FROM Cleaning ";
$result = mysqli_query($dbCIE, $sql) or die(mysqli_error($dbCIE));
/// NOW DISPLAY ALL INFO FROM CHOSEN DATABASE...
echo "
<table cellpadding ='4' border='1' width='80%' align='center'>
<tr>
<th class='tt' >Check </th>
<th class='tt'> Job's Name</th>
<th class='tt' >Description</th>
<th class='tt' > No Students needed</th>
<th class='tt' >Due Date</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<br>";
echo "<tr>";
echo "<td> <input type='checkbox' name='Id[]' value='".$row['Id']."' /> </td>"; // array[] cause to edit more than one record...
echo "<td>".'<input type="text" name="jobname['.$row['Id'].']" value='.$row['JobName'].' >'."</td>";
echo "<td>".'<input type="text" name="description['.$row['Id'].']" value='.$row['Description'].'> '."</td>";
echo "<td>".'<input type="text" name="nostudent['.$row['Id'].']" value='.$row['NoStudent'].'>'."</td>";
echo "<td>".'<input type="text" name="duedate['.$row['Id'].']" value='.$row['DueDate'].'>'."</td>";
echo "<input type=hidden name='Id[]' value='".$row['Id']."' >";
echo "</tr>";
echo "jobname['.$row[Id].']" ; // testing.
echo "description['.$row[Id].']" ; // testing.
echo "nostudent['.$row[Id].']" ; // testing.
}
echo "</table>";
/// END THE SEARCH HERE...........
echo " <br>
<div align='center'>
<input type='reset' value='clear' />
<input type='submit' name='update' value='update' />
</div> ";
mysqli_close($dbCIE);
echo "</form>";
}
else{echo "must logout to see this page..!!";}
?>
<html>
<head><title> ..Cleanding.... </title></head>
<style type="text/css">
body{
margin-top: 70px; /*space above the table....*/
background-color: #23438e;
}
table{
background-color: white;
}
.tt{
background: #f26822;
color: white ;
}
</style>
<body>
<!-- <a href= "../AdminIndex.php" > <button> Main Page </button></a> -->
</body>
</html>
First of all, your form and table are outside of <body> tag. You have to display everything like this: <body> **display here** </body>
Second, remove this line echo "<input type=hidden name='Id[]' value='".$row['Id']."' >"; from your code, it's not required.
And now comes to your question, $_POST['Id'] is an array of job ids, so use count() function to check if the array is empty or not and use foreach loop to update each individual row. So you should process your form like this:
// when the user click update..
if(isset($_POST['update'])){
if(count($_POST['Id'])){
// $_POST['Id'] is an array of job id
foreach($_POST['Id'] as $v){
$sqlUpdate = "UPDATE Cleaning SET JobName='" . $_POST['jobname'][$v] . "', Description='" . $_POST['description'][$v] . "', NoStudent='" . $_POST['nostudent'][$v] ."', DueDate='" . $_POST['duedate'][$v] . "' WHERE Id = '" . $v . "'";
$resultUpdate = mysqli_query($dbCIE,$sqlUpdate) or die(mysqli_error($dbCIE));
// If you want you can use mysqli_affected_rows() function to
// check how many were affected by the UPDATE query
}
}else{
echo"<h4>please choose something to update</h4>";
}
}
And your entire code should be like this:
<?php
session_start();
?>
<html>
<head>
<title> ..Cleanding.... </title>
<style type="text/css">
body{
margin-top: 70px; /*space above the table....*/
background-color: #23438e;
}
table{
background-color: white;
}
.tt{
background: #f26822;
color: white ;
}
</style>
</head>
<body>
<?php
if( isset($_SESSION['username']) ){
include('../CIEcon.php');
// when the user click update..
if(isset($_POST['update'])){
if(count($_POST['Id'])){
// $_POST['Id'] is an array of job id
foreach($_POST['Id'] as $v){
$sqlUpdate = "UPDATE Cleaning SET JobName='" . $_POST['jobname'][$v] . "', Description='" . $_POST['description'][$v] . "', NoStudent='" . $_POST['nostudent'][$v] ."', DueDate='" . $_POST['duedate'][$v] . "' WHERE Id = '" . $v . "'";
$resultUpdate = mysqli_query($dbCIE,$sqlUpdate) or die(mysqli_error($dbCIE));
// If you want you can mysqli_affected_rows() function to
// check how many were affected by the UPDATE query
}
}else{
echo"<h4>please choose something to update</h4>";
}
}
$sql = "SELECT * FROM Cleaning ";
$result = mysqli_query($dbCIE, $sql) or die(mysqli_error($dbCIE));
?>
<form action= 'adminCleaning.php' method = 'post'>
<table cellpadding ='4' border='1' width='80%' align='center'>
<tr>
<th class='tt' >Check </th>
<th class='tt'> Job's Name</th>
<th class='tt' >Description</th>
<th class='tt' > No Students needed</th>
<th class='tt' >Due Date</th>
</tr>
<?php
while($row = mysqli_fetch_array($result)){
?>
<tr>
<td> <input type="checkbox" name="Id[]" value="<?php echo $row['Id']; ?>" /> </td>
<td><input type="text" name="jobname[<?php echo $row['Id']; ?>]" value="<?php echo $row['JobName']; ?>" /></td>
<td><input type="text" name="description[<?php echo $row['Id']; ?>]" value="<?php echo $row['Description']; ?>" /></td>
<td><input type="text" name="nostudent[<?php echo $row['Id']; ?>]" value="<?php echo $row['NoStudent']; ?>" /></td>
<td><input type="text" name="duedate[<?php echo $row['Id']; ?>]" value="<?php echo $row['DueDate']; ?>" /></td>
</tr>
<?php
}
?>
</table>
<input type="reset" value="clear" />
<input type="submit" name="update" value="update" />
</form>
<br />
<div align='center'>
</div>
<?php
mysqli_close($dbCIE);
}
else{
echo "must logout to see this page..!!";
}
?>
</body>
</html>
I am currently creating an interface for users to enter details in regarding their pets. I am using two php pages, one with a html form in which allows the users to enter the data and the other one to display the data. I have currently encountered two problems,
one being that when the "submit" button on the HTML form is clicked, it does not divert to the second page.
The second one being that the data which is being entered onto the first page through text boxes is not being posted to the next page for the users to get an overview.
I am very new to php, I will display all of the code as I feel that there are many errors. The code is not too overwhelming and I hope someone can help with these issues, thanks.
p.s. the first section of code is the page where users can enter the data, and the second section is the second page.
<?php
echo '<link href="style.css" rel="stylesheet">';
session_start();
$fname = $_POST["fname"];
$petname = $_POST["petname"];
$pettype = $_POST["pettype"];
$pdob = $_POST["pdob"];
$appdate = $_POST["appdate"];
$apptime = $_POST["apptime"];
$reason = $_POST["reason"];
$validated = false;
$_SESSION['login'] = "";
if ($result > 0) $validated = true;
if($validated)
{//Divert to the protected page to display information after.
$_SESSION['login'] = "OK";
$_SESSION['fname'] = $fname;
$_SESSION['petname'] = $petname;
$_SESSION['pettype'] = $pettype;
$_SESSION['pdob'] = $pdob;
$_SESSION['appdate'] = $appdate;
$_SESSION['apptime'] = $apptime;
$_SESSION['reason'] = $reason;
header('Location: protected.php');
}
$_SESSION['login'] = "";
?>
<html>
<body>
<div align="center">
<h1 class="ribbon">
<strong class="ribbon-content">Veterinary Appointment Form</strong>
</h1>
<p><i>Please enter information reguarding your pet</i></p>
<form action="protected.php"
method="post">
<table>
<tr>
<td
align="right">Full Name* : </td>
<td><input size=\"20\"
type="text" size="20" maxlength="50"
name="fname"></td>
</tr>
<tr>
<td
align="right">Name of Pet* : </td>
<td><input size=\"20\"
type="text" size="20"
maxlength="50" name="petname"></td>
</tr>
<tr>
<td
align="right">Pet Type* : </td>
<td><input size=\"20\"
type="text" size="20"
maxlength="50" name="pettype"></td>
</tr>
<tr>
<td
align="right">Pet D.O.B : </td>
<td><input size=\"20\"
type="text" size="20"
maxlength="50" name="petdob"></td>
</tr>
<tr>
<td
align="right">Date of Appointment* : </td>
<td><input size=\"20\"
type="text" size="20"
maxlength="50" name="appdate"></td>
</tr>
<tr>
<td
align="right">Time of Appointment* : </td>
<td><input size=\"20\"
type="text" size="40"
maxlength="50" name="apptime"></td>
</tr>
<tr>
<td
align="right">Why Appoitnment is Needed : </td>
<td><input size=\"20\"
type="text" size="20"
maxlength="50" name="reason"></td>
</tr>
<tr>
<td> </td>
<td colspan="2"
align="left"><input type="submit"
value="Login"></td>
</div> </tr>
<br>
</table>
</form>
</body>
<img src="doglogo.png" alt="Logo" style="width:150;height:130;">
</html>
<?php
echo '<link href="style.css" rel="stylesheet">';
{
header('Location: ManageUser.php');
exit();
}
?>
<html>
<head>
<title>Welcome!</title>
</head>
<body>
<div align="center">
<h1 class="ribbon">
<strong class="ribbon-content">Veterinary Appointment Form</strong>
</h1>
<p><i>Here are your details</i></p>
<?php
echo "<p>Full Name: ";
echo $_SESSION['fname'];
echo "<br/>";
echo "<p>Name of Pet: ";
echo $_SESSION['petname'];
echo "<br/>";
echo "<p>Pet Type: ";
echo $_SESSION['pettype'];
echo "<br/>";
echo "<p>Pet D.O.B: ";
echo $_SESSION['pdob'];
echo "<br/>";
echo "<p>Date of Appointment: ";
echo $_SESSION['appdate'];
echo "<br/>";
echo "<p>Time of Appointment: ";
echo $_SESSION['apptime'];
echo "<br/>";
echo "<p>Why Appoitnment is Needed: ";
echo $_SESSION['reason'];
echo "<br/>";
echo "</p>";
{
echo "<p><a href='ManageUser.php'><i>Click here to return</i></a></p>";
}
?>
Print this page
<br>
<img src="doglogo.png" alt="Logo" style="width:150;height:130;">
</div>
</body>
</html>
This will always exit the script.
{
header('Location: ManageUser.php');
exit();
}
Maybe you wanted to do something like this :
if (something) // if the user didn't fill the form
{
header('Location: ManageUser.php');
exit();
}
Also, be careful with :
echo '<link href="style.css" rel="stylesheet">';
This will display the tag before <html>, you may want to place it inside the <head> tag.
You also forgot to add session_start() on the second page.
To summarize :
<?php
session_start();
if (something)
{
header('Location: ManageUser.php');
exit();
}
?>
<html>
<head>
<title>Welcome!</title>
<link href="style.css" rel="stylesheet">
</head>
Bonus : this code
<?php
echo "<p>Full Name: ";
echo $_SESSION['fname'];
echo "<br/>";
echo "<p>Name of Pet: ";
echo $_SESSION['petname'];
echo "<br/>";
echo "<p>Pet Type: ";
echo $_SESSION['pettype'];
echo "<br/>";
echo "<p>Pet D.O.B: ";
echo $_SESSION['pdob'];
echo "<br/>";
echo "<p>Date of Appointment: ";
echo $_SESSION['appdate'];
echo "<br/>";
echo "<p>Time of Appointment: ";
echo $_SESSION['apptime'];
echo "<br/>";
echo "<p>Why Appoitnment is Needed: ";
echo $_SESSION['reason'];
echo "<br/>";
echo "</p>";
{
echo "<p><a href='ManageUser.php'><i>Click here to return</i></a></p>";
}
?>
can be replaced by :
<p>Full Name: <?=$_SESSION['fname']?></p>
<br/>
<p>Name of Pet: <?=$_SESSION['petname']?></p>
<br/>
<p>Pet Type: <?=$_SESSION['pettype']?></p>
<br/>
<p>Pet D.O.B: <?=$_SESSION['pdob']?></p>
<br/>
<p>Date of Appointment: <?=$_SESSION['appdate']?></p>
<br/>
<p>Time of Appointment: <?=$_SESSION['apptime']?></p>
<br/>
<p>Why Appoitnment is Needed: <?=$_SESSION['reason']?></p>
<br/>
<p><a href='ManageUser.php'><i>Click here to return</i></a></p>
Be sure to check the rendered code with the W3C Validation tool. This will check if the HTML code is correct and tell you what is wrong.
I think the the problem is here:
if ($result > 0)
where did you define $result ?
Try to do check print_r($_POST); in protected.php and check you if condition.
This code here is working perfectly well. All i want to do is to pass the FirstName and LastName (using SESSION) which is already stored in the $userName. The first and last name is actually retrieved from the database when trying to login.
I want to have the First and Last Name show on every page once logged in.. Thanks
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><?php
$DisplayForm = TRUE;
$errors = 0;
if(isset($_POST['uname']) && isset($_POST['pass'])) {
include("dbconnect.php");
if($DBConnect !== FALSE){
$SQLstring = "SELECT userid, first_name, last_name FROM users WHERE username ='".
$_POST['uname']. "' and password = '".md5($_POST['pass'])."'";
$DisplayForm = FALSE;
$QueryResult = #mysql_query($SQLstring, $DBConnect);
echo mysql_error();
if (mysql_num_rows($QueryResult)=== 0){
echo "<p style='color:red;'><b> The email address/password " .
" combination is not valid.</b></p>\n";
++$errors;
$DisplayForm = TRUE;
}
else
{
$DisplayForm = FALSE;
}
}
}
if ($DisplayForm)
{?>
<form id="form1" name="loginForm" method="post" action="index.php">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="93" bgcolor="#DACFAF"><strong> Username:</strong></td>
<td width="149" bgcolor="#DACFAF"><label for="textfield"></label>
<input type="text" name="uname" id="textfield" /></td>
<td width="76" bgcolor="#DACFAF"><strong>Password:</strong></td>
<td width="150" bgcolor="#DACFAF"><label for="textfield2"></label>
<input type="password" name="pass" id="pass" /></td>
<td width="196" bgcolor="#DACFAF"><input type="image" name="login" src="images/login.jpg" /> </td>
<td width="68" bgcolor="#DACFAF"> </td>
<td width="68" bgcolor="#DACFAF"><strong>Register </strong> </td>
</tr>
</table>
</form>
<?php }
else {
$Row = mysql_fetch_assoc($QueryResult);
$userID = $Row['userid'];
$userName = $Row['first_name']. " ". $Row['last_name'];
echo "<table width=780px border=0px >";
echo "<tr>";
echo "<td style='color:red;'>";
echo "<b> Welcome back, $userName!</b>";
echo "</td>";
echo"<td align='right'>";
echo "<form method='POST' action=''>";
echo "<input type='submit' name='submit' value='logout'>";
echo "</form>";
echo "</td>";
echo "</tr>";
echo "</table>";
}
?> </td>
</tr>
</table>
Assuming you know how to set $_SESSION variable.
or if not
In your log in php start a session using session_start();. after all the checking is done. Put the name inside of the $_SESSION variable.
like this
$_SESSION['username'] = $firstname.$lastname;
assuming $firstname has the user's first name and $lastname has the user's last name.
THEN:
Put session_start(); at the very beginning of your PHP file that you want to display the username.
then
$userName=$_SESSION['username'];
Put this two together at the very start of every php file you want to display the name.
Now you can use the variable $userName to display the name.
I am having problem in this following code.It says undefined index on line 83.The second problem is that there is a huge gap between the text fill the required form and the input textbox of the form during output.Please help me out.The code is posted below.
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
$firstnameErr = $lastnameErr = $emailErr = "";
$firstname = $lastname = $email = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty($_POST["firstname"]))
{
$firstnameErr = "Name is required";
}
else
{
$firstname = test_input($_POST["firstname"]);
}
if (empty($_POST["lastname"]))
{
$lastnameErr = "Name is required";
}
else
{
$lastname = test_input($_POST["lastname"]);
}
if (empty($_POST["email"]))
{
$emailErr = "Email is required";
}
else
{
$email = test_input($_POST["email"]);
}
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<div text align =center><h1>Eventous Info</h1></div>
<h3>Fill the Required Form:</h3>
<p><span class="error">*required field</span></p>
<table>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<tr><?php// echo htmlspecialchars($_SERVER["PHP_SELF"]);?>
<td>Firstname:</td>
<td><input type="text" name="firstname" ></td>
<td><span class="error">* <?php echo $firstnameErr;?></span></td><br><br>
</tr>
<tr>
<td>Lastname:</td>
<td><input type="text" name="lastname" ></td>
<td><span class="error">* <?php echo $lastnameErr;?></span></td><br><br>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email"></td>
<td><span class="error">* <?php echo $emailErr;?></span></td><br><br>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" name="number"><td><br><br>
</tr>
</table>
<input type="submit" >
</form>
<?php
$con = mysql_connect("localhost","ashu123","bangalore");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("evantus", $con);
$sql="INSERT INTO employee (firstname, lastname, email, phone )
***LINE-83***
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[email]','$_POST[number]')";
$sql = "select * from employee";
$query = mysql_query( $sql );
echo "<table>";
echo "<tr><th>firstname</th>";
echo "<th>lastname</th>";
echo "<th>email</th>";
echo "<th>phone</th></tr>";
while( $row = mysql_fetch_assoc($query) )
{
echo "<tr><td>$row[firstname]</td>";
echo "<td>$row[lastname]</td>";
echo "<td>$row[email]</td>";
echo "<td>$row[phone]</td></tr>";
}
echo "</table>";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con)
?>
</body>
</html>
Your form has invalid html code. In short, just use:
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table>
<tr>
<td>Firstname:</td>
<td><input type="text" name="firstname" ></td>
<td><span class="error">* <?php echo $firstnameErr;?></span><br /><br /></td>
</tr>
<tr>
<td>Lastname:</td>
<td><input type="text" name="lastname" ></td>
<td><span class="error">* <?php echo $lastnameErr;?></span><br /><br /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email"></td>
<td><span class="error">* <?php echo $emailErr;?></span><br /><br /></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" name="number"><br /><br /><td>
<td></td>
</tr>
</table>
<input type="submit" >
</form>
More about it:
1. After opening the <table> element, next one must be table row, so <form> must be a wrapper to your table.
2. You have placed breaks after closing the </td> tag, which is wrong - they should be inside table cell.
3. Ref: undefined index, guess it is only a warning that you are using the $_POST variable that does not exist.
I feel your insert query is not right, try the query below.
$sql="INSERT INTO employee (firstname, lastname, email, phone ) VALUES ('".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['email']."','".$_POST['number']."')";
this is the first form that in the header of the page which search my titles.
<form action="index.php?cat=search_results&learn_id=1" method="post">
<div id="topSearchBodyStyle">
<input type="text" name="search" class="topSearchTextBackground" />
</div>
<div id="topSearchButtonStyle">
<input type="submit" name="submit" class="topSearchButtonBackground" value="" />
</div>
</form>
and this is the page called searchPage.php
<?php
if (isset($_POST['search'])){
$getSearch = clean_text($_POST['search']);
$connectToDb = "select * from tutorials where tutorial_title like '%".$getSearch."%' and active=1";
$searchResults = $db->query($connectToDb) or die($db->error);
$numResultas = $searchResults ->num_rows;
echo "<p class='counter_search'>Found : " . $numResultas . "</p>";
switch ($numResultas) {
case 0:
include "searchPageAdvanced.php";
break;
case $numResultas >= 1:
while($row = mysqli_fetch_array($searchResults)) {
echo "<a class='counter_linkHeader' href='index.php?cat=tutorials_view&learn_id=5&tutorial_id=".$row['tutorial_id']."'>".$row['tutorial_title']."</a>";
echo "<p class='counter_description'>";
$your_desired_width=200;
$description=$row['content'];
if (strlen($description) > $your_desired_width) {$description = wordwrap($description, $your_desired_width); $description = substr($description, 0, strpos($description, "\n"))." ..."; } echo $description;
echo"</p>";
}
break;
}
}else{
?>
<p> </p>
<table width="875" border="0">
<tr>
<td align="center" valign="middle"><img src="http://bytes.com/images/searchError.jpg" width="223" height="147" alt="search error" /></td>
</tr>
<tr>
<td align="center" valign="middle">Sorry you came here by mistake <br />
please use the search box to get results</td>
</tr>
</table>
<p> </p>
<?php
}
?>
and the is the advanced search page.
which will search the content.
<form action="" method="post">
<input type='text' name='searchAdv' />
<input type='submit' name='submit_adv' value='Search' id="submit_adv" />
</form>
</td>
</tr>
<tr>
<td align='center' valign='middle'><p>Sorry you came here because your search didn't </p>
<p>meet any of the content try advanced!!</p></td>
</tr>
</table>
<?php
if (isset($_POST['submit_adv'])){
$getSearch = clean_text($_POST['searchAdv']);
$connectToDb = "select * from tutorials where content like '%".$getSearch."%' and active=1";
$searchResultsAdv = $db->query($connectToDb) or die($db->error);
while($rowAdv = mysqli_fetch_array($searchResultsAdv)) {
echo "<a class='counter_linkHeader' href='index.php?cat=tutorials_view&learn_id=5&tutorial_id=".$rowAdv['tutorial_id']."'>".$rowAdv['tutorial_title']."</a>";
echo "<p class='counter_description'>";
$your_desired_width=200;
$description=$rowAdv['content'];
if (strlen($description) > $your_desired_width) {$description = wordwrap($description, $your_desired_width); $description = substr($description, 0, strpos($description, "\n"))." ..."; } echo $description;
echo"</p>";
}
}
?>
now again the problem begin in the advanced search page, the search page is working fine
but when I search in the advanced page it return the page empty like he didn't take any thing for the input area SearchAdv