PHP form validation with the same value
Get the solution ↓↓↓I faced a problem validating my PHP form where I described from location and to location, where they can't be same.
if (!isset($_POST["from"])){
$errorfrom="Select Departure Time";
$err = true;
}
else{
$from=$_POST["from"];
}
if (!isset($_POST["to"])){
$errorto="Select Departure Time";
$err = true;
}
else{
$to=$_POST["to"];
}
In the database, from and to are same, but they can't be same:
Answer
Solution:
If you don't want to allow users to choose same from and to location is not server stuff. In any case you must check locations like this:
if (!isset($_POST["from"])){
$errorfrom="Select Departure Time";
$err = true;
}else{
$from=$_POST["from"];
}
if (!isset($_POST["to"])){
$errorto="Select Departure Time";
$err = true;
}else{
$to=$_POST["to"];
}
if(strcmp($from, $to) !== 0){ //note that strcmp is case sensitive
$errorDescription="From and to location can not be the same";
$error = true;
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: mysqli::real_connect(): (hy000/2002): connection refused
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.