Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-15-2009, 08:52 PM   PM User | #1
Philey
New to the CF scene

 
Join Date: Mar 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Philey is an unknown quantity at this point
Stock Script

can someone help me the stock wont update the price and shows no new or no oldprice

Code:
<?
session_start(); 
include_once "includes/db_connect.php";
include_once "includes/functions.php";

$fetch=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$username'"));


$stats12 = mysql_fetch_object(mysql_query("SELECT * FROM site_stats WHERE id='1'"));

$stockam = explode("-", $fetch->stock);
$prices=explode("-", $stats12->newstockp);
$prices1=explode("-", $stats12->oldstockp);
if ($stats12->stime <= time()){
$newtime1 = time() + 600;
$a1 = $prices[0] + rand(-10,15);
$a2 = $prices[1] + rand(-10,15);
$a3 = $prices[2] + rand(-10,15);
$a4 = $prices[3] + rand(-10,15);
$a5 = $prices[4] + rand(-10,15);

$newpricess1="$a1-$a2-$a3-$a4-$a5";

	mysql_query("UPDATE site_stats SET oldstockp='$stats12->newstockp' WHERE id='1'");
		mysql_query("UPDATE site_stats SET newstockp='$newpricess1' WHERE id='1'");
	mysql_query("UPDATE site_stats SET stime='$newtime1' WHERE id='1'");
}
/////////diffrent ranks can hold diffrent stocks
if ($fetch->rank == "Tramp"){
	$maxstocks = "7";
}
if ($fetch->rank == "thief"){
	$maxstocks = "12";
}
if ($fetch->rank == "hooligan"){
	$maxstocks = "22";
}
if ($fetch->rank == "criminal"){
	$maxstocks = "35";
}
if ($fetch->rank == "gangster"){
	$maxstocks = "40";
}
if ($fetch->rank == "boss"){
	$maxstocks = "50";
}
if ($fetch->rank == "supreme boss"){
	$maxstocks = "65";
}
if ($fetch->rank == "don"){
	$maxstocks = "70";
}
if ($fetch->rank == "legendry don"){
	$maxstocks = "90";
}
if ($fetch->rank == "Moderator"){
	$maxstocks = "2000";
}
if ($fetch->rank == "Head Moderator"){
	$maxstocks = "2000";
}
if ($fetch->rank == "Admin"){
	$maxstocks = "1000000000";
}




