Note that there are some explanatory texts on larger screens.

plurals
  1. POForm input correction & database query- Codeigniter
    text
    copied!<p>Hey guys. I'm re-creating a registration for my website using codeigniter. On my previous page I did it in simple php and HTML. Now that I'm trying to recreate it in codeigniter I seem to be running into difficulties. </p> <p>The following code is a function that is called to validate an email address that the user puts in. It is supposed to query the database and check if the email already exists. If it does, print an error message, if not, everything is hunky dorey.</p> <pre><code>function email_check($str) { $num = $this-&gt;db-&gt;count_all("SELECT email FROM mytable WHERE email='$str'"); if ($num &gt; 0) { $this-&gt;validation-&gt;set_message('username_check', 'Email already in use'); return FALSE; } else { return TRUE; } } </code></pre> <p>However I keep on getting mysql errors. Along the lines of</p> <blockquote> <p>Error Number: 1064</p> <p>You have an error in your SQL syntax;</p> </blockquote> <p>or</p> <p>alternatively when i use</p> <pre><code>function email_check($str) { $database_email_check = ("SELECT email FROM myTable WHERE email='$str'"); $email_check = $this-&gt;db-&gt;query($database_email_check); $num = mysql_num_rows($email_check); if ($num &gt; 0) { $this-&gt;validation-&gt;set_message('username_check', 'Email already in use'); return FALSE; } else { return TRUE; } } } </code></pre> <p>gives the error</p> <blockquote> <p>mysql_num_rows(): supplied argument is not a valid MySQL result resource</p> </blockquote> <p>Any help would be appreciated. Including a facepalm and correction in my code. I'm convinced it's something stupid that I just can't see.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload