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