[thelist] php add email to a mysql db

Ben Phillips ben at inchima.com
Tue Aug 13 10:30:50 CDT 2002


there are a few syntax errors in the code. i've altered them below:

> this is the code:
>
> include("settings.inc");
>
> mysql_connect("$dbhost","$dbuser","$dbpass");
>
> $sql = "SELECT email FROM mailinglux WHERE
>           email='$email'";
>          $result=mysql_query($sql);
>          $num=mysql_numrows($result);

mysql_numrows() should be mysql_num_rows().

>          if ($num > 0)

when using if statements, surround all blocks in curly brackets. so:

if ($num > 0) {

  // do stuff when $num > 0
  echo "...";

} else {

  // do stuff when $num isn't > 0
  mysql_error()
  ...

}

it's a lot easier to read, for you and for others, and will also make
spotting errors easier.

benji.
inchima.com





More information about the thelist mailing list