ckdoublenecks Posted August 18, 2010 Share Posted August 18, 2010 how do I code the submit into this form? echo "<form action='#' method='post'><b>Prerent Update :<br /><br /> <table border='1'> <tr> <th>dep</th> <th>tenant</th> </tr>"; while($row = mysql_fetch_assoc($result)) { echo "<tr> <td><input type='text' name='dep' value='" . $row['dep'] . "'></td> <td><input type='text' name='name' value='" . $row['name'] . "'></td> </tr>"; } echo "</table> // *** <input type="submit" name="submit" value="update record"/> // *** echo</form>"; } else{echo "No listing for appartment $apt.<br />Please select another.<br />";} } if(!empty($_POST["update"])) { $sql = "UPDATE testtable SET dep, name, amtpaid, prevbal, misc, tentpay, hudpay, datepaid WHERE apt='apt'"; mysql_query($sql) or die("Update query failed."); echo "Record for appartment ".$_POST["apt"]." has been updated ..."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/211023-how-to-submit/ Share on other sites More sharing options...
kenrbnsn Posted August 18, 2010 Share Posted August 18, 2010 Change the double quotes to single quotes in this block of lines. From: <?php echo "</table> // *** <input type="submit" name="submit" value="update record"/> // *** echo</form>"; ?> To: <?php echo "</table> // *** <input type='submit' name='submit' value='Update Record' /> // *** echo</form>"; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/211023-how-to-submit/#findComment-1100589 Share on other sites More sharing options...
ckdoublenecks Posted August 18, 2010 Author Share Posted August 18, 2010 I've been chastised for showing too much code but obviously I need to show it now. I'm selecting a record to update then changing the fields. Now it doesn't like the form I'm using at the bottom. It works in another program? Below is the error message: Parse error: syntax error, unexpected $end in C:\xampp\htdocs\hofiles\prerentupdate.php on line 58 <?php mysql_connect(localhost,root,""); mysql_select_db(test) or die( "Unable to select database"); if(!empty($_POST["submit"])) { $apt = $_POST['apt']; $query="SELECT * FROM testtable Where apt='$apt'"; $result=mysql_query($query); if(mysql_num_rows($result)) { echo "<form action='#' method='post'><b>Prerent Update :<br /><br /> <table border='1'> <tr> <th>dep</th> <th>tenant</th> <th>apt</th> <th>amt paid</th> <th>rent due</th> <th>prevbal</th> <th>misc</th> <th>tentpay</th> <th>hudpay</th> <th>date paid</th> </tr>"; while($row = mysql_fetch_assoc($result)) { echo "<tr> <td><input type='text' name='dep' value='" . $row['dep'] . "'></td> <td><input type='text' name='name' value='" . $row['name'] . "'></td> <td><input type='text' name='apt' value='" . $row['apt'] . "' readonly style='border:none;' onmouseup='this.blur()'></td> <td><input type='text' name='amtpaid' value='" . $row['amtpaid'] . "'></td> <td><input type='text' name='rentdue' value='" . $row['rentdue'] . "' readonly style='border:none;' onmouseup='this.blur()'>></td> <td><input type='text' name='prevbal' value='" . $row['prevbal'] . "'></td> <td><input type='text' name='misc' value='" . $row['misc'] . "'></td> <td><input type='text' name='tentpay' value='" . $row['tentpay'] . "'></td> <td><input type='text' name='hudpay' value='" . $row['hudpay'] . "'></td> <td><input type='text' name='datepaid' value='" . $row['datepaid'] . "'></td> </tr>"; } echo "</table> <input type='submit' name='submit' value='Update Record' /> echo</form>";?> } else{echo "No listing for appartment $apt.<br />Please select another.<br />";} } if(!empty($_POST["update"])) { $sql = "UPDATE testtable SET dep, name, amtpaid, prevbal, misc, tentpay, hudpay, datepaid WHERE apt='apt'"; mysql_query($sql) or die("Update query failed."); echo "Record for appartment ".$_POST["apt"]." has been updated ..."; } ?> <form method="post" action="#"> <br /> <input type="text" name="apt"/> <p> <input type="submit" name="submit" value="select apartment"/> </form> Quote Link to comment https://forums.phpfreaks.com/topic/211023-how-to-submit/#findComment-1100784 Share on other sites More sharing options...
phpology Posted August 18, 2010 Share Posted August 18, 2010 remove the ?> from this line: echo</form>";?> Quote Link to comment https://forums.phpfreaks.com/topic/211023-how-to-submit/#findComment-1100801 Share on other sites More sharing options...
ckdoublenecks Posted August 18, 2010 Author Share Posted August 18, 2010 We're getting there. The record selection works but when I change the fields and click the "update" button, which has "echo" by it, no update is performed and none indicated? Quote Link to comment https://forums.phpfreaks.com/topic/211023-how-to-submit/#findComment-1100841 Share on other sites More sharing options...
wildteen88 Posted August 18, 2010 Share Posted August 18, 2010 You're not updating anything within your SQL query $sql = "UPDATE testtable SET dep, name, amtpaid, prevbal, misc, tentpay, hudpay, datepaid WHERE apt='apt'"; mysql_query($sql) or die("Update query failed."); echo "Record for appartment ".$_POST["apt"]." has been updated ..."; You're listing the fields to update but not providing anyvalues. An update query is formatted like so UPDATE table SET some_field='new value', another_field='some other value' WHERE whatever='something' Quote Link to comment https://forums.phpfreaks.com/topic/211023-how-to-submit/#findComment-1100843 Share on other sites More sharing options...
ckdoublenecks Posted August 18, 2010 Author Share Posted August 18, 2010 Obviously I'm new to PHP. I don't know how to relate the value of the changed field to the update field. Can you look at the code and give an example of the amtpaid field coded into the update statement? Quote Link to comment https://forums.phpfreaks.com/topic/211023-how-to-submit/#findComment-1100855 Share on other sites More sharing options...
wildteen88 Posted August 18, 2010 Share Posted August 18, 2010 I'm guessing the new value is in $_POST['amtpaid'] variable. Your query will be like this $sql = "UPDATE testtable SET amtpaid = '" . mysql_real_escape_sting($_POST['amptpaid']) . "' WHERE apt='" . mysql_real_escape_string($_POST['apt'] . "'"; mysql_query($sql) or die("Update query failed."); echo "Record for appartment ".$_POST["apt"]." has been updated ..."; Quote Link to comment https://forums.phpfreaks.com/topic/211023-how-to-submit/#findComment-1100858 Share on other sites More sharing options...
ckdoublenecks Posted August 18, 2010 Author Share Posted August 18, 2010 I got this message: Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\hofiles\prerentupdate.php on line 50 <?php mysql_connect(localhost,root,""); mysql_select_db(test) or die( "Unable to select database"); if(!empty($_POST["submit"])) { $apt = $_POST['apt']; $query="SELECT * FROM testtable Where apt='$apt'"; $result=mysql_query($query); if(mysql_num_rows($result)) { echo "<form action='#' method='post'><b>Prerent Update :<br /><br /> <table border='1'> <tr> <th>dep</th> <th>tenant</th> <th>apt</th> <th>amt paid</th> <th>rent due</th> <th>prevbal</th> <th>misc</th> <th>tentpay</th> <th>hudpay</th> <th>date paid</th> </tr>"; while($row = mysql_fetch_assoc($result)) { echo "<tr> <td><input type='text' name='dep' value='" . $row['dep'] . "'></td> <td><input type='text' name='name' value='" . $row['name'] . "'></td> <td><input type='text' name='apt' value='" . $row['apt'] . "' readonly style='border:none;' onmouseup='this.blur()'></td> <td><input type='text' name='amtpaid' value='" . $row['amtpaid'] . "'></td> <td><input type='text' name='rentdue' value='" . $row['rentdue'] . "' readonly style='border:none;' onmouseup='this.blur()'></td> <td><input type='text' name='prevbal' value='" . $row['prevbal'] . "'></td> <td><input type='text' name='misc' value='" . $row['misc'] . "'></td> <td><input type='text' name='tentpay' value='" . $row['tentpay'] . "'></td> <td><input type='text' name='hudpay' value='" . $row['hudpay'] . "'></td> <td><input type='text' name='datepaid' value='" . $row['datepaid'] . "'></td> </tr>"; } echo "</table> <input type='submit' name='update' value='Update Record' /> echo</form>"; } else{echo "No listing for appartment $apt.<br />Please select another.<br />";} } if(!empty($_POST["update"])) { $sql = "UPDATE testtable SET dep = '" . mysql_real_escape_sting($_POST['dep']) . "', name = '" . mysql_real_escape_sting($_POST['name']) . "', amtpaid = '" . mysql_real_escape_sting($_POST['amptpaid']) . "', prevbal = '" . mysql_real_escape_sting($_POST['prevbal']) . "', misc = '" . mysql_real_escape_sting($_POST['misc']) . "', tentpay = '" . mysql_real_escape_sting($_POST['tentpay']) . "', hudpay = '" . mysql_real_escape_sting($_POST['hudpay']) . "', datepaid = '" . mysql_real_escape_sting($_POST['datepaid']) . "' WHERE apt='" . mysql_real_escape_string($_POST['apt'] . "'"; mysql_query($sql) or die("Update query failed."); echo "Record for appartment ".$_POST["apt"]." has been updated"; } ?> <form method="post" action="#"> <br /> <input type="text" name="apt"/> <p> <input type="submit" name="submit" value="select apartment"/> </form> Quote Link to comment https://forums.phpfreaks.com/topic/211023-how-to-submit/#findComment-1100873 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.