jaady
April 17, 2015, 11:13pm
1
I am trying to populate a form with the data collected from another page.
I run a select * query in a page, format it into a table and added a hyperlink at the end of the $row. The idea is to pull this record out and bring it into my update form so I can update information in the record.
the problem that I am having is no matter what $row I select and click the hyperlink I always end up getting the last record of my database and not the record that I am trying to select. I’ve been playing around for a while and not getting any closer to figure it out. any idea whats happening?
update
the receiving input field in my table on the other page:
You would need to show some code. The $row[‘field’] would need to be in the WHILE loop.
jaady
April 18, 2015, 12:45am
3
//query to populate employee form//
$query = "SELECT * FROM employee ORDER BY firstname ASC";
$result = mysqli_query($dbc, $query);
echo'<table class="tblviewemp" >';
echo '<thead>';
echo '<tr class="tblviewemp">';
echo'<th class="dataH" id="emppicthumb">Employee Pic </th>';
echo'<th class="dataH"> First Name</th>';
echo'<th class="dataH">Last Name </th>';
echo'<th class="dataH"> ID</th>';
echo'<th class="dataH"> Update</th>';
echo '</thead>';
while ($row = mysqli_fetch_array($result)) {
// Display the employee data
echo '<tr>';
//echo '<td class="thumb"><img src="' . EMP_UPLOADPATH . $row['employeepic'] . '" alt="Employee image" /></td>';
echo '<td class="data">' . $row['firstname'] . '</td>';
echo '<td class="data">' . $row['lastname'] . '</td>';
echo '<td class="data">' . $row['employeeid'] . '</td>';
echo '<td><a class="update" href="update_employee.php?employeeid=' .
$row['employeeid'] . '&firstname='. $row['firstname'] . '&lastname=' . $row['lastname'] .'">update</a></td>';
}
echo '</tr>';
echo'</table>';
and the receiving end is:
<form>
<label for="employeeid" class="label" >Employee ID:</label>
<input name="employeeid" type="text" required class="input" id="employeeid" value="<?php echo $_GET['employeeid']; ?>"/>
<label for="firstname" class="label" >First Name:</label>
<input name="firstname" type="text" required class="input" id="firstname" value="<?php echo $_GET['firstname']; ?>"/>
<label for="lastname" class="label" >Last Name:</label>
<input name="lastname" type="text" required class="input" id="lastname" value="<?php echo $_GET['lastname']; ?>" />
</form>
jaady
April 18, 2015, 12:49am
4
ok this didn’t print out properly… let me try again
the sending script is:
//query to populate employee form//
$query = "SELECT * FROM employee ORDER BY firstname ASC";
$result = mysqli_query($dbc, $query);
echo'<table class="tblviewemp" >';
echo '<thead>';
echo '<tr class="tblviewemp">';
echo'<th class="dataH" id="emppicthumb">Employee Pic </th>';
echo'<th class="dataH"> First Name</th>';
echo'<th class="dataH">Last Name </th>';
echo'<th class="dataH"> ID</th>';
echo'<th class="dataH"> Update</th>';
echo '</thead>';
while ($row = mysqli_fetch_array($result)) {
// Display the employee data
echo '<tr>';
//echo '<td class="thumb"><img src="' . EMP_UPLOADPATH . $row['employeepic'] . '" alt="Employee image" /></td>';
echo '<td class="data">' . $row['firstname'] . '</td>';
echo '<td class="data">' . $row['lastname'] . '</td>';
echo '<td class="data">' . $row['employeeid'] . '</td>';
echo '<td><a class="update" href="update_employee.php?employeeid=' .
$row['employeeid'] . '&firstname='. $row['firstname'] . '&lastname=' . $row['lastname'] .'">update</a></td>';
}
echo '</tr>';
echo'</table>';
and the receiving form is:
<form>
<label for="employeeid" class="label" >Employee ID:</label>
<input name="employeeid" type="text" required class="input" id="employeeid" value="<?php echo $_GET['employeeid']; ?>"/>
<label for="firstname" class="label" >First Name:</label>
<input name="firstname" type="text" required class="input" id="firstname" value="<?php echo $_GET['firstname']; ?>"/>
<label for="lastname" class="label" >Last Name:</label>
<input name="lastname" type="text" required class="input" id="lastname" value="<?php echo $_GET['lastname']; ?>" />
</form>
jaady
April 18, 2015, 12:51am
5
for some reason the first couple of line don’t want to print in here: trying again with the missing lines:
<label for="employeeid" class="label" >Employee ID:</label>
<input name="employeeid" type="text" required class="input" id="employeeid" value="<?php echo $_GET['employeeid']; ?>"/>
jaady
April 18, 2015, 12:55am
6
Well the site doesn’t want to print my first two line which are the same: label and input for employeeid
When viewing source, do you see correct info? Have you tried moving class=“update” after href=? I have not see <a href broken like that before.
jaady
April 18, 2015, 1:51am
8
You my friend are getting too good at this… That was the problem. the class between “a” and “href” caused the problem. its loading perfectly now. thanks a bunch. Oh! and I hate you hahahaha I been working on this and reading for like 4 hours and it took you 1 look to figure it out. you are quite skilled. thank you very much.
I’ve fixed the posts now.
To post code, either highlight it and use the </> button in the editor window, or place three backticks` on a line above your code, and three on a line below your code.
1 Like
system
Closed
July 18, 2015, 3:11pm
10
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.