I need help about this, I have a PHP page, which searches for records, based on their first and last names, if sql finds the data then the second form comes out, which has lots of textboxes, to update the 'searched'information. And when I click the submit button of the second form , it does nothing, and even if I have syntax or whatever errors I have put on condition if(isset($_POST['submit'])), they end up being disregarded (no error messages will come up), after clicking the submit button, it just goes back to the page's original state, when it has to update the record I have searched for that was just edited. What exactly is the mistake on this part?
class.php - .php file that contains the operations for sql
$months = array('January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December');
class EmployeeProfile {
public
function openConnection() {
$conn = mysqli_connect("localhost", "root", "", "db_employee");
if (mysqli_connect_errno()) {
echo "Failed to connect to database server";
}
return $conn;
}
public
function insert($query) {
if (mysqli_query($this - > openConnection(), $query) == 1) {
echo "Profile successfully registered!";
} else {
echo "Register failed";
}
}
public
function display($query) {
$result = mysqli_query($this - > openConnection(), $query);
echo "
";
if ($result - > num_rows == 1) {
while ($row = $result - > fetch_assoc()) {
echo "";
echo "First Name: ".$row["firstname"]." ";
echo "Middle Name: ".$row["middlename"]." ";
echo "Last Name: ".$row["lastname"]." ";
echo "Date of Birth: ".$row["dateofbirth"]." ";
echo "Age: ".$row["age"]." ";
echo "School: ".$row["school"]." ";
echo "Highest Educational Attainment: ".$row["educ"]." ";
echo "Year Last Attended: ".$row["yearattended"]." ";
echo "Skills: ".$row["skills"]." ";
echo "Previous Company: ".$row["prevcompany"]." ";
echo "Position: ".$row["position"]." ";
echo "Date of Employment: ".$row["dateofemployment"]." ";
echo "
";
}
} else
{
echo "Profile not found";
}
}
public
function edit($query) {
$result = mysqli_query($this - > openConnection(), $query);
}
}
?>
edit.php - the page itself.
Edit Profile
and I do really think that this line and beyond gets ignored.
This is part of the edit.php
file that is shown above.
if(isset($_POST['submit'])):
$firstname = $_POST['firstname'];
$middlename = $_POST['middlename'];
$lastname = $_POST['lastname'];
$dateofbirth = $_POST['month']. " ".$_POST['days']. ", ".$_POST['year'];
$age = $_POST['age'];
$school = $_POST['school'];
$educ = $_POST['educ'];
$yearattended = $_POST['yearattended'];
$skills = $_POST['skills'];
$prevcompany = $_POST['prevcompany'];
$position = $_POST['position'];
$dateofemployment = $_POST['empmonth']. " ".$_POST['empyear'];
$row = $result->fetch_assoc();
$usr = $row["firstname"];
$query2 = "UPDATE employee SET firstname='$firstname', middlename='$middlename', lastname='$lastname', dateofbirth='$dateofbirth', age='$age', school='$school',
educ='$educ', yearattended='$yearattended', skills='$skills', prevcompany='$prevcompany', position='$position', dateofemployment='$dateofemployment',
WHERE firstname='$usr'";
mysqli_query($emp->openConnection(), $query2);
endif;
Answer
In general, there are two kinds of errors present.
- HTML tag order errors, which are extensive
- Syntax errors.
- >
must be->
to be properly parsedmust be
to be properly parsed
The syntax errors are present in both files.
Note: the following code contains some debug statements.
echo "In myquery.php header
";
error_reporting(E_ALL);
//echo "" . var_dump($_POST); . "
";
//echo "" . var_dump($_GET); . "
";
?>
include("class.php");
?>
Edit Profile
echo "In myquery.php body
";
?>
Enter first or last name
echo "about to check _post for search2
";
if(isset($_POST['search2'])):
echo "found _post for search2
";
$status = "hidden";
$query = "select * from employee WHERE firstname='".$_POST['search']."' OR lastname='".$_POST['search']."' ";
echo "about to open DB
";
$emp = new EmployeeProfile();
$emp->openConnection();
echo "about to place find query
";
$result = mysqli_query($emp->openConnection(), $query);
echo "about to check for successful query
";
if($result->num_rows == 1):
echo "successful search query
";
?>
Edit your profile:
*Enter first name:
Enter middle name:
*Enter last name:
*Date of Birth:
*Age:
*School:
*Highest Educational Attainment:
*Year Last Attended:
*Skill(s):
Previous Company:
Position:
*Date of Employment:
* - Required
echo "about to check for submit second form
";
if(isset($_POST['submit'])):
echo "found submit for second form
";
$firstname = $_POST['firstname'];
$middlename = $_POST['middlename'];
$lastname = $_POST['lastname'];
$dateofbirth = $_POST['month']. " ".$_POST['days']. ", ".$_POST['year'];
$age = $_POST['age'];
$school = $_POST['school'];
$educ = $_POST['educ'];
$yearattended = $_POST['yearattended'];
$skills = $_POST['skills'];
$prevcompany = $_POST['prevcompany'];
$position = $_POST['position'];
$dateofemployment = $_POST['empmonth']. " ".$_POST['empyear'];
$row = $result->fetch_assoc();
$usr = $row["firstname"];
$query2 =
"UPDATE employee
SET firstname='$firstname',
middlename='$middlename',
lastname='$lastname',
dateofbirth='$dateofbirth',
age='$age',
school='$school',
educ='$educ',
yearattended='$yearattended',
skills='$skills',
prevcompany='$prevcompany',
position='$position',
dateofemployment='$dateofemployment',
WHERE firstname='$usr'";
echo "about to update DB
";
mysqli_query($emp->openConnection(), $query2);
endif;
else:
echo "search query failed
";
echo "Profile not found";
endif;
endif;
?>
No comments:
Post a Comment