Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is a <em>lot</em> wrong with your code.</p> <ol> <li>There is no function <code>mysqle_select_db()</code>. There is one called <code>mysql_select_db()</code>, but since you're using PDO, you probably want to use <code>$conn-&gt;query('use group2')</code>, if at all.</li> <li>You are running a query with a variable that's not set yet. <code>$conn-&gt;query($sql);</code> just two lines further down won't work.</li> <li>Square brackets are not valid in table names, neither is <code>+</code> a valid query column. <code>SELECT + FROM counter[counter]</code> just won't work. You probably meant to do <code>SELECT * FROM counter</code>.</li> <li>Your query won't return <em>anything</em>, but I'm pretty sure it won't return a <code>counter[counter]</code> column. You probably meant to just do <code>$counter=$row['counter'];</code> (yes you can trick MySQL into using square brackets in column names, but that's most probably not whats intended here)</li> <li>Last but not least, your UPDATE query is not only issued twice (once using PDO, once though the mysql_* lib), but also wrong. It should most probably read <code>$insertNew = $conn-&gt;("UPDATE counter SET counter = '$add'");</code>, assuming that your <code>counter</code> table has a <code>counter</code> column.</li> </ol> <p>Edit:</p> <p>With a few minor details, your script looks okay.</p> <ol> <li>you probably shouldn't post your database password. </li> <li>One of your database queries is not doing much: <code>$conn-&gt;query($sql);</code> - you do that again on the next line.</li> <li>Your counter will start with 2 instead of 1, because you're updating after you inserted (the UPDATE is not in the <code>else</code> part of your <code>if</code> statement, so it will run in all cases)</li> </ol> <p>If it still doesn't work, you should try and put echo/print_r/var_dump statements into your code to see where it is breaking - e.g.:</p> <p><code>print_r($conn-&gt;errorInfo());</code> will give you information on errors inside PDO. <code>echo "$counter";</code> will give you the result of your select.</p> <p>print_r($conn->errorInfo());</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