Log in

View Full Version : Resolved passing variables through a form



mrabin
12-30-2010, 05:59 PM
This is what I want to happen:

if "one" is the text in the first text field, and the first button is clicked, post.php returns 1one

if "two" is the text in the second text field, and the second button is clicked, post.php returns 2two.

This is what happens right now:

the first button returns "2" regardless of what the input field is.

the second button works as I want

This is the code

designers.php


<?php
$result = mysql_query("SELECT * FROM designers");

$designercounter = 1;
while($row = mysql_fetch_array($result)){

$name ='designer'.$designercounter;
echo"<div id='header'><p>" . $row['designer_name'] . "</p></div>";
echo"<form action = 'post.php' method ='POST' >";
echo"<input type='submit' name='submit' value = 'Change name'>";
echo"<input type='text' name='designername' size='30' >";
echo"<input type='hidden' name='pasedvariable' value='".$designercounter."'> </form>";

$designercounter++ ;
}

?>

post.php



<?php

$designerid = $_POST['pasedvariable'];
$designername = $_POST['designername'];
echo $designerid;
echo $designername;

?>


Any help or guidance would be appreciated

Nile
12-30-2010, 08:57 PM
I don't completely understand what you want, isn't it as simple as:


if($_POST['first'] == "one" && isset($_POST['first_button'])){ echo "1one"; }

if($_POST['second'] == "two" && isset($_POST['second_button'])){ echo "2two"; }

mrabin
12-30-2010, 09:41 PM
the reason that I'm echoing those two is just to test that they've been properly passed to post.php, which isn't the case right now.

I want the values that are in 'designername' and 'pasedvariable' to be displayed

to me it seems logical that when I click on the first button, post.php would echo 1($designercounter = 1 for the first iteration of the while loop) followed by what is in the 'designername' textField.

but instead it just echos 2, which is $designercounter for the second iteration of the while loop.

Here's the link, http://www.unlikerabi.com/envied/admin/featureddesigners.php

sorry for being a bit unclear with the original post.

Nile
12-30-2010, 09:57 PM
The page you linked to is asking me for a username and a password

mrabin
12-30-2010, 10:40 PM
Ah yes, sorry. Should be available now.

Nile
12-30-2010, 10:42 PM
For one, your HTML is invalid. Fix that up:


echo"<input type='hidden' name='pasedvariable' value='".$designercounter."' /></form>";
http://validator.w3.org/check?uri=http://www.unlikerabi.com/envied/admin/featureddesigners.php&charset=(detect+automatically)&doctype=Inline&group=0

VijayKanta
12-31-2010, 06:37 AM
It works for me properly. You should just make this thread "Solved".

mrabin
01-02-2011, 11:57 PM
Thanks for the help. Nile you where right, that's all I had to change, I'll start using the html validator for everything.

Nile
01-03-2011, 12:01 AM
No problem, I'm glad to help :D

Here on DD, we like to keep things organized. In an effort to do so, you have the option to set a thread to resolved when an issue is fixed. To make the status of the thread resolved:
1. Go to your first post
2. Edit your first post
3. Click "Go Advanced"
4. In the dropdown next to the title, select "RESOLVED"