1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Ajax & Php! ;|

Discussion in 'C#' started by iDaTa, Sep 27, 2010.

  1. #1
    Afternoon all;
    I'm going to put this a simple as i can.
    I'm trying to learn ajax, hours upon hours of research, yet i can't find any 'good' examples to learn from; apart from the 'over populated ajax contact forms' i see in every website.

    I have a file below which includes html, php and 'snippets' of javascript.
    Could anybody at all; sort it so the post requests, automatically load.
    I'm not quite sure on how to explain it, but make it load the echo's without re-loading the page?
    SEMrush
    Even if somebody was to do 1 line of code for me, just for me to learn i'd appreciate it greatly.
    I may also send some money via 'Paypal' as a kind thanks afterwards.



    
    <?php
    
    session_start();
    
    require_once("includes/db_connect.php");
    require_once("includes/functions.php");
    require_once("includes/jail_check.php");
    
    $username = $_SESSION['username'];
    $page=$_GET['page'];
    
    $fetch = mysql_fetch_object(mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."'"));
    $bank = mysql_fetch_object(mysql_query("SELECT * FROM `bank` WHERE `location` = '".$fetch->location."'"));
    $fetch_owner = mysql_fetch_object(mysql_query("SELECT * FROM `users` WHERE `username` = '".$bank->owner."'"));
    
    $bankle = mysql_fetch_object(mysql_query("SELECT * FROM `bank` WHERE `location` = 'Washington - Olympia'"));
    $bankpf = mysql_fetch_object(mysql_query("SELECT * FROM `bank` WHERE `location` = 'California - Sacramento'"));
    $bankri = mysql_fetch_object(mysql_query("SELECT * FROM `bank` WHERE `location` = 'Texas - Austin'"));
    $bankbg = mysql_fetch_object(mysql_query("SELECT * FROM `bank` WHERE `location` = 'Florida - Tallahassee'"));
    $bankms = mysql_fetch_object(mysql_query("SELECT * FROM `bank` WHERE `location` = 'New York - Albany'"));
    $banksp = mysql_fetch_object(mysql_query("SELECT * FROM `bank` WHERE `location` = 'Georgia - Atlanta'"));
    $bankdu = mysql_fetch_object(mysql_query("SELECT * FROM `bank` WHERE `location` = 'Detroit - United States'"));
    $banktc = mysql_fetch_object(mysql_query("SELECT * FROM `bank` WHERE `location` = 'Toronto - Canada'"));
    
    $rand = rand(1,8);
    if ($rand == "1"){
    $selected1 = "selected";
    }elseif ($rand == "2"){
    $selected2 = "selected";
    }elseif ($rand == "3"){
    $selected3 = "selected";
    }elseif ($rand == "4"){
    $selected4 = "selected";
    }elseif ($rand == "5"){
    $selected5 = "selected";
    }elseif ($rand == "6"){
    $selected6 = "selected";
    }elseif ($rand == "7"){
    $selected7 = "selected";
    }elseif ($rand == "8"){
    $selected8 = "selected";
    }
    
    $last = $fetch->banktime - time();
    
    //Owner Check
    //No Owner
    
    if ($bank->owner == "0"){
    echo "This national bank is currently unowned, click here to become the owner.";
    exit();
    }
    
    //End
    
    
    //End
    //Deposit money from bank account
    
    $bank_type = strip_tags($_POST['bank_type']);
    $the_amount = strip_tags($_POST['the_amount']);
    
    if (strip_tags($_POST['update_button'])){
    
    if ($bank_type == "1"){
    
    if (!$the_amount){
    echo "<br><center>You must enter an amount to deposit.";
    }elseif ($the_amount){
    
    if ($the_amount == 0 || ereg('[^0-9]',$the_amount) || $the_amount < "0"){
    echo "<br><center>An invalid amount to deposit was entered.";
    }elseif ($the_amount != 0 && !ereg('[^0-9]',$the_amount) || $the_amount > "0"){
    
    if ($the_amount > $fetch->money){
    echo "<br><center>This account doesn't have that much money in it's money.";
    }elseif ($the_amount <= $fetch->money){
    
    $user_lose = $fetch->money - $the_amount;
    $bank_add = $fetch->bank + $the_amount;
    
    $newtime = 3600*24;
    $timewait = time()+ $newtime;
    
    mysql_query("UPDATE `users` SET `money` = '".$user_lose."', `bank` = '".$bank_add."', `banktime` = '".$timewait."' WHERE `username` = '".$username."'");
    
    echo "<br><center>You successfully deposited a total of &#163;".makecomma($the_amount)." into your bank account.";
    
    }}}}
    
    //End
    //Withdraw money from bank account
    
    if ($bank_type == "2"){
    
    if (!$the_amount){
    echo "<br><center>You must enter an amount to withdraw.";
    }elseif ($the_amount){
    
    if ($the_amount == 0 || ereg('[^0-9]',$the_amount) || $the_amount < "0"){
    echo "<br><center>An invalid amount to withdraw was entered.";
    }elseif ($the_amount != 0 || !ereg('[^0-9]',$the_amount) || $the_amount > "0"){
    
    if ($the_amount > $fetch->bank){
    echo "<br><center>This account doesn't have that much money in it's bank account.";
    }elseif ($the_amount <= $fetch->bank){
    
    $user_gain = $fetch->money + $the_amount;
    $bank_remove = $fetch->bank - $the_amount;
    
    mysql_query("UPDATE `users` SET `money` = '".$user_gain."', `bank` = '".$bank_remove."' WHERE `username` = '".$username."'");
    
    echo "<br><center>You successfully withdrew a total of &#163;".makecomma($the_amount)." from your bank account.";
    
    }}}}}
    
    //End
    //Send a user money
    
    
    if($_POST['send_button']){
    
    $whatbank = strip_tags($_POST['whatbank']);
    
    $fetch_bank = mysql_fetch_object(mysql_query("SELECT * FROM `bank` WHERE `id` = '".$whatbank."'"));
    
    $send_amount = intval(strip_tags($_POST['send_amount']));
    $to_person = strip_tags($_POST['to_person']);
    $type = strip_tags($_POST['type']);
    $send_message = strip_tags($_POST['send_message']);
    
    $totalsend = round($send_amount-(($send_amount/100)*$fetch_bank->commission));
    
    $num_true = mysql_num_rows(mysql_query("SELECT * FROM `users` WHERE `username` = '".$to_person."'"));
    $num_trueG = mysql_num_rows(mysql_query("SELECT * FROM `crews` WHERE `name` = '".$to_person."'"));
    
    
    if (!$to_person){
    echo "<br><center>You must enter a username to send money to.";
    }elseif ($to_person){
    
    if (!$type){	
    echo"<br /><center>You must choose to send to a player or gang!";
    }elseif ($type){
    
    if (!$send_amount){	
    echo"<br /><center>You must enter an amount.";
    }elseif ($send_amount){
    
    
    if ($num_true == 0){
    echo "<br><center>The username entered does not exist.";
    }elseif ($num_true != 0){
    
    
    $to_user = mysql_fetch_object(mysql_query("SELECT * FROM `users` WHERE `username` = '".$to_person."'"));
    
    if ($id == $to_user->id){
    echo "<br><center>You cannot send money to your own account.";
    }elseif ($id != $to_user->id){
    
    if ($to_user->status != "Alive"){
    echo "<br><center>The username you entered is not alive.";
    }elseif ($to_user->status == "Alive"){
    
    if ($send_amount == 0  || ereg('[^0-9]',$send_amount) || $send_amount < "0"){
    echo "<br><center>An invalid amount to send was entered.";
    }elseif ($send_amount != 0 || !ereg('[^0-9]',$send_amount) || $the_amount > "0"){
    
    if ($send_amount > $fetch->money){
    echo "<br><center>You don't have that much money to send!";
    }elseif ($send_amount <= $fetch->money){
    
    $amountcommission = ($send_amount/100)*$fetch_bank->commission;
     
    
    mysql_query("UPDATE `users` SET `money` = money-$send_amount WHERE `username` = '".$username."'");
    mysql_query("UPDATE `users` SET `money` = money+$amountcommission WHERE `username` = '".$fetch_bank->owner."'");
    mysql_query("UPDATE `bank` SET `profit` = profit+$amountcommission WHERE `owner` = '".$fetch_bank->owner."'");
    mysql_query("UPDATE `users` SET `money` = money+$totalsend WHERE `username` = '".$to_person."'");
    
    $now = date("d/m/y H:i:s");
    $now2 = date("l jS F Y H:i:s");
    mysql_query("INSERT INTO `banktransfers` (`id` , `to` , `from` , `amount` , `message` , `date`) VALUES ('', '$to_user->username', '$fetch->username', '$send_amount', '$send_message', '$now');");
    
    if ($send_message == ""){
    $message2 = "";
    }
    if ($send_message != ""){
    $message2 = "The sender left a message: $send_message";
    }
    
    mysql_query("INSERT INTO `inbox` (`id`, `username`, `from`, `message`, `subject`, `date`, `date_formatted`, `viewed`, `witness`, `lock`, `event`) VALUES ('', '$to_user->username', '$to_user->username', '$fetch->username has sent you &#163;".makecomma($send_amount).", after the $fetch_bank->commission% commission fee the bank charged you received a total of &#163;".makecomma($totalsend)."!<br><br>$message2', 'Bank Transfer', '$now', '$now2', '0', '0', '1', '0');");
    
    echo "<br><center>You successfully sent a total of &#163;".makecomma($send_amount)." to $to_user->username.";
    
    
    }}
    }}}}}}}
    
    //End
    
    ?>
    PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <link href="templates/cores.css" type="text/css" rel="stylesheet">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>The Don City - National Bank</title>
    <link rel="stylesheet" type="text/css" href="templates/box.css" />
    <script type="text/javascript" src="templates/javascript/jquery.js"></script>
    <script type="text/javascript" src="templates/javascript/boxxybabe.js"></script>
    
    <script type='text/javascript' src='templates/javascript/collier_test.js'></script> 
    
    <style>
    .hide {
    	display: none;
    }
    </style>
    </head>
    <body>
    <tr>
    <form name="form1" method="post" action="">
    <br />
    
    
    <?php 
    
    if($_GET['page'] == ""){
    
    
    //Owner Control Panel Access
    
    if ($fetch_owner->id == $fetch->id){
    echo "<br><center>National Bank Control Panel";
    }
    ?>
    <br />
    <table width='77%' align='center'>
    <td width='50%' valign='top'>
    <table width="400" border="0" align="center" class="table">
    <tr class='table' colspan='2'>
    <td class='header' colspan='2'>National Bank</td>
    </tr>
    <tr class='table' colspan='2'>
    <tr class='table'>
    <td class='subhead' colspan='2'><?php echo"$bankle->bank charges $bankle->commission% tax."; ?></td>
    </tr>
    <tr class='table' colspan='2'>
    <td class='table'>Reciepient:</td>
    <td class='table'><input type='text' class='tb' name='to_person' id='to_person' style='width:87%'></td>
    </tr>
    <tr class='table' colspan='2'>
    <td class='table'>Amount:</td>
    <td class='table'><input type='text' class='tb' name='send_amount' id='send_amount' style='width:87%' onKeyUp="moneyInput(this, 'send_amount');"></td>
    </tr>
    <tr class='table' colspan='2'>
    <td class='table'>Reciepient Type:</td>
    <td class='table'><select type='text' class='tb' name='type' id='type' style='width:87%' >
                      <option value='user' selected>Player</option>
    				  <option value='crew'>Detectives - Coming Soon</option>
    </td>
    <tr class='table' colspan='2'>
    <td class='table'>Message:</td>
    <td class='table'><textarea type='text' class='tb' name='send_message' id='send_message' style='width:87%' rows='5'></textarea></td>
    </tr>
    <tr class='table' colspan='2' align='center'>
    <td class='table' colspan='2' align='center'><center><input type='submit' class='button' name='send_button' id='send_button' style='width:27%' value='Send'></td>
    </table>
    
    
    <td width='50%' valign='top'>
    <table width="400" border="0" align="center" class="table">
    <tr class='table' colspan='2'>
    <td class='header' colspan='2'>National Bank</td>
    </tr>
    <tr class='table' colspan='2'>
    <tr class='table'>
    <td class='subhead' colspan='2'><?php if ($fetch->banktime <= time()){ echo "You can withdraw or deposit!";  }else{ echo "You can withdraw your money in <span id='Countdown'></span> ".maketime($fetch->banktime).""; } ?></td>
    </tr>
    
    
    <script>
    
    
    var seconds=<?php if($fetch->banktime <= 0 ){ echo""; }else{ echo"$fetch->banktime"; }?>;
    function display(){
    seconds=seconds-1;
    if(seconds<0){
    self.location.replace('../bank.php');
    }
    else
    {
    var countdown = document.all? document.all["Countdown"] : document.getElementById? document.getElementById("Countdown") : "";
    if (countdown)  {
    countdown.innerHTML=seconds;
    setTimeout('display()',1000);
    
    }
    }
    }
    display();
    </script>
    
    
    
    <tr class='table' colspan='2'>
    <td class='table'>Funds:</td>
    <td class='table'><?php echo "$".makecomma($fetch->bank).""; ?></td>
    </tr>
    <tr class='table' colspan='2'>
    <td class='table'>Amount:</td>
    <td class='table'><input type='text' class='tb' name='the_amount' id='the_amount' style='width:87%' onKeyUp="moneyInput(this, 'the_amount');"></td>
    </tr>
    <tr class='table' colspan='2'>
    <td class='table'>Type:</td>
    <td class='table'><select type='text' class='tb' name='bank_type' id='bank_type' style='width:87%' >
                      <option value='1' selected>Deposit</option>
    				  <option value='2'>Withdraw</option>
    </td>
    <tr class='table' colspan='2'>
    <td class='table'>Mercenary:</td>
    <td class='table'>If you even become a mercenary in your Don City, you'll be able to open a swiss bank, and get half the transfer commision price!</td>
    </tr>
    <tr class='table' colspan='2' align='center'>
    <td class='table' colspan='2' align='center'><center><input type='submit' class='button' name='update_button' id='update_button' style='width:27%' value='Update Account'></td>
    </table>
    </td>
    </table>
    <br /><br />
    
    
    
    
    
    
    <table width='450' align='center' class='table' colspan='2'>
    <td class='subtable' align='center'><center><a href='?page=logs'><img src='templates/DC/viewtransfers.png' border='0'></a></td>
    </table>
    <br />
    <?php } ?>
    
    <?php 
    
    if($_GET['page'] == "logs"){
    
    ?>
    <br />
    
    
    <table width='77%' align='center'>
    <td width='50%' valign='top'>
    <table width='350' align='right' class='table' id='bank'>
    <tr align='left'>
    <td class='header' colspan='4'> Last 10 Transactions Sent</td>
    </tr>
    <tr align='left" colspan='4'>
    <td class='subhead' width='33%'>Username</td>
    <td class='subhead' width='33%'>Amount Sent</td>
    <td class='subhead' width='34%'>Date of Transaction</td>
    <td class='subhead' width='14%'>Message</th>
    </tr>
    <?php 
    
    $track = mysql_query("SELECT * FROM `banktransfers` WHERE `from` = '".$fetch->username."' ORDER BY `id` DESC LIMIT 10");
    
    $rows = mysql_num_rows(mysql_query("SELECT * FROM `banktransfers` WHERE `from` = '".$fetch->username."'"));
    
    if ($rows == "0"){ echo "<td align='center' colspan='4' class='table'><center>You have not sent any transactions.</td></tr>"; }
    
    while($find = mysql_fetch_object($track)){
    
    $find_fetch = mysql_fetch_object(mysql_query("SELECT * FROM `users` WHERE `username` = '".$find->to."'"));
    
    echo "<tr align='left' class='table'>
    <td class='table'><a href='profile.php?user=$find_fetch->username'>$find->to</a></td>
    <td class='table'>&#163;".makecomma($find->amount)."</td>
    <td class='table'>$find->date</td>
    <td class='table'><a href='?page=view' rel='rel-25'>(View)</a></td>
    <tr id='465' class='hide'>
    <td class='table'>$find->message</td>
    </tr>";
    }
    ?>
    <script type="text/javascript">
    $(document).ready(function(){ 
    	$("a[rel='rel-25']").colorbox({width:"450", height:"175", iframe:true, transition:"none", current:"", opacity:0});	
    });
    </script>
    
    </table>
    </td>
    
    <td width='50%' valign='top'>
    <table width='350' align='right' class='table' id='bank'>
    <tr align='left'>
    <td class='header' colspan='4'> Last 10 Transactions Recieved</td>
    </tr>
    <tr align='left" colspan='4'>
    <td class='subhead' width='33%'>Username</td>
    <td class='subhead' width='33%'>Amount Received</td>
    <td class='subhead' width='34%'>Date of Transaction</td>
    <td class='subhead' width='14%'>Message</th>
    </tr>
    <?php 
    
    $bankfind = mysql_query("SELECT * FROM `banktransfers` WHERE `to` = '".$fetch->username."' ORDER BY `id` DESC LIMIT 10");
    
    $rows = mysql_num_rows(mysql_query("SELECT * FROM `banktransfers` WHERE `to` = '".$fetch->username."'"));
    
    if ($rows == "0"){ echo "<td align='center' colspan='4' class='table'><center>There is no received transactions.</b></td></tr>"; }
    
    while($check = mysql_fetch_object($bankfind)){
    
    $check_fetch = mysql_fetch_object(mysql_query("SELECT * FROM `users` WHERE `username` = '".$check->from."'"));
    
    echo "<tr align='left' class='table'>
    <td class='table'><a href='profile.php?user=$check_fetch->id'>$check->from</a></td>
    <td class='table'>$".makecomma($check->amount)."</td>
    <td class='table'>$check->date</td>
    <td class='table'><a href='javascript: ;' onclick='showMessage('465')'>(View)</a></td>
    <tr id='465' class='hide'>
    <td class='table'>$check->message</td>
    </tr>";
    }
    ?>
    
    
    
    </table>
    <?php } ?>
    
    
    
    <?php 
    
    if($_GET['page'] == "view"){
    
    ?>
    
    <style type="text/css">
    body {
    	background-color: #222;
    	padding-top: 4px;
    }
    .content {
    	z-index: 2;
    	width: 359px;
    	margin-left: auto;
    	text-align: left;
    	margin-right: auto;
    	margin-top: auto;
    	margin-bottom: auto;
    }
     
    .content-top {
    	height: 21px;
    	color: #222;
    	padding-left: 15px;
    	padding-top: 7px;
    	font-size: 11px;
    	font: 11px Tahoma, Verdana, Arial, Helvetica, sans-serif;
    }
    .content-main {
    	color: #222;
    	padding-left: 25px;
    	padding-top: 7px;
    	font-size: 11px;
    	background-color: #1a1a1a;
    	font: 11px Tahoma, Verdana, Arial, Helvetica, sans-serif;
    }
    .content-bottom {
    	height: 25px;
    	color: #222;
    	background-color: #1a1a1a;
    	text-align: center;
    	font-size: 11px;
    	line-height: 25px;
    }
    a:visited, a:active, a:link {
    	text-decoration: none;
    	color: #8b8b8b;
    	font-size: 12px;
    	font-weight: bold;
    	font-family: Tahoma, Verdana;
    }
    a:hover {
    	text-decoration: underline;
    	color: #8b8b8b;
    	font-size: 12px;
    	font-weight: bold;
    	font-family: Tahoma, Verdana;
    }
    </style>
    <table width="100%" height="60%">
    	<tr><td valign="middle" height="100%">
    	<div class="content"> 
    		<div class="content-main"> 
    		<font color='#333333'>A message was attached containing:<br />
    		Test'in message
    		
    		</div> 
    		<div class="content-bottom"><div style='float:left;'><font color='#333333'>Statement #0285</div><div style='float:right; padding-right: 13px;'>$500,000,000</div></div> 
    		</div> 
    	</div> 
    	</td></tr>
    
    </table>
    
    <?php } ?>
    HTML:
     
    Last edited: Sep 27, 2010
    iDaTa, Sep 27, 2010 IP
    SEMrush
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,681
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    May get a better response in the PHP forum rather than the ASP one.... of cause in ASP.Net it is all very simple but you're probably not wanting to switch programming languages
     
    AstarothSolutions, Sep 30, 2010 IP
  3. iDaTa

    iDaTa Member

    Messages:
    144
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #3
    Will go about trying this; thanks for notifying me. ;]
     
    iDaTa, Sep 30, 2010 IP
  4. prptl709

    prptl709 Guest

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I don't know about the Ajax.please help how to use the ajax control in my application
     
    prptl709, Mar 1, 2011 IP