Jump to content

Recommended Posts

Hello!

 

i want help with php snippet for function like this:

 

Users can buy athletes with points wich they have get when they registrated.

I also want it if the user don`t have points to buy one athlete the "buy" button

would be disabled. Please help me with php code how i can fix it!

 

This is a screenshot how i want the function look like:

http://img9.imageshack.us/img9/840/webmanagergame.png

Link to comment
https://forums.phpfreaks.com/topic/243125-help-with-online-based-manager-phpmysql/
Share on other sites

Do you want us to code for you, or do you actually plan on implementing an example into your existing code?

 

This is a VERY VERY simple logic problem, and if you're able to code a whole purchasing system, this shouldn't be a problem. Don't give me BS like "I'm trying to learn." A complex script is a terrible spot to start, especially if you cant grasp if/then/comparison operators.

 

When you loop out your items to display them, add a simple check

if( $users_points < $item_cost ) {
echo '<button type="button" disabled="disabled">Not Enough Money</button>';
} else {
echo '<input type="submit" name="buy" value="Buy me">';
}

 

 

This is how far i have come with the code please help me out, i also think im doing wrong!

and the code is not finished!

 

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<p><a href="">Logga UT</a> - <a href="byggalaget.php">Köp cyklister</a> - <a href="kalender.php">Kalender</a>- <a href="profil.php?anv=$anv">Min Profil</a></p>
<h1>Här bygger du ditt lag!</h1>
<?php
session_start();
?>
<?php
# anslutning till databas!´
$databashost = "localhost";
$dbanvandare = "root";
$dblosenord = "**********";
$databas = "cykelarenan";

$anslutning = mysql_connect($databashost, $dbanvandare, $dblosenord) or die("kunde för tillfället inte ansluta till databasen!");

mysql_select_db($databas) or die("Databas problem!");

#hämtar cyklisterna och information från dem!

mysql_query("SELECT * FROM cyklister") or die("Något tillfället fel med servern!");

# köp funktionen!
$pris = if($saldo < $priset) {
"";
else
"  <input type="hidden" name="button" id="button"  value="Köp" />";
}



# tabell med cyklisterna + köp funktionen!

echo '$cyklist';
echo '$pris';
echo '$kop';
echo '</table>';
?>
</body>
</html>

this...

$pris = if($saldo < $priset) {
"";
else
"  <input type="hidden" name="button" id="button"  value="Köp" />";
}

 

should be this...

$pris = if($saldo < $priset) {
   echo "";
        }
else {
echo "  <input type="hidden" name="button" id="button"  value="Köp" />";
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.