Mysql


#1

why cant i update mysql database from my web page

i have a database called cbjdfamily and a table called cpunt with a field labeld hit

what is wrong with this code, note i am not showing the password.

is there more set up i need to do.

<?php $connection = mysql_connect('mysql.cbjdfamily.com', 'cbjdfamily', '*****') or die ("No connection!"); mysql_select_db('cbjdfamily', $connection) or die ("No database!"); $query=("UPDATE count SET hit = 12 "); $result=mysql_query=($query); ?>


#2

Use the mysql format like

UPDATE table_name SET column_name = value (WHERE column_name = ).

Change table_name to cpunt (in this instance). And column_name = 12. So use

UPDATE cpunt SET hit = 12

You might want to add a where clause to the update statement, otherwise it will update every column in that table.


#3

that is what i am doing

I must be missing something

does it matter where in your html page this code resides.

i can update the table find in mysql phpadmin

The code you gace me i have tried and does not work.

what am i missing???


#4

Sorry. Was just looking at the query string. Didn’t notice the other errors. You should post what sort of errors you are getting when you ask for help. There are many things that can go wrong with php/mysql. Try these lines

$query=("UPDATE cpunt SET hit = 12 ");
$result=mysql_query($query);

EDIT Just thought. Is there a row in your cpunt table called hit or is the column called hit? You need to make sure that you use column names in the sql. You should really have a table set up with at least two columns. One as a unique id, and one as a value. I guess you are trying to do a hit counter or something? I have something similar, I use a config table. With 2 columns, a config_name and config_value.
Insert a row called hits and a value of 0. You then update it by doing
UPDATE config SET config_value = config_value 1 WHERE config_name = ‘hit’