Fields Empty
Hello,
i'm trying to do a check to see if the textboxes on my php form are empty I tried this code
i'm trying to do a check to see if the textboxes on my php form are empty I tried this code
Code: Select all
Even when I fill in all the fields I still get an error saying You need to fill in all the fields! can anyone help please?if(isset($_POST['submit']) ) {
if ($name="" && $gotdate="" && $paydate="" && $money="" && $number="" && $info="") {
include('scripts/connect.php');
$name = $_POST['name'];
$gotdate = $_POST['gotdate'];
$paydate = $_POST['paydate'];
$money = $_POST['money'];
$number = $_POST['number'];
$info = $_POST['info'];
$sql = "INSERT INTO customers (name, gotdate, paydate, money, number, info)
VALUES ('$name','$gotdate','$paydate','$money','$number','$info')";
$result = mysql_query($sql);
echo "<h3>Thank you, Information Saved!.</h3> $form";
}
else
echo "You need to fill in all the fields!<br>. $form ";
}
else
echo $form;
Add this
Code: Select all
After
$name = $_POST['name'];
$gotdate = $_POST['gotdate'];
$paydate = $_POST['paydate'];
$money = $_POST['money'];
$number = $_POST['number'];
$info = $_POST['info'];
Code: Select all
Also you should trim all the user input. Something like this
if(isset($_POST['submit']) ) {
Code: Select all
$name = trim($_POST['name']);
You can find me on Facebook or on Skype mihai_92b
I tried this but it still says the same error.
Code: Select all
if(isset($_POST['submit']) ) {
$name = $_POST['name'];
$gotdate = $_POST['gotdate'];
$paydate = $_POST['paydate'];
$money = $_POST['money'];
$number = $_POST['number'];
$info = $_POST['info'];
if ($name="" && $gotdate="" && $paydate="" && $money="" && $number="" && $info="") {
include('scripts/connect.php');
$sql = "INSERT INTO customers (name, gotdate, paydate, money, number, info)
VALUES ('$name','$gotdate','$paydate','$money','$number','$info')";
$result = mysql_query($sql);
echo "<h3>Thank you, Information Saved!.</h3> $form";
}
else
echo "You need to fill in all the fields!<br>. $form ";
}
else
echo $form;
?>
A few things here:
Firstly, you're using the single-equal "=" assignment operator instead of the double-equal "==" comparison operator. So in your if when you're checking the contents of your fields, use "==".
Secondly, and I might be misunderstanding this, you're sending a query to the database if all of the fields are empty... Should't it be only if all the fields are full?
Also, since you don't want to send the data only if ALL of the fields are filled, you'll want to use the "||" OR operator, not "&&" AND
Firstly, you're using the single-equal "=" assignment operator instead of the double-equal "==" comparison operator. So in your if when you're checking the contents of your fields, use "==".
Secondly, and I might be misunderstanding this, you're sending a query to the database if all of the fields are empty... Should't it be only if all the fields are full?
Also, since you don't want to send the data only if ALL of the fields are filled, you'll want to use the "||" OR operator, not "&&" AND
for easy check if a string is empty you can use
Code: Select all
$string1 = $_POST["date"]; // Declare string1 with stuff from the form date
$string2 = $_POST["name"];
if ($string != "" && $string2 != ""){ // Checks that string1 and string2 is not empty
//Do code for not empty string
}
im not at home at the moment just wondered if this would work.
Code: Select all
if ($username == "Mark") {
Mark's menu
}
else
echo "other users menu";
Mark wrote:im not at home at the moment just wondered if this would work.It should work just fine, it might be a little unsecure but it should work
Code: Select allif ($username == "Mark") { Mark's menu } else echo "other users menu";
I user a textarea box to type my info in and when I go to view it goes all along one straight line this is the code I use how do I get it so it shows on different lines instead of one?
Code: Select all
<tr>
<td>Other Information:</td>
<td><?=$myrow["info"];?> </td>
</tr>
Mark wrote:I user a textarea box to type my info in and when I go to view it goes all along one straight line this is the code I use how do I get it so it shows on different lines instead of one?You could use explode to make a string into an array and then seperate it like that
Code: Select all<tr> <td>Other Information:</td> <td><?=$myrow["info"];?> </td> </tr>
Copyright Information
Copyright © Codenstuff.com 2020 - 2023