Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is not enough. 1. You're missing cookies, $_COOKIE variable. 2. If you use $_REQUEST you're in trouble. 3. You didn't show your queries, you must enquote each variable with single quotes '' when you put it into query (especiall when the data is supposted to be an integer and you might think that quote is not necessary in that case, but that would be a big mistake). 4. Data used in your query could come from other source.</p> <p>The best way is to use data binding and have the data escaped automatically by the driver, this is available in PDO extension.</p> <p>Example code:</p> <pre><code>$PDO = new PDO('mysql:dbname=testdb;host=127.0.0.1' $user, $password); $stmt = $PDO-&gt;prepare("SELECT * FROM test WHERE id=? AND cat=?"); $stmt-&gt;execute(array($_GET["id"], $_GET["cat"])); $rows = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC); </code></pre> <p>You can also bind data using string keys:</p> <pre><code>$stmt = $PDO-&gt;prepare("SELECT * FROM test WHERE id = :id AND cat = :cat"); $stmt-&gt;execute(array(":id" =&gt; $_GET["id"], ":cat" =&gt; $_GET["cat"])); </code></pre> <p>If you want to learn PDO, you might find useful these helper functions I use:</p> <p><a href="http://www.gosu.pl/var/PDO.txt" rel="nofollow">http://www.gosu.pl/var/PDO.txt</a></p> <pre><code>PDO_Connect(dsn, user, passwd) - connects and sets error handling. PDO_Execute(query [, params]) - only execute query, do not fetch any data. PDO_InsertId() - last insert id. PDO_FetchOne(query [, params]) - fetch 1 value, $count = PDO_FetchOne("SELECT COUNT(*) .."); PDO_FetchRow(query [, params]) - fetch 1 row. PDO_FetchAll(query [, params]) - fetch all rows. PDO_FetchAssoc(query [, params]) - returns an associative array, when you need 1 or 2 cols 1) $names = PDO_FetchAssoc("SELECT name FROM table"); the returned array is: array(name, name, ...) 2) $assoc = PDO_FetchAssoc("SELECT id, name FROM table") the returned array is: array(id=&gt; name, id=&gt;name, ...) 3) $assoc = PDO_FetchAssoc("SELECT id, name, other FROM table"); the returned array is: array(id=&gt; array(id=&gt;'',name=&gt;'',other=&gt;''), id=&gt;array(..), ..) </code></pre> <p>Each of functions that fetch data accept as 2nd argument parameters array (which is optional), used for automatic data binding against sql injections. Use of it has been presented earlier in this post.</p>
    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. 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