Quick php question

votter

New Member
Messages
34
Reaction score
0
Points
0
<?php echo '<span style="color:#FFFFFF;">You are cutting ' . $amount . ' wood</span>'; ?>{
}
else
{
<?php echo '<span style="color:#FFFFFF;">You are not currently working..</span>'; ?>
}

I know I have it messed up, but cant find the right way to fix it. :p.
 

TheMan177

New Member
Messages
179
Reaction score
0
Points
0
The braces and the else statement must be inside php tags. Even then, though, your logic is not correct; what is it you are trying to do, exactly?
 

votter

New Member
Messages
34
Reaction score
0
Points
0
It is part of another script or 2, but I messed it up and forgot to keep the original while I tried to get the $amount to work.
 
T

themasterrocker

Guest
explain what you need to find out? Because I'm not sure what you're trying to do.
 

freemble1

New Member
Messages
14
Reaction score
0
Points
0
Is it this that you are after?

PHP:
<?php 
if (empty($amount) or $amount==0) {
echo '<span style="color:#FFFFFF;">You are not currently working..</span>';
} else {
echo '<span style="color:#FFFFFF;">You are cutting ' . $amount . ' wood</span>';
}
?>
 

votter

New Member
Messages
34
Reaction score
0
Points
0
Yes free, I think that is what I am after. Just gotta fix the error with it now and see if it works.
 

votter

New Member
Messages
34
Reaction score
0
Points
0
PHP:
<?php include("sheet.php"); ?>
<table align="center" width="59%" border="1">
<tr>
<td align="center">
<form name="counter"><p><input type="text" style="width:75px;" 
name="d2"></form>
<?php
$endTime = $Variables['endtimefield'];
$now = time();
$diff = $endTime - $now;
if($endTime > $now) {
?> 
<script type="text/javascript">
var timeLeft = <?php echo $diff; ?>;
var milisec=0;
var seconds=timeLeft;
document.counter.d2.value='30';
function display(){ 
if (milisec<=0){ 
milisec=9 
seconds-=1 
} 
if (seconds<=-1){ 
milisec=0 
seconds+=1 
} 
else 
milisec-=1 
document.counter.d2.value=seconds+"."+milisec 
setTimeout("display()",100) 
} 
display()
--> 
</script>
<?php 

 
if (empty($amount) or $amount==0) { 
echo '<span style="color:#FFFFFF;">You are not currently working..</span>'; 
} else { 
echo '<span style="color:#FFFFFF;">You are cutting ' . $amount . ' wood</span>'; 
} 
?> 
</td>
</tr>
</table>
</body></html>
Is what I got for the page, it all worked fine till I changed it.

Oh, and the freemble.com thing in your sig seems broken, or your site is down.
 
Last edited:

votter

New Member
Messages
34
Reaction score
0
Points
0
I just put an ending bracket like:

PHP:
if($endTime > $now) {
}
and it seems to run then. Just gotta fix the amount thing so it is correct and doesn't say you are not currently working. xD.

Thanks for the help all. :D.
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
You forgot a '}' in your php, and also, each line in JavaScript should end with a ';'.
Try this code:
PHP:
<?php include("sheet.php"); ?>
<table align="center" width="59%" border="1">
<tr>
<td align="center">
<form name="counter"><p><input type="text" style="width:75px;" 
name="d2"></form>
<?php
$endTime = $Variables['endtimefield'];
$now = time();
$diff = $endTime - $now;
if($endTime > $now) {
?> 
<script type="text/javascript">
var timeLeft = <?php echo $diff; ?>;
var milisec=0;
var seconds=timeLeft;
document.counter.d2.value='30';
function display(){ 
if (milisec<=0){ 
milisec=9;
seconds-=1;
} 
if (seconds<=-1){ 
milisec=0;
seconds+=1;
} 
else 
milisec-=1 
document.counter.d2.value=seconds+"."+milisec;
setTimeout("display()",100);
} 
display();
--> 
</script>
<?php 
}

 
if (empty($amount) or $amount==0) { 
echo '<span style="color:#FFFFFF;">You are not currently working..</span>'; 
} else { 
echo '<span style="color:#FFFFFF;">You are cutting ' . $amount . ' wood</span>'; 
} 
?> 
</td>
</tr>
</table>
</body></html>

EDIT: lol, didn't see there was a second page <.<
But the JavaScript thingie still stands.
 
Last edited:

freecrm

New Member
Messages
629
Reaction score
0
Points
0
Yep - missing braces for two if statements.


<?php
$endTime = $Variables['endtimefield'];
$now = time();
$diff = $endTime - $now;
if($endTime > $now) {
?>

This statement alone needs a "}" at the end. Such as <?php } ?>

or as part of another statement within <?php......?> tags

You then put in another if statement without closing the first, which is OK but the first is never closed.
 

chappill

New Member
Messages
74
Reaction score
0
Points
0
PHP:
<?php include("sheet.php"); ?> 
<table align="center" width="59%" border="1"> 
<tr> 
<td align="center"> 
<form name="counter"><p><input type="text" style="width:75px;"  
name="d2"></form> 
<?php 
$endTime = $Variables['endtimefield']; 
$now = time(); 
$diff = $endTime - $now; 
if($endTime > $now) { 
?>  
<script type="text/javascript"> 
var timeLeft = <?php echo $diff; ?>; 
var milisec=0; 
var seconds=timeLeft; 
document.counter.d2.value='30'; 
function display(){  
if (milisec<=0){  
milisec=9  
seconds-=1  
}  
if (seconds<=-1){  
milisec=0  
seconds+=1  
}  
else  
milisec-=1  
document.counter.d2.value=seconds+"."+milisec  
setTimeout("display()",100)  
}  
display() 
-->  
</script> 
<?php  
}
  
if (empty($amount) or $amount==0) {  
echo '<span style="color:#FFFFFF;">You are not currently working..</span>';  
} else {  
echo '<span style="color:#FFFFFF;">You are cutting ' . $amount . ' wood</span>';  
}  
?>  
</td> 
</tr> 
</table> 
</body></html>

Try that you missed a } before you closed the php bracket.
WOW actually never mind I see alot wrong. I'll be back in 5 minutes lol.
 
