Jump to content


MySQL Update Problem

  • Please log in to reply
2 replies to this topic

#1 lpxxfaintxx

  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 07 April 2006 - 10:02 PM

I wanted to use $_GET['sn'] and add it every time a user enters the page, but it won't work properly.

For example, I go to [a href=\"http://aimmultimedia.com/viewprofile.php?id=username&\" target=\"_blank\"]http://aimmultimedia.com/viewprofile.php?id=username&[/a]sn=lpxxfaintxx

require_once "db.php";
require_once "profileheader.php";
$owner = $_GET['id'];
$visitor = $_GET['sn'];

    $idq = mysql_query("SELECT `profilehits` FROM `fusion_users` WHERE `user_name` = '$owner'");
    $ida = mysql_fetch_assoc($idq);
    $newid = $ida['profilehits'] + ', '.$visitor; 

$sql = "UPDATE fusion_users SET profilehits='$newid' WHERE user_name = '$owner'";
      $result = mysql_query($sql);

$sql = "SELECT * FROM `registered_cat` WHERE `owner` = '$owner'";
$num_rows = mysql_num_rows($result);
echo 'There are '.$num_rows. ' categories. Please choose one.<br><br>';
$id = $row['id'];
    echo ' <a href="/viewprofilecat.php?id='.$id.'&sn=%n">'.$row['cat_name'].'</a> <br>' .
         "Description : {$row['cat_description']} <br>" .
         "Total Images : {$row['id']} <br> <hr>";


In MySQL, the row 'profilehits' is set to varchar, and default is 'anounymous'. So I was hoping it would store: Anounymous, lpxxfaintxx. But instead, it changes it to '0lpxxfaintxx'. Does anyone know how to fix this, or is there an easier way?

AIMMultimedia.com - God Bless You

#2 akitchin

  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 07 April 2006 - 10:25 PM

you are trying to mathematically add the two together when you use a + sign. this isn't javascript. try replacing the plus sign with a period; this is called the concatenation operator, which essentially glues two strings into one.

#3 lpxxfaintxx

  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 08 April 2006 - 11:21 AM

Thanks, it works, but is there any way so that php can count how many commas there are? For example. anounymous, blahblah, lpxxfaintxx, php, yahoo would shout up as "4"

Ive also tried

$sql2="SELECT profilehits FROM fusion_users WHERE user_name = '$owner'";
$views = $rows2['profileviews'];
$arr = explode(",", $views);

But it just shows up as 1.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users