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

  • Home
  • SEARCH
  • 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 8515207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:05:08+00:00 2026-06-11T05:05:08+00:00

On the below code up to echo $AA it works! The echo shows the

  • 0
  1. On the below code up to echo $AA it works! The echo shows the $rec[‘totsb’] minus 1 correctly, subtracting 1 from the existing value in the database. Then I need to save the new number generated after reducing one back to the database which is where my code is for sure is wrong. I tried many alternatives to correct it but couldn’t get through. Can some one tell me how to save the new number back to the database?

info: my database looks like below. And as you see in between numbers are populated in a drop down to be selected by the user.(database has only starting 302 and end as 309, drop down has all 302,303,304…309) So if a user picks 306 for instance it should automatically identify in between which start and end number 306 fits in and save the new number as appropriate in totsb.

+--------+---------+------+
|sbstart |sbend    | totsb|
+--------+---------+------+
|302     |309      | 8    |
|200     |208      | 9    |
|405     |409      | 5    |
+--------+---------+------+

Code:

<?php
$con=mysql_connect('localhost','root') or die ("Server connection failure!");
$db=mysql_select_db('regional_data',$con) or die ("Couldn't connect the database");
$SQL="SELECT * FROM newchk";
$run=mysql_query($SQL,$con) or die ("SQL Error");
$nor=mysql_num_rows($run);

while ($rec = mysql_fetch_array($run))
{
for($i=$rec['sbstart']; $i<=$rec['sbend']; $i++)
    {
    $opt=$_POST['options'];
    if($i = $opt)
     {
        if($rec['totsb'] <= "0")
        {
        echo "You have already entred this cheque number."; 
        return false;
        } else {
        echo "You can proceed with this entry";
        $AA = $rec['totsb']-1;
        $BB=$rec['sbstart'];
        echo $AA;
        $con=mysql_connect('localhost','root') or die ("Server connection      failure!");
        $db=mysql_select_db('regional_data',$con) or die ("Couldn't connect the     database");
        $SQL="UPDATE newchk SET totsb='$AA'";   
        return false;
        }
     }
     else 
     { echo "Error: Cant find choosen in the databse"; 
      return false;
     }
    }
}
?>
  • 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-06-11T05:05:09+00:00Added an answer on June 11, 2026 at 5:05 am

    unless you are missing code…

    1) you are not doing anything with the SQL statement (need to actually run it) as you did the first one.
    2) if the amount is numeric as you indicate in your table chema, you don’t need quotes around it
    3) also recommend using your sbstart as a qualifier for the record to update or you will update everything.

    $SQL2="UPDATE newchk SET totsb=$AA where sbstart=$BB"; 
    $run2=mysql_query($SQL2,$con) or die ("SQL Error"); 
    

    if that doesn’t help, send more info on your database schema

    added code

    $matches=0;
    $opt=$_POST['options'];
    while ($rec = mysql_fetch_array($run)){
        if($opt>=$rec['sbstart'] && $opt<=$rec['sbend']){
            # we have a match, run your code
    
            if($rec['totsb'] <= "0") 
            { 
            echo "You have already entred this cheque number.";  
            return false; 
            } else { 
            echo "You can proceed with this entry"; 
            $AA = $rec['totsb']-1; 
            $BB=$rec['sbstart']; 
            echo $AA; 
            $con=mysql_connect('localhost','root') or die ("Server connection      failure!"); 
            $db=mysql_select_db('regional_data',$con) or die ("Couldn't connect the     database"); 
    # fixed lines
            $SQL2="UPDATE newchk SET totsb=$AA where sbstart=$BB"; 
            $run2=mysql_query($SQL2,$con) or die ("SQL Error"); 
    # end fixed lines
            return false; 
            } 
            # end your code
            $matches++
        }else{
            # no match
        }
    } # while loop through records
    
    if($matches==0){
        echo "Error: Cant find choosen in the databse";  
        return false; 
    }else{
        return true;
    }
    

    you could clean up your code a bit more, but that should get you on the right track

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below takes an array value, if it's key exist it should echo
I have a loading image that works using the code below. It shows the
In the code below, the echo at the top returns true, but the echo
For the code below, I would like to append echo $_SERVER['QUERY_STRING']; to the end
below code is my databasehandler class i got it from a tutorial. Beside that
I'm trying a simple ajax test in Wordpress / Buddypress. The code below works
I am trying to scrap some content from a website but the code below
I'm trying to return a count from mysql. My code is below $number_of_options_sql =
I was hoping I could get some help from you guys. The code below
The code below works all fine and dandy. However, I would like to put

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.