Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Generic User Avatar

questions about mysqli displaying variables


  • Please log in to reply
3 replies to this topic

#1 guitarzRwe

guitarzRwe

  •  Avatar image
  • Members
  • 6 posts
  • OFFLINE
  •  
  • Local time:01:51 AM

Posted 08 April 2023 - 03:58 PM

 

My project seems simple, update a couple of database tables, one from a little form, print a receipt
and echo out the receipt# and other values. The updates work but the values echoed are wrong or
absent. Cmon brave souls, tell me what I'm doin rong.

 

<!DOCTYPE html><html>
<head>
     <title>record payment</title>
<html><head>
<script type="text/javascript">
var monthNames = [ "January","February","March","April","May","June","July",
                   "August","September","October","November","December"     ];
var today = new Date();  
var date = monthNames[today.getMonth()] + " - " + today.getDate() + " - " + today.getFullYear();
</script>
</head>
<body><center>
Date:<script type="text/javascript">document.write(date);</script><p>
<img src="apt-pic.jpg" alt="apartment" height=100 width=300><p>
<?php
$link = mysqli_connect("localhost", "root", "", "homedb"); 
// Check connection
if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); }
 
$unit=$_POST['unit'];
$amtpaid=$_POST['amtpaid'];
$paidday=$_POST['paidday'];
$id = '';

$amtpaid = 0;
$amtdue =  0;
$dueday = '';

$prevbal =  0;
$latechg =  0;

$secdep =  0;
$damage =  0;
$courtcost =  0;
$nsf =  0;
$paidday = ''; 

$bizname = '';
$bizstreet = '';
$bizcity = '';
$bizzip = '';
$bizemail = '';
$receiptno = 0;
$owed = $amtdue - $amtpaid;
$due= '';
/* Perform a query, check for error */
$sql = "UPDATE crttbl SET 
receiptno = receiptno + 1 where id=1";

echo "receipt# $receiptno";  // line 50

 if(mysqli_query($link, $sql)){ echo "receiptno updated"; } 
else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); }

$due = $amtdue + $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf;

  /* if no pay or part pay, add $35 to latechg field and amount not paid to prevbal field */
    if ($amtpaid < $due) { $prevbal = $due - $amtpaid; $latechg = $latechg + 35.00; 
$amtpaid = 0; $secdep = 0; $damage = 0;  $courtcost = 0;
$nsf = 0; $hudpay = 0; $comments = ' '; $paidday = ' ';	}
/* if amt paid = amt due,  */
    if ($amtpaid == $due) { $amtpaid = 0; $prevbal =  0; $latechg = 0;; 
 $secdep = 0; $damage = 0;  $courtcost = 0;
$nsf = 0; $hudpay = 0; $comments = ' '; $paidday = ' '; }  
/* if over-payment subtract over-payment from prevbal */
    if ($amtpaid > $due)  { $prevbal = $amtpaid - $due;
$amtpaid = 0; $latechg = 0; $secdep = 0; $damage = 0;  $courtcost = 0;
$nsf = 0; $hudpay = 0; $comments = ' '; $paidday = ' ';	} 

/* Perform a query, check for error */
$sql = "UPDATE paytbl SET 
$amtpaid = '$amtpaid', dueday = DATE_ADD(dueday, INTERVAL 1 MONTH), prevbal = '$prevbal', 
latechg = '$latechg', paidday = '$paidday' WHERE unit = '$unit'";
 if(mysqli_query($link, $sql)){ echo ""; } 
else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); }
?>

<?php echo $bizname;echo "<br />"; ?>  // line  78 
<?php echo $bizstreet;echo "<br />"; ?>  
<?php echo $bizcity;echo "<br />"; ?>  
<?php echo $bizzip;echo "<br />"; ?><br>  
<?php echo $bizemail;echo "<br />"; ?>  // line 82  

For:<SELECT name="options">
<option value="#990033" style="background-color: Violet;">Rent payment</option>
<option value="#003300" style="background-color: Aquamarine;">Background Check</option>
<option value="#6600cc" style="background-color: Pink;">Security Deposit Payment</option>
<option value="#003300" style="background-color: Aquamarine;">Damages Payment</option>
<option value="#990033" style="background-color: Violet;">Late Charges Payment</option>
<option value="#003300" style="background-color: Aquamarine;">Court Costs Payment</option>
<option value="#6600cc" style="background-color: Pink;">NSF Payment</option>
<option value="#990033" style="background-color: Violet;"> </option>
</SELECT><p>

Tenant paying is: <?php echo $_POST["unit"]; ?> - 
Amount paid is: <?php echo $_POST["amtpaid"]; ?> - 

Balance due is:<?php echo $owed; ?><br>  // line 98 
<b><input type="text" size="35" maxlength="35" name=frm.Name" value="sign" STYLE="color: #000000; font-weight: bold; background-color: #ffccff;" onFocus="this.value=''"><br>
<h3>We Thank You</h3>
</center></body></html>
<?php
 // Close connection
mysqli_close($link);
?>

 

 apartment
receipt# 0receiptno updatedERROR: Could not able to execute UPDATE paytbl SET 0 = '0',
dueday = DATE_ADD(dueday, INTERVAL 1 MONTH), prevbal = '0', latechg = '0', paidday = ' '
WHERE unit = 'unit1'. You have an error in your SQL syntax; check the manual that corresponds
to your MariaDB server version for the right syntax to use near '0 = '0', dueday = DATE_ADD(dueday,
INTERVAL 1 MONTH), prevbal = '0', latech...' at line 2
// line 78

// line 82 For: Tenant paying is: unit1 - Amount paid is: 530.00 - Balance due is:0
// line 98

 

 



BC AdBot (Login to Remove)

 


#2 guitarzRwe

guitarzRwe
  • Topic Starter

  •  Avatar image
  • Members
  • 6 posts
  • OFFLINE
  •  
  • Local time:01:51 AM

Posted 11 April 2023 - 04:15 PM

 

I coded my first php program, set up my first database and designed my first website with help from
this site years ago. Recently I have solicited help and received 0 reads. Please delete my posts.



#3 xBlueRobot

xBlueRobot

  •  Avatar image
  • BSOD Kernel Dump Expert
  • 408 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:%systemroot%
  • Local time:06:51 AM

Posted 22 April 2023 - 08:07 AM

The error is literally shown to you. You're trying to set a column called 0 which doesn't exist. You need to correct your SQL to:

 

$sql = "UPDATE paytbl SET
amtpaid = '$amtpaid', dueday = DATE_ADD(dueday, INTERVAL 1 MONTH), prevbal = '$prevbal',
latechg = '$latechg', paidday = '$paidday' WHERE unit = '$unit'";
if(mysqli_query($link, $sql)){ echo ""; } 
else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); }
?>


#4 xBlueRobot

xBlueRobot

  •  Avatar image
  • BSOD Kernel Dump Expert
  • 408 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:%systemroot%
  • Local time:06:51 AM

Posted 22 April 2023 - 08:11 AM

 

 

I coded my first php program, set up my first database and designed my first website with help from
this site years ago. Recently I have solicited help and received 0 reads. Please delete my posts.

 

 

That's probably because you never respond to advice given in prior posts and then decided to create a new account when you didn't understand the advice given to you. You're better off posting any programming questions to StackOverflow rather than BleepingComputer which is predominantly a support forum for computer issues.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users