user3830570 user3830570 - 4 years ago 109
HTML Question

Table with database values and user input

So I've been wrestling with this issue on and off for quite a while now, and just like driving around lost in a strange city, I am finally breaking down for direction! I am developing table with values from a database, but also need a column that will process user input. I have been able to display the table but my input is not updating the necessary database element. Code below:

or die("Did Not Connect");
$query="SELECT * FROM $tbl2_name ORDER BY $tbl2_name.$col_name ASC";
or die("Query Not Working");
echo"<table border='1'
<form name='payments' action='' method='POST'>
<td class='update' colspan='5'>
<button data-theme='b' id='submit' type='submit'>Update</button>
<th class='profile'>Last Name</th>
<th class='profile'>First Name</th>
<th class='profile'>Saturday Payment Owing</th>
<th class='profile'>Enter Payment</th>
<th class='profile'>Saturday Balance</th>
while ($row=mysqli_fetch_assoc($result))
extract ($row);
<td class='profile'>$lastname</td>
<td class='profile'>$firstname</td>
<td class='profile'>$owingsat</td>
<td class='profile'><input type='number' name='paidsat' value=''/></td>
<td class='profile'>$owingsat-$paidsat</td>
echo "</form>";
echo "</table>";

This displays the table in the way I want. Having worked through the results of the following code, it seems that I am returning a null value, so I am thinking I have an issue with either the form action or the submit Update button, but can not find the solution after much experimentation and searching. Balance of code below:

$paidsat = $_POST['paidsat'];
if(($paidsat) != null)
$stmt = $cxn->prepare("UPDATE $tbl2_name SET paidsat = ? WHERE firstname=? and lastname=?");
$stmt->bind_param('sss', $paidsat, $firstname, $lastname);
$status = $stmt->execute();
if($status === true) //To check if the execute was successful
echo("<p class='click'>You have successfully added the payment for $firstname $lastname\n<br /></p>");
else echo"Not Successful";
else echo "<p class='click'>Make your changes as required</p>";

Everything comes to a crashing halt at the second if statement.....or should I say, although things look pretty, they don't function! Thanks in advance, appreciate any help!

Answer Source

Be sure you have a proper value for $tbl2_name checking


in your code before the update

and for debug try using a string concatenation like

"UPDATE " . $tbl2_name . "  SET paidsat = ? WHERE firstname=? and lastname=?";

and try use

  if( $paidsat  != NULL )

and last check if you have proper value for update

  paidsat = ? WHERE firstname=? and lastname=?


 var_dump( $paidsat);
 var_dump( $firstname);
 var_dump(  $lastname); 

and build a proper select for test if you value math the rows you think and test this select in you db console

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download