Solved

get time and update row

Posted on 2012-03-10
2
254 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 76

Accepted Solution

by:
arnold earned 500 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
The viewer will learn how to dynamically set the form action using jQuery.

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now