Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I get the following when I try to execute:
What is wrong?

expiry was updated successfully.
Warning: Use of undefined constant expiry - assumed 'expiry' (this will throw an Error in a future version of PHP) on line 14

Warning: Use of undefined constant expiry - assumed 'expiry' (this will throw an Error in a future version of PHP) on line 15

Warning: Use of undefined constant expiry - assumed 'expiry' (this will throw an Error in a future version of PHP) on line 16
---------------------------------------------------------------
the code
<?php
$link = mysqli_connect("localhost", "root", "", "prerentdb"); 
// Check connection
if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); }
echo "<center>";echo date('m/d/y');
echo "<br />";
$id='id';
$expiry='expiry';

$sql = "UPDATE paytbl SET $expiry = $expiry-1 where id = '$id'";
if(mysqli_query($link, $sql)){ echo "expiry was updated successfully."; } 
else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); }

if(expiry == 7) {echo "1 week remaining on contract";} 
elseif (expiry == 1) {echo "1 day remaining on contract";}
elseif (expiry == 0) {echo "contact xxxxx.com to renew and continue use";}

// Close connection
mysqli_close($link);
?>


What I have tried:

the code
<?php
$link = mysqli_connect("localhost", "root", "", "prerentdb"); 
// Check connection
if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); }
echo "<center>";echo date('m/d/y');
echo "<br />";
$id='id';
$expiry='expiry';

$sql = "UPDATE paytbl SET $expiry = $expiry-1 where id = '$id'";
if(mysqli_query($link, $sql)){ echo "expiry was updated successfully."; } 
else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); }

if(expiry == 7) {echo "1 week remaining on contract";} 
elseif (expiry == 1) {echo "1 day remaining on contract";}
elseif (expiry == 0) {echo "contact xxxxx.com to renew and continue use";}

// Close connection
mysqli_close($link);
?>
Posted
Updated 7-Jun-22 10:08am
Comments
Richard MacCutchan 22-Apr-21 3:36am    
It should be $expiry.
Richard Deeming 22-Apr-21 3:47am    
$sql = "UPDATE paytbl SET $expiry = $expiry-1 where id = '$id'";

What exactly do you expect that query to do?

You won't have a column called $expiry in your table. And subtracting 1 from the string 'expiry' makes no sense.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900