473,378 Members | 1,479 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,378 software developers and data experts.

add/subtract php mysql

Expand|Select|Wrap|Line Numbers
  1. $existing= "select * from * where id = 2";
  2. $exist=mysql_query($existing);
  3. $num=mysql_numrows($exist);
  4. if($num == 0)
  5. {
  6. echo " ";
  7. }
  8. else
  9. {
  10. if(isset($_POST['*'])){
  11. $add=1;
  12. $query="update * set *=*+$add where id=1";
  13. mysql_query($query) or die("Cannot update");
  14. }
  15. if(isset($_POST['*'])){
  16. $subtract=1;
  17. $query="update * set *=*-$subtract where id=2";
  18. mysql_query($query) or die("Cannot subtract");
  19. }
  20. }
  21.  

can anyone help me.... even if the value in the database equals zero it still does the else instead of echoing the message.
Nov 9 '12 #1
2 2182
Rabbit
12,516 Expert Mod 8TB
What do you mean by if the value in the database equals 0? The mysql_numrows() function only returns 0 if the query returned no data.
Nov 9 '12 #2
Dormilich
8,658 Expert Mod 8TB
why in the world are you not specifying the table you want to read from/write to? that can mess up your DB server faster than you can say hippopotamus.

just because you can use a wildcard does not mean that this is a good idea (btw, it is never).
Nov 10 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ben | last post by:
I would like to use php to query a database and retrieve a unix timestamp. The problem is that mysql is storing the data in the date format and not a timestamp. I am sure that I can amend my...
4
by: Westcoast Sheri | last post by:
Two mySQL Questions: 1.) how to numerically increase or decrease the value of a mySQL column 2.) what is the best column structure (e.g. "varchar" or "char" etc.) for speediest...
0
by: PAUL MENARD | last post by:
--0-930715088-1061086093=:22602 Content-Type: text/plain; charset=us-ascii Hello All, I'm having trouble understanding the MySQL docs on how to subtract two DATETIME values. I have two tables...
3
by: John | last post by:
I would like to subtract tow fields in table for example Table1 has fields A, B, C I wrote the statement as follows Select A, B, (A-B) as diff from Table1. MySQL is complaining that there...
3
by: Me Alone | last post by:
Hello: I am trying to edit some C code I found in "The definitive guide to using, programming, and administering MySQL" by Paul DuBois. This C client program connects and then segfaults when...
6
by: Brandon | last post by:
I'm using PHP with MySQL 4.x and was having trouble converting a datetime from MySQL into a formatted string until I ran across this solution that converts a YYYY-MM-DD HH:MM:SS string into a...
2
by: deepbright | last post by:
I'm having trouble understanding the MySQL docs on how to subtract two DATETIME values. I have two tables that have a DATETIME column. In my SELECT I am doing a JOIN to bring in both sets of rows....
1
by: chemz | last post by:
hi all, i have problem in creating a formula of my code. this is all about updating a mysql database in including it in php. I dont know how to generate it. can you please give me some code in a...
6
by: lptl | last post by:
I know the title is misleading. I am working on a class project where we are trying to setup a notification system written in PHP and using an MySQL database. We are trying to set-up a notification...
4
by: luxsphinx | last post by:
OS: Ubuntu Linux PHP: v5.3.2 MySQL: v5.1.41 Hello all, I'm new to Bytes, but I'm hoping that someone here will be able to help me as I learn PHP and MySQL. With any luck, I'll understand it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.