Jump to content

form actions with variables


TeddyKiller

Recommended Posts

Here is an example..

$x = 'hello'; 
$y = 'goodbye';
echo "<a href=\"main.php?username=$x&password=$y&action=shop\">stuff</a>";

The href would technically be.. main.php?username=hello&password=goodbye&action=shop

which works

 

Though, if I had..

$x = 'hello'; 
$y = 'goodbye';
echo "<form method=\"get\" action=\"main.php?username=$x&password=$y&action=shop\">\n";

What would the action actually be? The problem is.. even though its the same link, href's work. Form actions don't. When I try it with a form action.. I get "You are not logged in."

The code behind that is

if (empty($username)) die("You are not logged in.<br>\n");"

I'm honestly assuming it's not getting $x and $y values in the action link.

 

Can anyone help me?

Link to comment
https://forums.phpfreaks.com/topic/195387-form-actions-with-variables/
Share on other sites

I changed GET, to POST, and all the $_GETs to posts too. Now it recieves no results.

The action is / because technically the page is the URL that I had problems with.

It doesn't say theres no items found either. It just literally.. refreshes basically.

 

Can you help me?

case "weapon":
        //Check in case somebody entered 0
        $_POST['fromprice'] = ($_POST['fromprice'] == 0)?"":$_POST['fromprice'];
        $_POST['toprice'] = ($_POST['toprice'] == 0)?"":$_POST['toprice'];

        
        //Construct query
        $query = "select `id`, `name`, `slot`, `price`, `type`, `bonus`, `target`, `attr`, `effect`, `value`, `descript` from `items` where ";
        $query .= ($_POST['name'] != "")?"`name` LIKE  ? and ":"";
        $query .= ($_POST['fromprice'] != "")?"`price` >= ? and ":"";
        $query .= ($_POST['toprice'] != "")?"`price` <= ? and ":"";        
        $query .= "`type`='weapon' order by `price` asc";
        
        //Construct values array for adoDB
        $values = array();
        if ($_POST['name'] != "")
        {
            array_push($values, "%".trim($_POST['name'])."%");
        }
        if ($_POST['fromprice'])
        {
            array_push($values, intval($_POST['fromprice']));
        }
        if ($_POST['toprice'])
        {
            array_push($values, intval($_POST['toprice']));
        }
        
        $query = $db->execute($query, $values); //Search!
        
        $q = $db->execute("select * from `users` where `id`=?", array($player->id));
        $r = $q->fetchrow();
        if($r['gender'] == 'male'){$sirmad = 'sir';}else{$sirmad = 'madam';}
        echo "<fieldset>";
        echo "<legend><b>Shop Keeper:</b></legend>\n";
        echo "<i>What would you like to see, ".$sirmad."?</i><br /><br />\n";
        echo "<form method=\"post\" action=\"\">\n";
        echo "<table width=\"100%\">\n";
        echo "<tr>\n<td width=\"40%\">Name:</td>\n";
        echo "<td width=\"60%\"><input type=\"text\" name=\"name\" value=\"" . stripslashes($_POST['name']) . "\" /></td>\n";
        echo "</td>\n</tr>";
        echo "<tr>\n<td width=\"40%\">Price:</td>\n";
        echo "<td width=\"60%\"><input type=\"text\" name=\"fromprice\" size=\"4\" value=\"" . stripslashes($_POST['fromprice']) . "\" /> to <input type=\"text\" name=\"toprice\" size=\"4\" value=\"" . stripslashes($_POST['toprice']) . "\" /></td>\n";
        echo "</td>\n</tr>";
        echo "<tr>\n<td width=\"40%\">Type:</td>\n";
        echo "<td width=\"60%\"><select name=\"act\" size=\"2\">\n";
        echo "<option value=\"weapon\" selected=\"selected\">Weapons</option>\n";
        echo "<option value=\"head\">Headgear</option>\n";
        echo "<option value=\"shield\">Shields</option>\n";
        echo "<option value=\"neck\">Neck</option>\n";
        echo "<option value=\"shoulders\">Shoulders</option>\n";
        echo "<option value=\"body\">Body</option>\n";
        echo "<option value=\"arm\">Arms</option>\n";
        echo "<option value=\"wrists\">Wrist</option>\n";
        echo "<option value=\"hands\">Hands</option>\n";
        echo "<option value=\"finger\">Fingers</option>\n";
        echo "<option value=\"legs\">Legs</option>\n";
        echo "<option value=\"feet\">Feet</option>\n";
        echo "<option value=\"pet\">Pets</option>\n";
        echo "</select></td>\n</tr>\n";
        echo "<tr>\n<td></td>";
        echo "<td><input type=\"submit\" value=\"Submit\" /></td>\n</tr>";
        echo "</table>";
        echo "</form>\n";
        echo "</fieldset>";
        echo "<br /><br />";
        echo "<b>Shop Keeper:</b><br />\n";
        echo "<i>Here's our collection:</i><br /><br />\n";
        
        if ($query->recordcount() == 0)
        {
            echo "No items found! Try changing your search criteria.";
        }
        else
        {
            while ($item = $query->fetchrow())
            {
                echo "<fieldset>\n";
                echo "<legend><b>" . ucwords($item['name']) . "</b></legend>\n";
                echo "<table width=\"100%\">\n";
                echo "<tr><td width=\"85%\">";
                echo $item['descript'] . "\n<br />";
                echo "</td><td width=\"15%\">";
                echo "<b>Price:</b> " . $item['price'] . "<br />";
                echo "<a href=\"?act=buy&id=" . $item['id'] . "\">Buy</a><br />";
                echo "</td></tr>\n";
                echo "</table>";
                echo "</fieldset>\n<br />";
            }
        }
        break;

Archived

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

×
×
  • 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.