Solved

PHP Help Needed

Posted on 2013-01-11
5
451 Views
Last Modified: 2013-01-11
I have a table in my database named clerk_names. In this database there is a colum named active & by default they are all set to 0. Will this code mark all the entries in the active columnn to 1?

<?phprequire('connection.php');$query="UPDATE clerk_names SET active = '1' ";?>

Open in new window


Basically, I will be calling this script from a web page & when it is called I need it to mark all the 0's in active field to 1. There are only 10 entries in the active field. Thanks for any help provided.
0
Comment
Question by:wantabe2
5 Comments
 
LVL 12

Expert Comment

by:adrian_brooks
ID: 38768681
That code will update every record in your table setting active to 1.
0
 
LVL 12

Assisted Solution

by:adrian_brooks
adrian_brooks earned 200 total points
ID: 38768685
If you wish to mark all 0's to 1's, do this instead;

$query="UPDATE clerk_names SET active = '1'  where active = '0'";

Open in new window

0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 200 total points
ID: 38768727
The answer from looking at the code is no.
<?php require('connection.php');$query="UPDATE clerk_names SET active = '1' ";?>

Open in new window

should be
<?php 
require('connection.php');
$query="UPDATE clerk_names SET active = '1' where active = '0' ";
$result = mysql_query($query) or die("There was an error");
?>

Open in new window

0
 
LVL 27

Assisted Solution

by:yodercm
yodercm earned 100 total points
ID: 38768745
It matters if the only two possible values in that field are 0 and 1.

What you wrote will set ALL values in that column to 1 regardless of what is there.

If you want to change only the 0's to 1's, then use what adrian_brooks and roads_roads gave you.

If there are other possible values, including blanks for example, you might need more decision making in your query.
0
 
LVL 15

Author Comment

by:wantabe2
ID: 38768759
Thanks everyone!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question