if ($_POST['doit']){
	$doit = $_POST['doit'];
if ($doit == 'buy'){
/////////ny trains
if ($_POST['nytl']){
$stocka = (strip_tags($_POST['nytl']));
$totala=$stocka*$prices[0];
}else{
$stocka=0;
}

/////////ny trains
if ($_POST['tnyt']){
$stockb = (strip_tags($_POST['tnyt']));
$totalb=$stockb*$prices[1];
}else{
$stockb=0;
}

/////////ny trains
if ($_POST['qits']){
$stockc = (strip_tags($_POST['qits']));
$totalc=$stockc*$prices[2];
}else{
$stockc=0;
}

/////////ny trains
if ($_POST['abco']){
$stockd=(strip_tags($_POST['abco']));
$totald=$stockd*$prices[3];
}else{
$stockd=0;
}

/////////bronx consultancy
if ($_POST['brcg']){
$stocke=(strip_tags($_POST['brcg']));
$totale=$stocke*$prices[4];
}else{
$stocke=0;
}
///////////////////
if(ereg("[^[:digit:]]", $stocka)){
			echo "			
Bad amount!!</font>";
}elseif (!ereg("[^[:digit:]]", $stocka)){
///////////////////
if(ereg("[^[:digit:]]", $stockb)){
			echo "			
Bad amount!!</font>";
}elseif (!ereg("[^[:digit:]]", $stockb)){
///////////////////
if(ereg("[^[:digit:]]", $stockc)){
			echo "			
Bad amount!!</font>";
}elseif (!ereg("[^[:digit:]]", $stockc)){
///////////////////
if(ereg("[^[:digit:]]", $stockd)){
			echo "			
Bad amount!!</font>";
}elseif (!ereg("[^[:digit:]]", $stockd)){
///////////////////
if(ereg("[^[:digit:]]", $stocke)){
			echo "			
Bad amount!!</font>";
}elseif (!ereg("[^[:digit:]]", $stocke)){
///////////////////

if ($stockam[0] != 0){
			$stocka = $stocka + $stockam[0];
		}
if ($stockam[1] != 0){
			$stockb = $stockb + $stockam[1];
		}
if ($stockam[2] != 0){
			$stockc = $stockc + $stockam[2];
		}
if ($stockam[3] != 0){
			$stockd = $stockd + $stockam[3];
		}
if ($stockam[4] != 0){
			$stocke = $stocke + $stockam[4];
		}	
$total = $stocka+$stockb+$stockc+$stockd+$stocke;
		
if ($total > $maxstocks){
echo "You can only have $maxstocks stocks</font>";
}elseif ($total <= $maxstocks){
$totalprice = $totala + $totalb + $totalc + $totald + $totale;
if ($totalprice > $fetch->money){
echo "You cant afford that.";
}elseif ($totalprice <= $fetch->money){
$newstocks = "$stocka-$stockb-$stockc-$stockd-$stocke";
$new_money=$fetch->money-$totalprice;
					mysql_query("UPDATE users SET money=$new_money WHERE username='$username'");
					mysql_query("UPDATE users SET stock='$newstocks' WHERE username='$username'");
echo "Successful transaction.";
echo "<meta http-equiv=\"refresh\" content=\"0;URL=stocks.php\">";

}}}}}}}}}
/////////////sell stocks
if ($_POST['doit']){
	$doit = $_POST['doit'];
if ($doit == 'sell'){
if ($_POST['nytl']){
$sell1 = intval(strip_tags($_POST['nytl']));
$totals1 = $sell1* $prices[0];
}else{
$sell1 = 0;
}
if ($_POST['tnyt']){
$sell2 = intval(strip_tags($_POST['tnyt']));
$totals2 = $sell2* $prices[1];
}else{
$sell2 = 0;
}
if ($_POST['qits']){
$sell3 = intval(strip_tags($_POST['qits']));
$totals3 = $sell3* $prices[2];
}else{
$sell3 = 0;
}
if ($_POST['abco']){
$sell4 = intval(strip_tags($_POST['abco']));
$totals4 = $sell4* $prices[3];
}else{
$sell4 = 0;
}
if ($_POST['brcg']){
$sell5 = intval(strip_tags($_POST['brcg']));
$totals5 = $sell5* $prices[4];
}else{
$sell5 = 0;
}
////////////check for invalid digits
if(ereg("[^[:digit:]]", $sell1)){
			echo "			
<font color=red>Bad ammount!!</font>";
}elseif (!ereg("[^[:digit:]]", $sell1)){
//////////////////////////
if(ereg("[^[:digit:]]", $sell1)){
			echo "			
<font color=red>Bad ammount!!</font>";
}elseif (!ereg("[^[:digit:]]", $sell2)){
////////////////////////////
if(ereg("[^[:digit:]]", $sell3)){
			echo "			
<font color=red>Bad ammount!!</font>";
}elseif (!ereg("[^[:digit:]]", $sell3)){
///////////////////////
if(ereg("[^[:digit:]]", $sell4)){
			echo "			
<font color=red>Bad ammount!!</font>";
}elseif (!ereg("[^[:digit:]]", $sell4)){
////////////////
if(ereg("[^[:digit:]]", $sell5)){
			echo "			
<font color=red>Bad ammount!!</font>";
}elseif (!ereg("[^[:digit:]]", $sell5)){
////////// check to see if they have that many stocks
if($sell1 > $stockam[0]){
				echo "You dont have that many!";
				}elseif ($sell1 <= $stockam[0]){
if($sell2 > $stockam[1]){
				echo "You dont have that many!";
				}elseif ($sell2 <= $stockam[1]){
if($sell3 > $stockam[2]){
				echo "You dont have that many!";
				}elseif ($sell3 <= $stockam[2]){
if($sell4 > $stockam[3]){
				echo "You dont have that many!";
				}elseif ($sell4 <= $stockam[3]){
if($sell5 > $stockam[4]){
				echo "You dont have that many!";
				}elseif ($sell5 <= $stockam[4]){
///////////work out new values of each stock
if ($stockam[0] != 0){
			$sell1 =$stockam[0] - $sell1;
		}
if ($stockam[1] != 0){
			$sell2 =$stockam[1] - $sell2;
		}

if ($stockam[2] != 0){
			$sell3 =$stockam[2] - $sell3;
		}
if ($stockam[3] != 0){
			$sell4 =$stockam[3] - $sell4;
		}
if ($stockam[4] != 0){
			$sell5 =$stockam[4] - $sell5;
		}
////////// workout values if you sell all stocks
if ($sell1 == ""){
			$sell1 = 0;
		}	
if ($sell2 == ""){
			$sell2 = 0;
		}	
if ($sell3 == ""){
			$sell3 = 0;
		}	
if ($sell4 == ""){
			$sell4 = 0;
		}	
if ($sell5 == ""){
			$sell5 = 0;
		}	
//////////////work out money and new stocks and insert it into db
$new_stocks1 = "$sell1-$sell2-$sell3-$sell4-$sell5";		
$setmemycash = $totals1 + $totals2 + $totals3 + $totals4 + $totals5;
						$new_money_1 = $fetch->money + $setmemycash;
						mysql_query("UPDATE users SET money='$new_money_1', stock='$new_stocks1' WHERE username='$username'");
						echo "Successful transaction.";
echo "<meta http-equiv=\"refresh\" content=\"0;URL=stocks.php\">";
}}}}}}}}}}}}