Last edited:

votter

New Member
Messages
34
Reaction score
0
Points
0
I have another question for this, I am trying to get it to work with another form process, but can't get the {}'s to work out.


PHP:
<?php include("sheet.php"); ?>
<table align="center" width="59%" border="1">
<tr>
<td align="center">
<?php
$endTime = $Variables['endtimefield'];
$now = time();
$diff = $endTime - $now;
if($endTime > $now) { 
?> 
<form name="counter"><p><input type="text" style="width:75px;" 
name="d2"></form>
<script type="text/javascript">
var timeLeft = <?php echo $diff; ?>;
var milisec=0;
var seconds=timeLeft;
document.counter.d2.value='30';
function display(){ 
if (milisec<=0){ 
milisec=9 
seconds-=1 
} 
if (seconds<=-1){ 
milisec=0 
seconds+=1 
} 
else 
milisec-=1 
document.counter.d2.value=seconds+"."+milisec 
setTimeout("display()",100) 
} 
display()
--> 
</script>
<?php include("levels.php"); ?>
<?php 
$woods = $_POST['amount'];
$wood = $Resources['wood'];
echo '<span style="color:#FFFFFF;">You are cutting ' . $woods . ' wood</span><br />'; 
echo '<span style="color:#FFFFFF;">You have ' . $wood . ' wood</span>'; 
} else {
echo '<span style="color:#FFFFFF;">You are not currently woodcutting</span>'; 
}
{
$mineamount = $_POST['mineamount'];
$gorfore = $Resources['gorfore'];
echo '<span style="color:#FFFFFF;">You are mining ' . $mineamount . ' gorf ore</span><br />'; 
echo '<span style="color:#FFFFFF;">You have ' . $gorfore . ' ore</span>'; 
}
?> 

</td>
</tr>
</table>
</body></html>
 
Last edited:

VPmase

New Member
Messages
914
Reaction score
0
Points
0
You don't need to have the last two brackets at the bottom of your script.

The { and } at the bottom are useless.
 

votter

New Member
Messages
34
Reaction score
0
Points
0
Ok, Thanks. Got rid of those, 1 thing down, more to go. lol.
Edit:
I still haven't figured it out, anybody know what I can do?
 
Last edited:
Top