Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6913585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:14:15+00:00 2026-05-27T09:14:15+00:00

Hi, I have made this simple script but I need to have it check

  • 0

Hi, I have made this simple script but I need to have it check if the balance is correct before it goes into negative. How can I add a line to do this, and what should be in this line? An example would be really good, as none are around for this specific function.

Here is the code as is. There are two files, so I can always make edits for different amounts.

<php code>


<? require ("tracker.php");

?>


<center>
<?php 
include 'dbc.php';


?>
<title>J~Net Level Up</title>
 <?php session_start();
 $id = $_SESSION['user_id']; 
 // Connects to your Database 
 mysql_connect("localhost", "root", "pass") or die(mysql_error()); 
 mysql_select_db("messages") or die(mysql_error()); 
 $data = mysql_query("UPDATE `users` SET `balance` = `balance` - 1000 WHERE `users`.`id` =$id") 
 or die(mysql_error()); 
 echo "<table border cellpadding=3>"; 
 while($info = mysql_fetch_array( $data )) 
{ 
 echo "<tr>"; 
 echo "<th>User:</th> <td>".$info['user_name'] . "</td> "; 
 echo "<th>Balance:</th> <td>".$info['balance'] . " </td></tr>"; 
 } 
 echo "</table>";
 // echo "Balance Is ".$_SESSION['balance']; 
echo $row['user_name'] . " " . $row['balance'];
 ?>
<META HTTP-EQUIV=REFRESH CONTENT="0; URL=010101levup.php">

<end php code for page 1>

Page 2 does the magic afterwards. The first page is for sorting out the balance, and the second page only carries on after the balance amount has been validated by page 1, so doesn’t really needed to be added at this point.

Any ideas? Anyone, please help, if at all possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:14:15+00:00Added an answer on May 27, 2026 at 9:14 am

    This should do as you wish, subtracts 1000 if the users balance > 0 else sets to 0

    <php code>
    
    
    <? require ("tracker.php");
    
    ?>
    
    
    <center>
    <?php 
        include 'dbc.php';
    
    
    ?>
    <title>J~Net Level Up</title>
     <?php session_start();
     $id = $_SESSION['user_id']; 
     // Connects to your Database 
     mysql_connect("localhost", "root", "pass") or die(mysql_error()); 
     mysql_select_db("messages") or die(mysql_error()); 
    
     $user = mysql_query("SELECT * FROM `users` WHERE `users`.`id` =$id") or die(mysql_error());
    
     $balance = $user['balance'] > 1000 ? ($balance - 1000) : 0;
    
     mysql_query("UPDATE `users` SET `balance` = $balance WHERE `users`.`id` =$id") 
     or die(mysql_error()); 
     echo "<table border cellpadding=3>"; 
     //while($info = mysql_fetch_array( $data )) 
     //{ 
         echo "<tr>"; 
         echo "<th>User:</th> <td>".$user['user_name'] . "</td> "; 
         echo "<th>Balance:</th> <td>".$balance . " </td></tr>"; 
     //} 
     echo "</table>";
     // echo "Balance Is ".$balance; 
    echo $user['user_name'] . " " . $balance;
     ?>
    <META HTTP-EQUIV=REFRESH CONTENT="0; URL=010101levup.php">
    
    <end php code for page 1>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this custom, simple script I made, somehow it's failing but it always
I have made a simple chat script using jquery and AJAX but the huge
I have made some progress with the DataList and UserControl this morning but I
Hi I made this site a while ago in my table days but have
I need your help. I have made a really clean and simple example to
I have this simple script: function orientation() { var orientation = window.orientation; switch(orientation) {
I have made a simple script application which accepts radius as input from user
I have been trying everything I can to get this script to work and
This javascript I have is supposed to be very simple. It is, but IE
Hi have made this function which is made to replicate an error that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.