Jump to content

Cannot store selected form row items in variables


BenjaminDisco

Recommended Posts

Hi guys,

 

Sorry im a bit of a noob when it comes to PHP but I just wondered if someone had an idea on how I could solve this PHP problem.

 

I have a PDO statement that gets all users from a database.

With the array of users from the database I create a foreach loop to display all of the users in a table which I want to use to select a specific user, enter a number in the row next to the user I select, then click submit and store the users name and also the number in vairables. I will use this information to populate another database later. 

 

My question is, I cant seem to reference the user or the number in the table to extract the user and number I enter. When I try and request the numbered entered in the index.php, it will only ever display a number if I enter a number for a the final user in the table. When I try and view the FullName it never works and I get 'Undefined index: FullName' error.

I also specified to 'POST in the form but it doesnt seem to be doing that. 

Does anyone have any ideas?

 

Thanks

 

//function.php

function getRequestors($tableName, $conn)

{

try {

$result = $conn->query("SELECT * FROM $tableName");

return ( $result->rowCount() > 0)

 

? $result

: false;

 

} catch(Exception $e) {

return false;

}

}

 

//form.php

<form action "index.php" method "POST" name='form1'>

<table border="1" style="width:600px">

<tr>

<th>Name</th>

<th>Number Entered</th>

<tr/>

<tr>

 

<?php foreach($users as $user) : ?>

 

 <td width="30%" name="FullName"><?php echo $user['FullName']; ?></td>

 <td width="30%"><input type="int" name="NumberedEntered"></td>

<td><input type="submit" value="submit"></td>

</tr>

<?php endforeach; ?>

</table>

</form>

 

//index.php

if ( $_REQUEST['NumberedEntered']) {

echo $_REQUEST['NumberedEntered'];

echo $_REQUEST['FullName'];

}

I think that type="int" is not valid for html. Also, if you have multiple elements in the same form it will only use the last one unless you make them an array <input name="myvarname[]"> (notice the square brackets).

This code is :

 

1 - too incomplete to analyze your problem.  Where was $users defined?  Dont' see it.

2 - for a newbie you sure have some knowledge of little-used syntaxes.  Why don't you use the more common (and preferred) syntax for 'foreach' and 'if' instead of the ones you are using?  Would make it easier for you to read and follow as well as for others.

3 - please post code properly should you decide to give us what we need to see

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.