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'];

}

Link to comment
Share on other sites

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

Edited by ginerjm
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.