Solved

PHP Help Needed

Posted on 2013-01-11
5
426 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

910 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now