Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Update a mysql field using PHP

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Update a mysql field using PHP

Postby tonypward » Sat May 11, 2013 12:18 am

Hi all

A bit of a newbie to php and mysql. I am having a tiny issue with the following code:

Code: Select all
$datenowis = date("Y-m-d");
$datecheck = date("Y-m-d", strtotime($row_rsAllEvents['event_date']));
if ($datecheck > $datenowis) {
   
  $updateSQL = sprintf("UPDATE all_events_tbl SET active='no'",
                       
                       GetSQLValueString($_POST['active'], "text"));

  mysql_select_db($database_myfsesql, $myfsesql);
  $Result1 = mysql_query($updateSQL, $myfsesql) or die(mysql_error());
}


What I am trying to do is update the 'active' field, if the event date has passed. What seems to be happening here is all the events get updated to 'no'. I have tried both the greater-than / less-than symbols. What am I doing wrong? Also can anyone confirm what we call these in php world, symbols, operators or something else?

Sorry a footnote to this, I think I need to do above code as a function as the mysql update is in a do while loop. I have a feeling that it is passing the same value all the time. That's newbies for you.
Not sure how to do that and get a result passed back to the loop, if you know what I mean.

Thanks for looking
Tony
tonypward
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sat May 11, 2013 12:05 am

Re: Update a mysql field using PHP

Postby okoa » Sun May 12, 2013 9:19 am

I am not sure if I got you right, but I think you need to add the WHERE clause on your update query.
okoa
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed May 08, 2013 9:18 am

Re: Update a mysql field using PHP

Postby swarups » Sun May 12, 2013 9:59 pm

hi

You need to add Where clause at the end of query. like:

WHERE event date < current date;

Thanks
Swarup Sahu
http://www.mindfiresolutions.com/
swarups
New php-forum User
New php-forum User
 
Posts: 20
Joined: Tue Mar 06, 2012 11:05 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.