Bry Man
08-20-2005, 11:29 PM
Hey,
I figured id try and make a simple little counter for my site using php/sql, but i cant seem to get it to work, its buggin the crap out of me, im fairly new to Sql and am just trying things out here and there. This is what I have for script so far.
<?php
$username="root";
$password="";
$database="SiteDatabase";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM counter WHERE id=1";
$count=mysql_query($query);
print("$count");
$count++;
$query = "UPDATE counter SET count=$count WHERE id=1";
mysql_query($query);
mysql_close();
print("$count");
?>
And the database table for that
$query="CREATE TABLE counter (
id int(1) NOT NULL,
count int(10) NOT NULL,
PRIMARY KEY (id),
KEY count (count)
)";
and it will print 'Resource id #2' to the browser, but nothing else and the table remains unchanged which makes me think that im screwing up on the updating part =S, probably on the retriveing part as well...hell the whole thing may be wrong for all i know
And to clear something up, I changed the value of the 'id' to 1 inside phpmyadmin, Im not just assuming its 1 because of this "id int(1) NOT NULL,"....im not that new...but perhaps its something simple like that. Any help is appreciated
I figured id try and make a simple little counter for my site using php/sql, but i cant seem to get it to work, its buggin the crap out of me, im fairly new to Sql and am just trying things out here and there. This is what I have for script so far.
<?php
$username="root";
$password="";
$database="SiteDatabase";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM counter WHERE id=1";
$count=mysql_query($query);
print("$count");
$count++;
$query = "UPDATE counter SET count=$count WHERE id=1";
mysql_query($query);
mysql_close();
print("$count");
?>
And the database table for that
$query="CREATE TABLE counter (
id int(1) NOT NULL,
count int(10) NOT NULL,
PRIMARY KEY (id),
KEY count (count)
)";
and it will print 'Resource id #2' to the browser, but nothing else and the table remains unchanged which makes me think that im screwing up on the updating part =S, probably on the retriveing part as well...hell the whole thing may be wrong for all i know
And to clear something up, I changed the value of the 'id' to 1 inside phpmyadmin, Im not just assuming its 1 because of this "id int(1) NOT NULL,"....im not that new...but perhaps its something simple like that. Any help is appreciated