Jump to content

Small Funtion


Dethman

Recommended Posts

Ok I need someone to help make me a Function... Details Below...

 

If the sql row Mothership is 0 Display button (<form name=elemental action=elemental.php method=post>

    <input type=submit value="Buy Elemental for 450,000,000 Naquadah & 6,000 Untrained Units"></form>).....

And then have that button change the Mothership row to 1...

 

Then if the sql row `Mothership` is 1 Display button (Outfit Mothership goto link /mothership.php)

 

 

 

here is the SQL code

 

$q = @mysql_query("select Mothership from `UserDetails` where ID='$user->ID'

 

 

Link to comment
https://forums.phpfreaks.com/topic/84473-small-funtion/
Share on other sites

//-----------BuyMS Function	
function BuyMS($user,$wal,$type)
{
$noNaquadah="Not enough Naquadah!";
$nosold="Not enough untrained units!";
if($type==0){
	$pris=350000000*$wal;
	if($pris <= ($user->gold)){
		$q = @mysql_query("select Mothership from `UserDetails` where ID='$user->ID' ");
		$el=mysql_fetch_array($q, MYSQL_ASSOC);
		if($el[]>=$wal){
			$q = @mysql_query("update `UserDetails` set Mothership = 1, gold=gold-'$pris' where ID='$user->ID' ");
			if (!$q) {print ('Query failed: '.mysql_error());	return;	}
		}else return $nosold;
	}
	else return $noNaquadah;
}

if($cgi[buyMS]){

	if($cgi[Mothership]){
		$wal=$cgi[Mothership];$typ=0;
		$detail.=Mothership($user,$wal,$typ);
	}

//-------------Button1		
	<form name=Mothership action=mothership.php method=post>
	  		  <input type=submit value="Buy Elemental for 450,000,000 Naquadah"></form>
//-------------Button2
form name= action=mothership.php method=post>
	  		  <input type=submit value="Outfit Mothership"></form>

 

I do not know how to do if else function I got this code off someone I need someone to make an if else function for me... there are the buttons and the code...Tell me if I got the BuyMS function right?

Link to comment
https://forums.phpfreaks.com/topic/84473-small-funtion/#findComment-430404
Share on other sites

<?php

function BuyMS($user, $wal, $type)
{
    $noNaquadah = "Not enough Naquadah!";
    $nosold = "Not enough untrained units!";
    if ($type == 0) {
        $pris = 350000000 * $wal;
        if ($pris <= ($user->gold)) {
            $q = @mysql_query("select Mothership from `UserDetails` where ID='$user->ID' ");
            $el = mysql_fetch_array($q, MYSQL_ASSOC);
            if ($el[] >= $wal) { // error on this line.
                $q = @mysql_query("update `UserDetails` set Mothership = 1, gold=gold-'$pris' where ID='$user->ID' ");
                if (!$q) {
                    print ('Query failed: ' . mysql_error());
                    return;
                }
            } else
                return $nosold;
        } else
            return $noNaquadah;
    }

    if ($cgi[buyMS]) {

        if ($cgi[Mothership]) {
            $wal = $cgi[Mothership];
            $typ = 0;
            $detail .= Mothership($user, $wal, $typ);
        }
    }
}
?>

 

since he's lazy.

Link to comment
https://forums.phpfreaks.com/topic/84473-small-funtion/#findComment-430438
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.