Jump to content

Problem with form


dadoef

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?
Link to comment
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)
Link to comment
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?
Link to comment
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
Link to comment
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]
Link to comment
Share on other sites

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.