html - PHP page does not load when I try to show an error message
Get the solution ↓↓↓I am trying to show a duplicate error on a form, but this function crashes the page and the page does not load. How can I configure file php.ini for this?
This is the function with that I am trying to show the error messages on the form page:
public function getError($error) {
if(!in_array($error, $this->errorArray)) {
$error = "";
}
return "<span class='errorMessage'>$error</span>";
}
This is the function which I am trying to use to get the error in the array:
private function validateEmails($em) {
$checkEmailQuery = mysqli_query($this->con,"SELECT email FROM member_forms WHERE email='$em'");
if(mysqli_num_rows($checkEmailQuery) != 0) {
array_push($this->errorArray, Strings::$emExists);
return;
}
}
These functions double-check with the database and if an error occurs,<?php echo $account->getError(Strings::$emExists); ?>
should display it, but it does not and the page doesn't load.
When the error occurs, it goes until the error, but it does not render anything and the body of the HTML page goes empty
HTML
<div class="form-group" style="padding-left: 0px;">
<p>
<?php echo $account->getError(Strings::$fnCharacters); ?>
<div class="col-md-3 indent-small">
<div class="form-group internal">
<input class="form-control" id="firstName"
name="firstName" type="text"
placeholder="First Name"
style="width: 180%;/*! padding-right: ; */margin: 0px 0px 0px 12px;"
value="<?php getInputValue('firstName')?>" required>
</div>
</div>
<div class="col-md-3 indent-small"
style="margin-left: 15px;width: 25%;">
<div class="form-group internal">
<input class="form-control" id="lastName"
name="lastName" type="text" placeholder="Last Name"
style="width: 188%;/*! padding-left: 33px; */margin-left: 56px;"
value="<?php getInputValue('lastName')?>" required>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2 col-md-offset-2" for="email"
style="margin-left: 0;width: 28%;/*! float: left; */">E-mail
Address</label>
<div class="col-md-6">
<div class="form-group">
<div class="col-md-11">
<p>
<?php echo $account->getError(Strings::$emExists); ?>
<input class="form-control" id="email" name="email"
type="email" placeholder="Your E-mail..."
style="width: 156%;"
required>
</p>
</div>
</div>
</div>
</div>
Answer
Solution:
I have used that code you posted works totally fine on my local host. Have you checked the server used on your new hosting?
If it's different, then the same code might not work as expected on another server. There are several factors affecting that. Click here to get tips on that.
You can also use the phpinfo() function. It might help in further debugging.
Answer
Solution:
I'm pretty sure that this code should fix this error:
if (isset($_POST['Update'])) {
/* a bunch of code to insert into the DB */
// if inserted echo the following messges
if ($r) {
echo "<script> alert('Saved')</script>";
}else{
echo "<b>Oops! we have an issu </b>";
}
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: php undefined array key
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.