473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

strange variables

Hi, when i use the following code;

$current_available = mysql_query("SELECT availableplaces FROM
tblCourses WHERE course_id='$_POST[selectedcourse]'");
$current_available -= 1;
mysql_query("UPDATE tblCourses SET
availableplaces='$current_available' WHERE
course_id='$_POST[selectedcourse]'");
The variable $current_available is initially 32, after running the
above it is changed to 2.

I'm really lost and would appreciate some direction.

Many thanks
Jul 17 '05 #1
3 1556
none wrote:
Hi, when i use the following code;

$current_available = mysql_query("SELECT availableplaces FROM
tblCourses WHERE course_id='$_POST[selectedcourse]'");
$current_available -= 1;
mysql_query("UPDATE tblCourses SET
availableplaces='$current_available' WHERE
course_id='$_POST[selectedcourse]'");


I think I understand what you want, however you are doing it wrong.
Firstly you have an error, you need to fetch the result then decrement it.

$course_places = mysql_query("SELECT `availableplaces` - 1 FROM
`tblCourses` WHERE `course_id`='$_POST[selectedcourse]' LIMIT 1");
$amount_available = mysql_result($current_available, 0, 'availableplaces');
mysql_query("UPDATE `tblCourses` SET
`availableplaces`='$amount_available' WHERE
`course_id`='$_POST[selectedcourse]' LIMIT 1");

That should work, however there is a much faster, and easier way of
doing it (UNLESS YOU WANT THE AMOUNT AVAILABLE)!

mysql_query("UPDATE `tblCourses` SET
`availableplaces`=`availableplaces`-1 WHERE
`course_id`='$_POST[selectedcourse]' LIMIT 1");
Jul 17 '05 #2
ki*****@aol.com (none) wrote in message
news:<86**************************@posting.google. com>...

when i use the following code;

$current_available = mysql_query("SELECT availableplaces FROM
tblCourses WHERE course_id='$_POST[selectedcourse]'");
$current_available -= 1;

The variable $current_available is initially 32, after running the
above it is changed to 2.

I'm really lost and would appreciate some direction.


OK, here is your code again, slightly reformatted:

$current_available = mysql_query("SELECT availableplaces
FROM tblCourses WHERE course_id='$_POST[selectedcourse]'");

This makes $current_available a resource.

$current_available -= 1;

Now all of a sudden you decide to treat $current_available as if
it were an integer. Needless to say, the results are not what
you expect them to be...

Cheers,
NC
Jul 17 '05 #3
nc@iname.com (Nikolai Chuvakhin) wrote in message news:<32*************************@posting.google.c om>...
ki*****@aol.com (none) wrote in message
news:<86**************************@posting.google. com>...

when i use the following code;

$current_available = mysql_query("SELECT availableplaces FROM
tblCourses WHERE course_id='$_POST[selectedcourse]'");
$current_available -= 1;

The variable $current_available is initially 32, after running the
above it is changed to 2.

I'm really lost and would appreciate some direction.


OK, here is your code again, slightly reformatted:

$current_available = mysql_query("SELECT availableplaces
FROM tblCourses WHERE course_id='$_POST[selectedcourse]'");

This makes $current_available a resource.

$current_available -= 1;

Now all of a sudden you decide to treat $current_available as if
it were an integer. Needless to say, the results are not what
you expect them to be...

Cheers,
NC

Thanks for the input,

I'm quite new to php but i suspected it may be something I was doing
with the variables.

The query;

mysql_query("UPDATE `tblCourses` SET
`availableplaces`=`availableplaces`-1 WHERE
`course_id`='$_POST[selectedcourse]' LIMIT 1");

worked a treat, but the first one (long way) threw an error as not
been valid syntax.

Cheers anyway :o)
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Francesco [tRO] | last post by:
Hi everybody! I developed a suite of php scripts and i've tested it with PHP 4.3.3 and Apache; obiouvsly all works fine. Now I had a customer that want to buy my application and it needs to run...
2
by: Jeff Homan | last post by:
Hello, I don't know where to begin with this as it's kind of a strange error and I can't figure it out. I've got a form that I pass several variables to a php page. One of the variables is a...
0
by: Daniel O'Brien | last post by:
Hi - any help with this would be greatly appreicated - it has already had me confused for a good few hours! I am using Visual Studio 2003 and the .NET framework 1.1. I have a C# Windows...
3
by: Alfonso Morra | last post by:
I have some code that I am porting over from C. It is full of static functions and global variables. I have got around this by wrapping most of the code in a singleton object. However, I am...
3
by: Sameh Halabi | last post by:
Hi I have a strange problem in C , I hope someone may help with it . the problem is as follows : I have an existing big structure (that I can't change) which contains in it groups of...
6
by: Edd Dawson | last post by:
Hi. I have a strange problem involving the passing of command line arguments to a C program I'm writing. I tried posting this in comp.programming yesterday but someone kindly suggested that I'd...
11
by: Marlene Stebbins | last post by:
Something very strange is going on here. I don't know if it's a C problem or an implementation problem. The program reads data from a file and loads it into two arrays. When xy, x, y, *xlist and...
1
by: shalin | last post by:
I am having a strange problem in my ASP.NET application. When multiple users access the web site, the changes done by a user gets reflected in another users session. I have some global...
0
by: theintrepidfox | last post by:
Dear Group I came accross a very annoying behaviour of Visual Studio, giving me six hours of headache till I found the solution. This post is mainly for fellow developers for reference as it...
1
by: Crutcher | last post by:
I've been playing with dictionary subtypes for custom environments, and I encountered a strange interaction between exec, dictionary subtypes, and global variables. I've attached a test program,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.