Jump to content

Recommended Posts

Post your error messages here along with your code then we'll be able to help you a lot more. Basically fi you want to see if certain field is emtpy the use this:
[code]if(!isset($_POST['FieldName']) || empty($_POST['fileName']))
{
    echo "PLease fill in all fields thank you!;
}[/code]
a quick way i found to check in general is

foreach($_POST[] as $post) {
if ($post == '') {
$error("Blank field detected");
}
}

Then you just do
if (!$error) {
all code to insert/upload the data
} else {
normal form to display and echo all the variables abck into the boxes to save the user som hastle
}

As far as i've tested on my own pages that works :)
the var $post is the one that has the value of the field right?

And what does the ! behind $error or isset as I sometimes see?

it gives this error:


Warning: Invalid argument supplied for foreach() in /home/www/infocenter.awardspace.com/inter/ps2ub/insert.php on line 21
[code]   <?php    if (isset($_POST['Submit'])) {
           
        include 'db.php';

        $n=$_POST['textfield3'];
        $s=$_POST['radiobutton1'];
        $w=$_POST['radiobutton'];        
        $c=$_POST['textfield'];
        $p=$_POST['textfield2'];
        $e=$_POST['textfield22'];
        
        foreach($_POST[] as $post) {
        if ($post == '') {
        $error("Blank field detected");
        }
        }
        
        if (!$error) {
        $query="INSERT INTO usbextreme (name,system,work_status,comments,postedby,email) VALUES     ('$n','$s','$w','$c','$p','$e')";        
        $exec=mysql_query($query,$connect);
        } else {
        echo "try again";
        }
        echo '</p>
<p align="center"><strong>Success</strong></p>
<p align="center"><a href="submit.php">Add another game</a> | <a href="index.php">Check game list ';
        } else {
        echo "<center><b>This page should only be accessed when submitting a game<b></center>";
        }
?>[/code]
if ($error) {}
means if there is a value in $error then do what ever is between the brakcets

! means NOT.. therefore

if (!$error) {}

means if there is NO value to $error then do somthing

i think i did that wrong and should have used $_POST instead of $_POST[] in the foreach loop..
[a href=\"http://infocenter.awardspace.com/inter/ps2ub/submit2.php\" target=\"_blank\"]http://infocenter.awardspace.com/inter/ps2ub/submit2.php[/a]
[a href=\"http://infocenter.awardspace.com/inter/ps2ub/insert.php\" target=\"_blank\"]http://infocenter.awardspace.com/inter/ps2ub/insert.php[/a]

insert.php:

[code]<?php    if (isset($_POST['Submit'])) {
           
        include 'db.php';

        $n=$_POST['textfield3'];
        $s=$_POST['radiobutton1'];
        $w=$_POST['radiobutton'];        
        $c=$_POST['textfield'];
        $p=$_POST['textfield2'];
        $e=$_POST['textfield22'];
        
        foreach($_POST as $post) {
        if ($post == '') {
        $error("Blank field detected"); //line 23
        }
        }
        
        if (!$error) {
        $query="INSERT INTO usbextreme (name,system,work_status,comments,postedby,email) VALUES             ('$n','$s','$w','$c','$p','$e')";        
        $exec=mysql_query($query,$connect);
        } else {
        echo "try again";
        }
        echo '</p>
<p align="center"><strong>Success</strong></p>
<p align="center"><a href="submit.php">Add another game</a> | <a href="index.php">Check game list ';
        } else {
        echo "<center><b>This page should only be accessed when submitting a game<b></center>";
        }
?>[/code]

Whats the problem?
when submitting NO data i get error:
Fatal error: Call to undefined function: () in /home/www/infocenter.awardspace.com/inter/ps2ub/insert.php on line 23

well im confused on this one because error line is in red below yet nothing at all wrong with it!


} else {
[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--] echo "try again";[!--colorc--][/span][!--/colorc--]
}


But if i submit data i get success..
wow, i fixed it. i changed from $error("...") to $error="..." and then tested with different data, on different boxes and works fine, now the problem is that if there is one form to fill up it says try again, but I only want it to try again if one of the required fields arent filled up, they are the ones with stars *. How can i do that?

Ignore the success message as it always appear if the submit button is clicked.

One more thing, is there any code to make the browser return to a previous page without deleting the values written on the fields?
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.