|
-
Mar 19th, 2002, 06:20 PM
#1
Thread Starter
PowerPoster
How do you overwrite entry in MySQL?
Okay, I have this code so far:
PHP Code:
$ip = getenv("REMOTE_ADDR");
$view_date = date("F j, Y");
echo "<br>Your IP address is $ip<br>Today's date is $view_date.";
$sql = "SELECT * FROM page_view";
$connection = mysql_connect("localhost", "**********", "**********") or die("Could not connect.");
$db = mysql_select_db(**********, $connection) or die("Could not select database.");
$result = mysql_query($sql,$connection);
echo "<br>The following people have visited this website:<br>";
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$username = $row['username'];
$ip = $row['ip'];
$view_date = $row['view_date'];
echo "$username<br>";
}
$sql = "REPLACE INTO `page_view` (`id`, `username`, `ip`, `date`) VALUES ('', '$user', '$ip', '$view_date')";
$result = mysql_query($sql,$connection) or die("ERROR2!");
When I run that, it displays the viewer's name correctly, but if the user returns, his name is displayed again! How would I make it so that the name of the user is shown only once?
Last edited by eiSecure; Mar 19th, 2002 at 06:23 PM.
-
Mar 19th, 2002, 09:56 PM
#2
oh man I am very surprised it works at all.
as it sits now everytime a person comes to that page tehn it will record there ip, username, and date.
if you don't want that then you have to check for the username in the database and if it is there already then you just exit, if it is not in there you insert the info.
besides, never seen
REPLACE INTO
should use insert...
-
Mar 21st, 2002, 06:18 AM
#3
Fanatic Member
PHP Code:
// counter code
$link = mysql_connect("localhost", "root");
mysql_select_db("ubunreal");
IF ($page == "") {$temp_page_count = mysql_result(mysql_query("SELECT count FROM counter"),0,"count");
$temp_page_count++;
mysql_query("UPDATE counter SET count=$temp_page_count");}
ECHO mysql_result(mysql_query("SELECT count FROM counter"),0,"count");
the following code is for my counter, it checks if a value ($page) exists then if it doesnt it'll add 1 to the value in the database then run the query again to get it out.
i dont know if this will help you but i hope it does.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|