php - Prepared SQL statement not 'preparing' -
I am trying to create a basic hit counter which I can use on all my websites.
I have a prepared statement to interrogate both my Daddy MySQL server and my MMP MySQL server, and the statement will not be 'ready' here:
function hit_counter ($ url) {if ($ mysqli = new mysqli ('localhost', 'root', '', 'db')) {$ crack = "select hc-id, hc-url, hc- Unique_hits, hc-total_hits, hc-last_view hit_counter where hc-url =? "; If ($ stmt = $ mysqli- & gt; ready (crack)) {$ stmt-> Bind_param ('s', $ url); $ Stmt- & gt; Executed (); $ Stmt- & gt; Store_result (); $ Stmt- & gt; Bind_salt ($ id, $ url, $ unique_hits, $ total_hits, $ last_vited); $ Stmt- & gt; Bring (); The echo "The statement was successfully prepared"; $ Total_hits = $ total_hits + 1; $ Last_ viewed = date ('LJSFFHH: ISAA'); Copy $ unique_hits; If ($ unique === true) {$ unique_hits = $ unique_hits + 1; } $ Update = 'update hit_counter set hc-unique_hits =? Hc-total_hits =? Hc-last_viewed =? WHERE hc-url =? '; If ($ stmt = $ mysqli- & gt; Ready ($ updates)) {$ stmt-> gt; Bind_param ('iiss', $ unique_hits, $ total_hits, $ last_viewed, $ url); $ Stmt- & gt; Executed (); } And {echo "update statement was not ready".}}} And "echo" statement was not prepared. "}} And {resonant" no connection to SQL ";}} I know that it is connecting to the database, but whenever I run a script, it accepts the statement for and ($ stmt = $ mysqli- & gt; ready )) {"Column was not ready" .
Your column contains hyphens that are interpreting MySQL hc < Strong> MINUS unique_hits etc. think that you want to do a mathematical problem.
You also have commas set your SETs
hit_counter set `hc-unique_hits` =?,` Hc-total_hits` =?, `Hc-end_view '=? WHERE 'HC-URL'? It is best to stay away from using hyphen for column names. Use underscores instead.
Using
if (! $ Stmt-> execute!) {Trigger_error ("There was an error ...". $ Mysqli - & Gt; error, E_USER_WARNING);} that error has to be seen. Hit_counter where hc-url =?
$ crack = "select hc-id, hc-url, hc-unique_hits, hc-total_hits, hc-last_view by hit_counter where hc-url =?" ; Use backtaking around those hyphens.
Comments
Post a Comment