Current location: Hot Scripts Forums » Programming Languages » PHP » find row input data


find row input data

Reply
  #1 (permalink)  
Old 03-21-09, 07:49 PM
Textahead Textahead is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
find row input data

I need to search "visitornumber column" to find row thatr matches varible '$hits". when found input data from varible "$state" into "state column"

this is what I have sofar

$connect=mysql_connect("localhost", "*******","*******");
mysql_select_db("peoplecounter",$connect);

$sql = mysql_query("SELECT * FROM userslocation WHERE visitornumber='$hits'")or die(mysql_erorr());

$sql =mysql_query("INSERT INTO userslocation SET('$state', '', '', '')") ;




any help much appreciated
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-21-09, 07:55 PM
de.monkeyz's Avatar
de.monkeyz de.monkeyz is offline
Wannabe Coder
 
Join Date: Apr 2008
Location: Leeds, UK
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
So what doesn't work so far? All I can see is that you've overwritten $sql with the insert statement.
__________________
Wanna learn AJAX? Goto http://www.deathmonkeyz.com/tutorials for free video tutorials.

AJAX - Lesson 11 - AJAX Guestbook (23/8/08)
C++ - Lesson 10 - Classes (24/8/08)
JavaScript - Lesson 03 - The DOM (24/8/08)
Need an AJAX app? Look no further, I'm available for work
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-21-09, 08:02 PM
Textahead Textahead is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
totally

I dont understand what You mean by "overwritten sql" should I be doing this in an IF ELSE statement or something? when i look in my SQL_ADMIN the data Im trying to input is not there
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 03-21-09, 08:07 PM
de.monkeyz's Avatar
de.monkeyz de.monkeyz is offline
Wannabe Coder
 
Join Date: Apr 2008
Location: Leeds, UK
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
You've made a variable called $sql in your code, and saving the result of the select statement (will be a mysql_resource). But right afterwards, you are saving the result of the update into it as well which will delete the select data result. As well as using a variable called state which does not exist.

If you wish to grab the state from the select statement you do:
PHP Code:

$connect=mysql_connect("localhost""*******","*******"); 
mysql_select_db("peoplecounter",$connect);

$sql mysql_query("SELECT * FROM userslocation WHERE visitornumber='$hits'")or die(mysql_erorr());

$res mysql_fetch_assoc($sql);
$state $res['state']; //state is the column name

$update =mysql_query("INSERT INTO userslocation SET('."mysql_real_escape_string($state)."', '', '', '')") ; 
__________________
Wanna learn AJAX? Goto http://www.deathmonkeyz.com/tutorials for free video tutorials.

AJAX - Lesson 11 - AJAX Guestbook (23/8/08)
C++ - Lesson 10 - Classes (24/8/08)
JavaScript - Lesson 03 - The DOM (24/8/08)
Need an AJAX app? Look no further, I'm available for work
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 03-21-09, 08:21 PM
Textahead Textahead is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Spin more lost

I understand now what you mean about redoing the $sql variable

ok ill explain it a different way.
i have table with 4 columns
STATE CATAGORY VISITORNUMBER PAGECOUNT

VISITORNUMBER is already set as=$hits
now i need to search VISITORNUMBER row until it finds $hits then ineed to put into STATE column results of varible $state

Last edited by Textahead; 03-21-09 at 08:24 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 03-21-09, 08:22 PM
de.monkeyz's Avatar
de.monkeyz de.monkeyz is offline
Wannabe Coder
 
Join Date: Apr 2008
Location: Leeds, UK
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
So you want to edit the row which has that hitcount?
__________________
Wanna learn AJAX? Goto http://www.deathmonkeyz.com/tutorials for free video tutorials.

AJAX - Lesson 11 - AJAX Guestbook (23/8/08)
C++ - Lesson 10 - Classes (24/8/08)
JavaScript - Lesson 03 - The DOM (24/8/08)
Need an AJAX app? Look no further, I'm available for work
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 03-21-09, 08:30 PM
Textahead Textahead is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
??

No I want to put new info into the state column
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 03-21-09, 08:32 PM
de.monkeyz's Avatar
de.monkeyz de.monkeyz is offline
Wannabe Coder
 
Join Date: Apr 2008
Location: Leeds, UK
Posts: 116
Thanks: 0
Thanked 0 Times in 0 Posts
So what's the point of the select statement? As it seems to do nothing whatsoever. And inserting a row just to store data in one column is pretty pointless as well. You're gonna have to clarify what you want it to do exactly
__________________
Wanna learn AJAX? Goto http://www.deathmonkeyz.com/tutorials for free video tutorials.

AJAX - Lesson 11 - AJAX Guestbook (23/8/08)
C++ - Lesson 10 - Classes (24/8/08)
JavaScript - Lesson 03 - The DOM (24/8/08)
Need an AJAX app? Look no further, I'm available for work
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 03-21-09, 08:54 PM
Textahead Textahead is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
table with 4 columns
STATE CATAGORY VISITORNUMBER PAGECOUNT

Each new visitor is asigned a number IE: $hits
the visitor then clicks on a link with the $state varible embedded in it. I then need search VISITORNUMBER to find one that matches $hits and inputs the varible $state into the STATE column so I have a database record of Visitor number ($hits) and what link they clicked on ($state)

They will later click on a catagory link which will put into CATAGORY acording to thier $hits number ect ect so I can build up a profile of where they are and where they have been

they may also later click on link changing $state again so it will have to find thier $hits number again and change the STATE catagory to a new $state again.



i hope this explains it well enough

Last edited by Textahead; 03-21-09 at 09:04 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 03-21-09, 10:02 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
PHP Code:



<?php

//assign visitor number by his IP address
$visitor $_SERVER['REMOTE_ADDR'];

$state 'string';  //populate by a $_GET or $_POST

//build an UPDATE query
$query "UPDATE `userslocation` SET `state`='$state' WHERE `visitornumber`='$visitor' ";

//execute query
mysql_query($query);


?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 12:10 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.