Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Being new to programming, I'll give you the classic message we give to people using the <code>mysql_*</code> functions:</p> <blockquote> <p><a href="http://bit.ly/phpmsql" rel="nofollow"><strong>Please, don't use <code>mysql_*</code> functions in new code</strong></a>. They are no longer maintained <a href="https://wiki.php.net/rfc/mysql_deprecation" rel="nofollow">and are officially deprecated</a>. See the <a href="http://j.mp/Te9zIL" rel="nofollow"><strong>red box</strong></a>? Learn about <a href="http://j.mp/T9hLWi" rel="nofollow"><em>prepared statements</em></a> instead, and use <a href="http://php.net/pdo" rel="nofollow">PDO</a> or <a href="http://php.net/mysqli" rel="nofollow">MySQLi</a> - <a href="http://j.mp/QEx8IB" rel="nofollow">this article</a> will help you decide which. If you choose PDO, <a href="http://j.mp/PoWehJ" rel="nofollow">here is a good tutorial</a>.</p> </blockquote> <p>However, as a straightforward answer to your question: instead of validating after you've inserted the results, validate before. <strong>Also, remember to sanitize (using <code>mysql_real_escape_string</code>) anything you insert into a database if you do use mysql_* functions.</strong> Sanitizing inputs will prevent from <a href="http://www.unixwiz.net/techtips/sql-injection.html#finduser" rel="nofollow" title="SQL injection">SQL injections</a> and remove some vulnerability issues.</p> <pre><code>if($errors) { // there are errors, don't submit to database // run through error display process } else { // submit to database $insert = mysql_query("INSERT INTO Songs (Artist, Song) VALUES ('$artist', '$song')"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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