Question about simple PHP syntax...

So I have a bit of code that upon submit of a page (a page that has a simple checkbox on it with a value of “1”) should update a record in the database to reflect that the checkbox was checked by the website user.

if($_POST){
	$cr = ($_POST["agree"] == 1)? 1:0;
	$res = mysql_query("update mytable set useragreed='$cr' where id='$_ARTICLE[id]'");

I program in other languages, so I’m confident I understand what’s going on here.

The one thing I don’t understand is what the “1:0” at the end of the second line is doing.

Basically for some reason the database is not being updated, and I’m trying to troubleshoot as to why.

That is a Ternary operator. It is saying if post agree is 1 then $cr =one or else it equals zero. Also, you are using obsolete MySQL. You need to use PDO or Mysqli. The other problem is the quotes around your update variables and also the lack of in your article id variable…

Sponsor our Newsletter | Privacy Policy | Terms of Service