?>
<link rel="stylesheet" href="file:///C|/Documents%20and%20Settings/J/My%20Documents/My%20Received%20Files/main.css" type="text/css">
<link href="/includes/in.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {color: #CCCCCC}
-->
</style>
<center>
<span class="style1"> You can hold <? echo "$maxstocks"; ?> stocks
</span>
<form action='' method='post'>
<table width="61%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="000000" class="thinline">
  <tr>
    <td class="header" colspan=7><div align="center">Stock Market </div></td>
  </tr>  </tr>
  <tr bgcolor=#666666>
    <td width="29%" colspan=6 class=tip><div align="center">The prices will change in <? echo "".maketime($stats12->stime).""; ?></div></td>
  </tr>
  <tr bgcolor=#666666>
    <td width="29%" class=tip><div align="center">Company</div></td>
    <td width="10%" class=tip><div align="center">Symbol</div></td>
    <td width="10%" class=tip><div align="center">Price </div></td>

    <td width="10%" class=tip><div align="center">Old Price </div></td>
    <td width="11%" class=tip><div align="center"># Owned </div></td>
	    <td width="15%" class=tip><div align="center">Buy/Sell</div></td>
  <tr>
    <td><strong>Coca-Cola</strong></td>
    <td>CC</td>
    <td><strong><? echo "$".makecomma($prices[0]).""; ?></strong></td>
   
    <td><? echo "$".makecomma($prices1[0]).""; ?></td>
    <td><? echo "$stockam[0]"; ?></td>
	    <td><input name="nytl" type="text" class="submit" size="8" maxlength="4"></td>
  </tr>
  <tr>
    <td><strong>Samsung</strong></td>
    <td>Sa</td>
    <td><strong><? echo "$".makecomma($prices[1]).""; ?></strong></td>
  
    <td><? echo "$".makecomma($prices1[1]).""; ?></td>
    <td><? echo "$stockam[1]"; ?></td>
	    <td><input name="tnyt" type="text" class="submit" size="8" maxlength="4"></td>
  </tr>
  <tr>
    <td><strong>British airways </strong></td>
    <td>BA</td>
    <td><strong><? echo "$".makecomma($prices[2]).""; ?></strong></td>

    <td><? echo "$".makecomma($prices1[3]).""; ?></td>
    <td><? echo "$stockam[2]"; ?></td>
	    <td><input name="qits" type="text" class="submit" size="8" maxlength="4"></td>
  </tr>
  <tr>
    <td><strong>Sony</strong></td>
    <td>So</td>
    <td><strong><? echo "$".makecomma($prices[3]).""; ?></strong></td>
    
    <td><? echo "$".makecomma($prices1[3]).""; ?></td>
    <td><? echo "$stockam[3]"; ?></td>
	    <td><input name="abco" type="text" class="submit" size="8" maxlength="4"></td>
  </tr>
  <tr>
    <td><strong>Tesco</strong></td>
    <td>Te</td>
    <td><strong><? echo "$".makecomma($prices[4]).""; ?></strong></td>
  
    <td><? echo "$".makecomma($prices1[4]).""; ?></td>
    <td><? echo "$stockam[4]"; ?></td>
	    <td><input name="brcg" type="text" class="submit" size="8" maxlength="4"></td>
  </tr>
  
  <tr>
     <td>&nbsp;</td>
	   <td><input type="radio" name="doit" value="buy" checked="checked"/>
Buy</td>
	     <td><input type="radio" name="doit" value="sell"/>
         Sell</td>
		   
		   <td>&nbsp;</td>
		     <td>Total: <? $total3456=$stockam[0]+$stockam[1]+$stockam[2]+$stockam[3]+$stockam[4]; echo "$total3456"; ?></td>
			   <td>
			     <input name="Submit" type="submit" class="submit" value="Submit"/>		      </td>
  </tr>
</table>
</form>

<div align="center">
  <p>The Stock Market may crash at anytime </p>
  <p><a href="stocks.php">Refresh</a><br>
  </p>
</div>
<?php include_once"includes/footer.php"; ?>

please help maybe someone know how this works correctly
Philey is offline   Reply With Quote
Old 03-16-2009, 12:41 PM   PM User | #2
student101
Regular Coder

 
student101's Avatar
 
Join Date: Nov 2007
Posts: 610
Thanks: 80
Thanked 13 Times in 13 Posts
student101 is on a distinguished road
I have no clue where this script came from, maybe the short open tag isn't enabled? Change <? to <?php
If that isn't it, Do the select statements work on their own?

Cheers
__________________
Thanks for your support!
Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

Give thanks & resolve when done :thumbsup:
student101 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:21 AM.


Advertisement
Log in to turn off these ads.