Link to home
Start Free TrialLog in
Avatar of bschwarting
bschwarting

asked on

mysql syntax - if then and

why isn't this working?

if ((mysql_num_rows($result) > 0) and $date1 != '' then {

i need to check two things, if the $result is great than zero and make sure $date isn't blank.
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

what about this:
if (  ((mysql_num_rows($result) > 0) && ($date1 != '' ) ) {

Open in new window

Avatar of bschwarting
bschwarting

ASKER

angelIII, that didn't work either.
can you clarify "does not work"
the page is blank, if i remove this code, it works fine
if (  ((mysql_num_rows($result) > 0) && ($date1 != '' ) ) then {
$sql2 = "INSERT INTO $createtablename (date2, timesubmit2, answer2) VALUES ( ' $date1 ' , ' $timesubmitcombine ' , ' $answer ' ) ;";
mysql_query($sql2) or die ("Error in query: $sql2. ".mysql_error());
  echo "Updated";
 }
 else {
  echo "NOT READY TO INSERT";
 }

Open in new window

remove "then" , that is not PHP code.
yeah, i tried both ways, still doesn't work.
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try this

if  ((mysql_num_rows($result) > 0) && ($date1 != '' ) ) {
$sql2 = "INSERT INTO $createtablename (date2, timesubmit2, answer2) VALUES ( ' $date1 ' , ' $timesubmitcombine ' , ' $answer ' ) ;";
mysql_query($sql2) or die ("Error in query: $sql2. ".mysql_error());
  echo "Updated";
 }
 else {
  echo "NOT READY TO INSERT";
 }
sorry try this

if  ((mysql_num_rows($result) > 0) && ($date1 != '') ) {
$sql2 = "INSERT INTO $createtablename (date2, timesubmit2, answer2) VALUES ( ' $date1 ' , ' $timesubmitcombine ' , ' $answer ' ) ";
mysql_query($sql2) or die ("Error in query: $sql2. ".mysql_error());
  echo "Updated";
 }
 else {
  echo "NOT READY TO INSERT";
 }
sorry all, i thought i closed this.

angelIII last response fixed it.  i think we had a double (( before mysql_num_rows and only needed a single (