I am having a small problem with this script I am working on.
First it receives some values from a small form. It then inserts them into a table and returns the values to a HTML table directly above the input form.
When the new table data is printed I have a function which is included in the functions.php file. It is supposed to connect to the database and check to see if a certain field equals Y or N for each record. If it returns N I want a checkbox to print, otherwise YES should print.
Basically I need help figuring out how to get the checkno variable into the function
I hope you can help me with this problem.
// Functions.php
// Provides a checkbox and verifies if check has been cashed.
// If it has no checkbox will display, and will return YES.
function checkcash($checkno) {
global $link;
mysql_select_db("dbname", $link);
$sql = "SELECT cash FROM tablename WHERE checkno = '$checkno'";
if ($checkno == "N") {
echo "<input type='checkbox' name='cash' value='Yes'>";
}
else {
echo "YES";
}
}
// Master.php
include $DOCUMENT_ROOT . "/checkbook/functions.php";
if ($Submit) {
$link = mysql_connect("host","user","");
mysql_select_db("dbname", $link);
$insert_check = "INSERT into tablename SET
cash = '$cash',
void = '$void',
checkno = '$checkno',
date = '$date',
acctno = '$acctno',
payto = '$payto',
amount = '$amount'";
mysql_query($insert_check);
$sql = "SELECT * FROM tablename";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
}
for($x=1;$x<=$num_rows;$x++) {
$row = mysql_fetch_array($result);
print "<tr class='check_tr'>";
print "<td>" . checkcash($row[checkno]) . "</td>";
print "<td>$row[void]</td>";
print "<td>$row[checkno]</td>";
print "<td>$row[date]</td>";
print "<td>$row[acctno]</td>";
print "<td>$row[payto]</td>";
print "<td>$row[amount]</td>";
print "<td>$row[balance]</td>";
print "<td>$row[bank]</td>";
print "</tr>";
}