i have a problem in my code. When i post something then it displays:
SCREAM: Error suppression ignored for
Notice: Undefined variable: suffix in...
But i have defined my variable in my code... So how i can fix this error?
<?php
$conn = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("test", $conn);
$time = time();
if(isset($_POST['pateikti'])) {
if(empty($_POST['tekstas'])) { echo "Tekstas per trumpas!"; }
else {
mysql_query("INSERT INTO tsp (timestamp, text) VALUES ('".time()."', '$_POST[tekstas]')");
}
}
$query = mysql_query("SELECT * FROM tsp");
while($row = mysql_fetch_assoc($query)) {
$diff = $time - $row['timestamp'];
switch(1) {
case ($diff < 60):
$ago = $diff;
if($ago == 0)
$ago == "akimirką";
else if($diff < 10)
$suffix = "sekundes";
else
$suffix = "sekundžių";
break;
}
echo $row['text']." buvo parasytas prieš ".$diff." ".$suffix."</br>";
}
?>
<form action="" method="POST" >
<input type="text" name="tekstas" /><br>
<input type="submit" name="pateikti" value="Pateikti" />
</form>
Thank you in advance for helping me!
since you do not define it before the switch then use a default to set it in case diff is greater than 60
switch(1) {
case ($diff < 60):
$ago = $diff;
if($ago == 0)
$ago == "akimirką";
else if($diff < 10)
$suffix = "sekundes";
else
$suffix = "sekundžių";
break;
default:
$suffix ="default text";
break;
}
You have the following switch:
switch(1) {
case ($diff < 60):
$ago = $diff;
if($ago == 0)
$ago == "akimirką";
else if($diff < 10)
$suffix = "sekundes";
else
$suffix = "sekundžių";
break;
}
Here, if $diff
is equal to 0
, you have that $suffix
never gets defined.
Simply change the switch to:
$suffix = ''; // <-- define "suffix"
switch(1) {
case ($diff < 60):
$ago = $diff;
if($ago == 0)
$ago == "akimirką";
else if($diff < 10)
$suffix = "sekundes";
else
$suffix = "sekundžių";
break;
}
Also, IMHO, that switch could be replaced with:
$suffix = '';
if($diff < 60) {
$ago = $diff;
if($ago == 0) {
$ago == "akimirką";
}
else if($ago < 10) {
$suffix = "sekundes";
}
else {
$suffix = "sekundžių";
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.