Having trouble adding to a table's value via query [SOLVED]
Posted: Fri Jul 04, 2008 2:03 pm
EDIT: PROBLEM SOLVED SEE BOTTOM FOR SOLUTION
I finally got the database to work. I went and asked on the hosting site's forum and someone was able to help me. Now I'm having trouble getting this query to add to the value by 1 each time I visit. I'm really unfamiliar with MySQL so please be patient for these are probably simple problems and I may have several more ^-^
Ok, so here is my script.
*Note that in the script there are backslashes used but for some reason when they are in the
I finally got the database to work. I went and asked on the hosting site's forum and someone was able to help me. Now I'm having trouble getting this query to add to the value by 1 each time I visit. I'm really unfamiliar with MySQL so please be patient for these are probably simple problems and I may have several more ^-^
Ok, so here is my script.
*Note that in the script there are backslashes used but for some reason when they are in the
Code: Select all
tags they dissapear... but their still there!*[/b]
[syntax=php]
<?php
$host = 'localhost';
$user = 'groog_admin';
$pass = '********'; //It's a secret ;)
$query = 'UPDATE guides_table SET guide_views=++1 WHERE guide_name=\'Test\'';
$connect = @mysql_connect($host, $user, $pass) or die('Error connecting to MySQL!');
mysql_select_db(groog_guides) or die('Error connecting to database!');
$result = mysql_query($query);
?>
[/syntax]
Ok, so I'm trying to get guide_views to add 1 every time I visit the page. I've tried just making the value equal a number to test it. ex-
[syntax=php]$query = 'UPDATE guides_table SET guide_views=5 WHERE guide_name=\'Test\'';[/syntax]
And this worked so now I just need to find out how to make it add 1 each time. I've tried not only =++ but
[syntax=php]$query = 'UPDATE guides_table SET guide_views=+1 WHERE guide_name=\'Test\'';[/syntax]
And if you're familiar with Adobe Flash I tried going that route-
[syntax=php]$query = 'UPDATE guides_table SET guide_views+=1 WHERE guide_name=\'Test\'';[/syntax]
Just in case :roll:
Anyway, am I doing this wrong? Please help, even though I have a feeling this should be easy as pie 8O
[color=#FF0000][b]EDIT: PROBLEM SOLVED[/b][/color]
I fixed it. Just in case anyone has the same problem you need to do this-
[syntax=php]$query = 'UPDATE guides_table SET guide_views=guide_views ++ 1 WHERE guide_name=\'Test\'';[/syntax]