Jump to content

Archived

This topic is now archived and is closed to further replies.

dadoef

Problem with form

Recommended Posts

First my code
[code]
include "database.php";
$database=new MySQLDB();
$modules=$database->getBrasam();
echo "<form method=post action=usercreate.php>\n";
if($_POST[modules]=="")
{
    echo "<select name=modules>\n";
    for($i=0;$i<count($modules);$i++)
    {
        echo "<option value=$modules[$i]>$modules[$i]</option>\n";
    }
    echo "</select><br>\n";
}
else
{
    if($_POST[LT]=="" || $_POST[PORT]=="" || $_POST[vp]=="" || $_POST[vc]="")
    {
        echo $_POST[modules]."<br>";
        echo "<INPUT TYPE=hidden name=modules value=$_POST[modules]>";
        echo "LT:<INPUT TYPE=text NAME=LT SIZE=4>";
        echo " PORT:<INPUT TYPE=text NAME=PORT SIZE=4>";
        echo " VP: <INPUT TYPE=text NAME=vp SIZE=4>";
        echo " VC: <INPUT TYPE=text NAME=vc SIZE=4><BR>";
    }
    else
    {
        //echo $_POST[veecee]."<br>";
        if($_POST[moduleend]=="")
        {
            echo $_POST[modules]."<br>";
            echo "<INPUT TYPE=hidden name=modules value=$_POST[modules]>";
            echo "<INPUT TYPE=hidden name=PORT value=$_POST[PORT]>\n";
            echo "<INPUT TYPE=hidden name=LT value=$_POST[LT]>\n";
            echo "<INPUT TYPE=hidden name=vp value=$_POST[vp]>\n";
            echo "<INPUT TYPE=hidden name=vc value=$_POST[vc]>\n";
            echo "LT= $_POST[LT] PORT= $_POST[PORT] VP= $_POST[vp] VC= $_POST[vc]<br>\n";
            echo "<select name=modules>\n";
            for($i=0;$i<count($modules);$i++)
            {
                echo "<option value=$modules[$i]>$modules[$i]</option>\n";
            }
            echo "</select><br>\n";
        }
    }
}
echo "<INPUT TYPE=submit VALUE=Verzenden>";
echo "</form>";
[/code]
Now the problem I have is the following, every time I print this it doesn't echo the $_POST[vc] anymore?
I can't see anything wrong with my code?
Anyone has an idea?

Share this post


Link to post
Share on other sites
Well I can't really understand what your script does but there's a proper way to echo HTML and variables

you have:
[code]
echo "<INPUT TYPE=hidden name=vc value=$_POST[vc]>\n";
[/code]

try changing it into:

[code]
echo "<input type='hidden' name='vc' value='" . $_POST['vc'] . "'>\n";
[/code]

Im not sure if this will fix your problem but this way you kind of break out of the echo which is better for variabeles I believe. I've had problems with that.

if it doesnt work ->

Explain a bit what your code does (use comments) and what is actually done (information is inserted using a form)

Share this post


Link to post
Share on other sites
[code] echo "<input type='hidden' name='vc' value='" . $_POST['vc'] . "'>\n";[/code]
I have tried this before but this gives me the following error.
[code]Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in usercreate.php on line 46[/code]
I need to make a form which does a kind of refresh every page.
Every step it checks if the previous form fields aren't blank, then you can go to the next step.
In the next step there is a following field and it echo's the previous field. Normally, the next field can't be displayed if one of the values is blank but this one does.
The weird part is, if I use get it shows the value in the addressbar usercreate.php?vc=... but if I do a $_GET[vc] it doesn't return the value.
Any ideas?

Share this post


Link to post
Share on other sites
Put these two debug statements at the start of the script that proceeses the form:
[code]<?php
echo '<pre> $_POST Array: ' . htmlentities(stripslashes(print_r($_POST,true))) . '</pre>';
echo '<pre> $_GET Array: ' . htmlentities(stripslashes(print_r($_GET,true))) . '</pre>';
?>[/code]

See what is displayed on the screen and see if you can see what the problem is.

Ken

Share this post


Link to post
Share on other sites
echo "<form method=post action=usercreate.php>\n";

change to

echo "<form method='post' action='usercreate.php'>\n";


[code]
include "database.php";
$database=new MySQLDB();
$modules=$database->getBrasam();
echo "<form method='post ' action='usercreate.php'>\n";
if($_POST[modules]=="")
{
    echo "<select name='modules'>\n";
    for($i=0;$i<count($modules);$i++)
    {
        echo "<option value='$modules[$i]'>$modules[$i]</option>\n";
    }
    echo "</select><br>\n";
}
else
{
    if($_POST[LT]=="" || $_POST[PORT]=="" || $_POST[vp]=="" || $_POST[vc]="")
    {
        echo $_POST[modules]."<br>";
        echo "<INPUT TYPE='hidden' name='modules' value='".$_POST[modules]."'>";
        echo "LT:<INPUT TYPE='text' NAME='LT' SIZE='4'>";
        echo " PORT:<INPUT TYPE='text' NAME='PORT' SIZE='4'>";
        echo " VP: <INPUT TYPE='text' NAME='vp' SIZE='4'>";
        echo " VC: <INPUT TYPE='text' NAME='vc'SIZE='4'><BR>";
    }
    else
    {
        //echo $_POST[veecee]."<br>";
        if($_POST[moduleend]=="")
        {
            echo "'.$_POST[modules].'"<br>";'".$_POST[LT]."'>\n";
            echo "<INPUT TYPE='hidden' name='vp' value='".$_POST[vp]."'>\n";
            echo "<INPUT TYPE='hidden' name='vc' value='".$_POST[vc]"'.>\n";
            echo "LT= $_POST[LT] PORT= '".$_POST[PORT]."' VP= '".$_POST[vp]."' VC= '".$_POST[vc]."'<br>\n";
            echo "<select name='modules'>\n";
            for($i=0;$i<count($modules);$i++)
            {
                echo "<option value='".$modules[$i]."'>$modules[$i]</option>\n";
            }
            echo "</select><br>\n";
        }
    }
}
echo "<INPUT TYPE='submit' VALUE='Verzenden'>";
echo "</form>";
[/code]

Share this post


Link to post
Share on other sites

×

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.