Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

get time and update row

Posted on 2012-03-10
2
Medium Priority
?
269 Views
Last Modified: 2012-03-10
I'm trying to do 2 things... My code works but I need it to record the time the data is saved so I can see if the data is stale also is there such thing as a insert or replace function or Update because I don't want to generate a new row every time but simply check if a user and group existent and update that row or if it doesn't then create the row... I know I use insert or replace in sqlite how about php --> mysql ?


<?php
$dbhost =xxxx
$dbuser = xxxx
$dbpass = xxxxx;
$dbname=xxxxx;


$con = mysql_connect("$dbhost","$dbuser","$dbpass");
mysql_select_db($dbname);

if (!$con)

  {
  die('Could not connect: ' . mysql_error());
  }


$sql="INSERT INTO gpscoordinates (UserName, Password1, Group1,Latitude,Longitude)
VALUES
('$_POST[User]','$_POST[Password1]','$_POST[Group1]','$_POST[Latitude]','$_POST[Longitude]')";

//$sql="INSERT INTO gpscoordinates (UserName, Password1, Group1,Latitude,Longitude)
//VALUES ('1','2','3','4','5')";


if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)
?> 

Open in new window

0
Comment
Question by:dolamitejenkins
2 Comments
 
LVL 80

Accepted Solution

by:
arnold earned 1500 total points
ID: 37706125
If you have a datetime, or an int(11) for time keeping (actual date or unix timestamp)
you can use now() or unix_timestamp() for the columns when you do the insert, replace/update.
0
 

Author Closing Comment

by:dolamitejenkins
ID: 37706198
thanks
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question