php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29381 Data not inserting into MySQL Database
Submitted: 2004-07-26 01:03 UTC Modified: 2004-07-26 06:52 UTC
From: dj at cleancode dot org Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.3.8 OS: Red hat 9
Private report: No CVE-ID: None
 [2004-07-26 01:03 UTC] dj at cleancode dot org
Description:
------------
When using mysql_query(), I can not insert a specific line into MySQL.  However, if I have PHP echo the string I'm trying to insert into the database, and then copy and paste it into the mysql command line tool, it inserts fine.



Reproduce code:
---------------
    $conn = mysql_connect("localhost", "organizer", "organizer") or die("Can't connecto to DB" . mysql_error());
    mysql_select_db("Organizer") or die("Can't change DB: " . mysql_error());
    $currdate = time();

    if ($taskarr['closed'] != "")
        $closed_date = $currdate;
    else
        $closed_date = 0;

    /* insert into database. */
    $q = "INSERT INTO Tasks SET post_date = $currdate, closed_date = $closed_date, last_edit = $currdate, subject = '" . $taskarr['subject'] . "', body = '" . $taskarr['body'] . "';";

    echo "$q<BR><BR>";
    mysql_query($q) or die("Couldn't insert data: " . mysql_error());
    mysql_close();


Expected result:
----------------
The data should get inserted in the table 

Actual result:
--------------
Doing a SELECT * FROM Tasks; shows nothing in the DB.
After performing this, mysql_query() returns fine... No error from mysql_error() since mysql_query() does not return false.

To make matters more interesting, if I statically set $currdate, it works.  For instance:

$currdate = 1090793160;

The data gets inserted into the database properly.  It seems if I use time() or mktime() cause the issue...

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-26 06:52 UTC] georg@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Please read 
http://dev.mysql.com/doc/mysql/en/Date_and_time_type_overview.html 
and http://www.php.net/time 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Aug 15 20:01:27 2024 UTC