Fields Empty

17 posts Page 1 of 2
Contributors
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Fields Empty
Mark
Hello,
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
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;
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?
http://www.mbappz.com
User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

Re: Fields Empty
XTechVB
Add this
Code: Select all
    $name = $_POST['name'];
    $gotdate = $_POST['gotdate'];
    $paydate = $_POST['paydate'];
    $money = $_POST['money'];
    $number = $_POST['number'];
    $info = $_POST['info'];
After
Code: Select all
if(isset($_POST['submit']) )  {
Also you should trim all the user input. Something like this
Code: Select all
$name = trim($_POST['name']);
You can find me on Facebook or on Skype mihai_92b
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Re: Fields Empty
Mark
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;
?>
http://www.mbappz.com
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: Fields Empty
Shim
Find my programs on Softpedia
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: Fields Empty
comathi
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
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: Fields Empty
AnoPem
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
}
https://t.me/pump_upp
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Re: Fields Empty
Mark
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";
http://www.mbappz.com
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: Fields Empty
AnoPem
Mark wrote:
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";
It should work just fine, it might be a little unsecure but it should work
https://t.me/pump_upp
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Re: Fields Empty
Mark
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"];?>&nbsp;</td>
    </tr>
http://www.mbappz.com
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Re: Fields Empty
AnoPem
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?
Code: Select all
 <tr>
        <td>Other Information:</td>
        <td><?=$myrow["info"];?>&nbsp;</td>
    </tr>
You could use explode to make a string into an array and then seperate it like that
https://t.me/pump_upp
17 posts Page 1 of 2
Return to “Help & Support”