Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Somethings Im missing?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Kryllster
Smarty Rookie


Joined: 22 Sep 2007
Posts: 25

PostPosted: Thu Aug 14, 2008 10:28 pm    Post subject: Somethings Im missing? Reply with quote

Why doesnt this work

$gold = $smarty->assign('gold',$gold);

That is in my php script

in my template I have

{$gold}

where I want that variable displayed??

also in my php script I have above that:

$gold = mt_rand(1000,4000);

why is it not displaying in my template Im not undertanding it? I have looked at the docs and the forums but there probably is an explantion but different people undertand well differently??

** Edited

I have used smarty for about 2 years now and really all I have ever done is small stuff. mostly static pages and a small amount of php. Now, tho, I am learning more about php so i need to learn differently about how smaty works and how to do things with scripts outside of smarty and take their output to another page or template. I have been working on this game which was come to find out very insecure or unsecure however it goes. I had been basically doing a lot of buttons in form form to post or act as links. I didnt realise this complicates matters. I have been looking all over this forum for understanding where to go next cause its not just static anymore I need to learn how to do it dynamically I guess. I am new still but I want to learn more. I took one of the little post buttons out of the html page but now I dont know how to run the script and get the variable I need after the script is run as a link i have

<a href="mainview2.php?diamond=main">Link Here</a> where as before it was

<form action="scriptname.php" method="post">
<input type="submit" value="Click Here to run script kinna">
</form>
which was running the script fine and redirect to the right template did the database work the script works fine excet when I send it to the corresponding page I can get the variables form the output I want on that page. I know this is a long one but I am very confused cause now it wont even run lol I have royally made a boo boo I think but I need to realearn I supose.

Thanks for any help in advance I wanna learn cause someday I may actually need the knowledge!

Kryllster aka Terry

Thanks for your help?

Kryllster
Back to top
View user's profile Send private message Send e-mail
Kryllster
Smarty Rookie


Joined: 22 Sep 2007
Posts: 25

PostPosted: Fri Aug 15, 2008 9:47 am    Post subject: Reply with quote

Well for what it might be worth here is my code I'm trying to use?

Code:
<?php
//session_start();
//$uname = $_SESSION['uname'];

// initialize outcome of fight and loot chances
$outcome = mt_rand(1,100);
$level_advance = 2;
$gold = mt_rand(1000,4000);
$diamonds = mt_rand(3,8);
$rubies = mt_rand(3,7);

 // My Fight and loot generator
$smarty->assign('gold',$gold);
$smarty->assign('rubies',$rubies);
$smarty->assign('diamonds',$diamonds);

// First the fight
if($outcome < 70){

// Connect to database
include('includes/config.php');
include('includes/advance_level.php');

// Update database
$sql="UPDATE $tbl_name SET
   onhand = onhand + $gold,
   diamond = diamond + $diamonds,
   rubie = rubie + $rubies,
   advance = advance + $level_advance
   WHERE uname='$uname'";
mysql_query($sql) or die (mysql_error()."<p>$sql</p>");

// Take me to my readout
header("Location:mainview2.php?diamond=fight_success");

}
else{
header("Location:mainview2.php?diamond=fight_failure");
exit();
}
?>


Thanks
Back to top
View user's profile Send private message Send e-mail
Celeb
Administrator


Joined: 17 Apr 2007
Posts: 1025
Location: Vienna

PostPosted: Fri Aug 15, 2008 10:04 am    Post subject: Reply with quote

You need to display() a template in order for it to be displayed.

If you're taking the browser to a different location using a HTML header all your assigned Smarty variables are gone.
_________________
Darn computers always do what I tell them to instead of what I want them to do.
Back to top
View user's profile Send private message
Kryllster
Smarty Rookie


Joined: 22 Sep 2007
Posts: 25

PostPosted: Fri Aug 15, 2008 10:27 am    Post subject: Reply with quote

Thanks for showing me that I have learned so much from the past 48 hrs and it is going to help tremendously. It worked really well and I feel like I have passed into a whole other dimension lol!!

I cant say thank you enough!



Kryllster
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP