Jump to content

[SOLVED] query not inserting to db


rondog

Recommended Posts

does anyone know why this insert statement isnt inserting anything into the data base?

$date = date("m-d-y");
$datequery = "INSERT INTO users timelogged VALUES $date WHERE username = '$uname'";
$rundate = mysql_query($datequery);

 

echo $datequery; returns

INSERT INTO users timelogged VALUES 08-30-07 WHERE username = 'abarter'

 

so that sounds right to me..i dunno i might be crazy

 

does the timelogged field in the DB have to be something specific? I have it set as VARCHAR right now

Link to comment
https://forums.phpfreaks.com/topic/67333-solved-query-not-inserting-to-db/
Share on other sites

Don't think it's the varchar problem unless it's not long enough to hold the value submitted.

 

But what's wrong is the VALUES $date part. You have to tell the database to input date into what table field.

 

Something like this:

<?php

$date = date("m-d-y");
$datequery = "INSERT INTO users timelogged VALUES date='$date' WHERE username = '$uname'";
$rundate = mysql_query($datequery) or die(mysql_error());

?>

Also try to put in die methods

the insert statment goes like this though...

 

INSERT INTO table_name (column1, column2) VALUES ('value1','value2') so the date= part on your statement would be wrong.

 

I did add the or die part and got this error:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'timelogged VALUES 08-30-07 WHERE username = 'abarter'' at line 1

 

timelogged is my column name and then im just saying put it in the row where username = the person that is logged in

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.