Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are some problems in your code. Firstly you do query twice. Secondly are you sure your db name is $db = '#######'; change it to proper name. </p> <p>To check if query was ok and if rows were added use <strong>mysql_affected_rows()</strong> to check errors use <strong>mysql_error()</strong></p> <p>Also change your sql engine to <strong>PDO</strong> or <strong>mysqli</strong> which are better. </p> <p><strong>Please mind that Mysql_* functions are depracated.</strong> That is why I've given you example how to use db connection in PDO.</p> <pre><code>&lt;?php $host = 'localhost'; $user = 'users'; $pw = ''; $db = '#######'; //CHANGE IT TO PROPER NAME WHERE TABLE users IS! $connect = mysql_connect($host,$user,$pw) or die ("Could not connect."); mysql_select_db($db); $sql = mysql_query( "INSERT INTO users VALUES('' ,'l','l','l','l', 'l','l')") or die(mysql_error()); if(mysql_affected_rows()&gt;0) echo "Item added successfully.&lt;br/&gt;"; else echo "Item addition failed.&lt;br/&gt;"; ?&gt; </code></pre> <p>I'll give you proper example how to do it with PDO cause if you still learn it'll help you :)</p> <p><strong>PDO example</strong></p> <pre><code>&lt;?php $dsn = 'mysql:dbname=YOUR_DB_NAME;host=localhost'; $user = 'users'; $password = ''; try { $dbh = new PDO($dsn, $user, $password); $count = $dbh-&gt;exec("INSERT INTO users VALUES('' ,'l','l','l','l', 'l','l');"); echo $cout ? "Item added successfully" : "Item addition failed"; } catch (PDOException $e) { echo 'Failed: ' . $e-&gt;getMessage(); } ?&gt; </code></pre> <p>The secure and good way to insert values is using prepared statements. To create prepared statement you use</p> <pre><code>$stmt = $dbh-&gt;prepare("INSERT INTO users (name, email) VALUES(?,?)"); $stmt-&gt;execute( array('user', 'user@example.com')); </code></pre> <p><a href="http://pl1.php.net/manual/en/class.pdo.php" rel="nofollow">You can learn more here</a> </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