/    Sign up×
Community /Pin to ProfileBookmark

MYSQL bit(1) field reading and writing to in PHP

Hello,

I am all to happy an confident with writing and reading from fields like varchar but I am struggling with a bit(1) mysql field. I can’t seem to change the content to either a 0 or a 1 as I guess because I am treating it like an ASCII value?

Below is my code — the bit field is called eventFull – I need to read the current value, if it is a 0 then swap it to a 1 and vice versa?

Could anyone help me?

$geteventssql2 = “SELECT * FROM `events` WHERE id = ‘”.mysql_real_escape_string($_POST[‘workshop’]).”‘”;
$geteventsresult2 = @mysql_query($geteventssql2,$connection) or die(mysql_error());
while($geteventsrow2 = mysql_fetch_array($geteventsresult2))
{
if ($geteventsrow2[‘eventFull’]==’0′) {$swap=1;}

if ($geteventsrow2[‘eventFull’]==’1′) {$swap=0;}

//print”<script>alert (‘Status has been changed’);</script>”;
//print”<script>document.location=’ticketing.php’; </script>”;
$sql = “UPDATE `events` SET eventFull = ‘”.$swap.”‘ WHERE id = ‘”.mysql_real_escape_string($_POST[‘workshop’]).”‘”;
$query = mysql_query($sql);

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@MarPloJul 03.2012 — Hi,

Try replace with this code in your script:
if ($geteventsrow2['eventFull'] === '0') {$swap=1;}
else if ($geteventsrow2['eventFull'] === '1') {$swap=0;}

If not works, try use the numbers 0 and 1 without quotes.
×

Success!

Help @rt050465 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...