-2

Hi I don't know what's the problem. The date field is not inserting to mysql.The format should be in YYYY-MM-DD like in mysql. Maybe that's the problem? The date in the input type is mm-dd-yyyy.

Query:

if(isset($_POST['subButton']))
  {
     mysql_query("INSERT INTO order_queue (Date, Tracking, Name, Address,
     ContactNo, dateneed, Payment, Claiming, qtyBlackWhite,
     totalBlackWhite, qtyChocnut, totalChocnut, qtyHotMama, totalHotMama,
     qtyMocha, totalMocha, qtyUbeKeso, totalUbeKeso, GrandTotal) 
     VALUES (NOW(), '".$_POST['Tracking']."', '".$_POST['Name']."',
     '".$_POST['Address']."', '".$_POST['ContactNo']."', 
     '".$_POST['dateneed']."', '".$_POST['Payment']."', 
     '".$_POST['Claiming']."', '".$_POST['qtyBlackWhite']."', 
     '".$_POST['totalBlackWhite']."', '".$_POST['qtyChocnut']."', 
     '".$_POST['totalChocnut']."', '".$_POST['qtyHotMama']."', 
     '".$_POST['totalHotMama']."', '".$_POST['qtyMocha']."', 
     '".$_POST['totalMocha']."', '".$_POST['qtyUbeKeso']."', 
     '".$_POST['totalUbeKeso']."', '".$_POST['GrandTotal']."')");   

  }

html

<input type="date" name="dateneed" id="dateneed" />

The date input type is mm/dd/yyyy.

In mysql the dateneed field is in DATE datatype and NN. What's wrong? In the query the Date is the auto inserting of date when the form is submitted. The problem is the dateneed is kinda preventing the form from insert everything. T__T

MarkTu
  • 39
  • 2
  • 8
  • 3
    You are wide open to SQL injections – John Conde Feb 04 '15 at 12:44
  • @JohnConde i told him to use musqli or PDO but he's not listening. – Junius L Feb 04 '15 at 12:48
  • Please provide more information. What is the date format, that you trying to insert? What is the exact query string? Try to put your full query string into a variable then print it and post it here. On the other hand, I'm with John Conde, NEVER use queries like this. Read about SQL injections and how to prevent them. – Fenistil Feb 04 '15 at 12:48
  • @Jay_P hi. Sorry but i'm not familiar with those yet.I still rely on what i research. – MarkTu Feb 04 '15 at 12:51
  • @MarkTu do you want to store the current date or just a date? – Junius L Feb 04 '15 at 12:51
  • @Jay_P I want to insert the date from the input in here it's format is mm/dd/yyyy. it's supposed to be yyyy-mm-dd like in mysql.Maybe that's why it's not letting me insert T.T – MarkTu Feb 04 '15 at 12:53
  • @Fenistil updated post with the format. – MarkTu Feb 04 '15 at 12:55
  • Then use Google or you can find here a lot of information about it: http://stackoverflow.com/questions/332365/how-does-the-sql-injection-from-the-bobby-tables-xkcd-comic-work http://stackoverflow.com/search?q=sql+injection – Fenistil Feb 04 '15 at 12:56
  • @MarkTu start learning PDO from http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers it will take you less than 20 minutes. – Junius L Feb 04 '15 at 12:59
  • @Jay_P ok. then how do i change the format?It's kinda like the default format for the input type="date"... – MarkTu Feb 04 '15 at 13:01

3 Answers3

1

There are more problems with it.

As other suggested, first of all, don't use PHP mysql extension, use mysqli or PDO.

Second, always check for EVERY user input data, and format them according to your query.

Use parameters in your SQL or escape the values you insert.

But to answer your question, use this:

$d = explode('/',$_POST['dateneed']);
$date = $d[2].'-'.$d[0].'-'.$d[1];

But you should check the date to be valid.

Fenistil
  • 3,734
  • 1
  • 27
  • 31
0

You Just have to pass fieldname is dateneed instead of Date

if(isset($_POST['subButton']))
{
    mysql_query("INSERT INTO order_queue (dateneed, Tracking, Name, Address,
 ContactNo, dateneed, Payment, Claiming, qtyBlackWhite,
 totalBlackWhite, qtyChocnut, totalChocnut, qtyHotMama, totalHotMama,
 qtyMocha, totalMocha, qtyUbeKeso, totalUbeKeso, GrandTotal) 
 VALUES (NOW(), '".$_POST['Tracking']."', '".$_POST['Name']."',
 '".$_POST['Address']."', '".$_POST['ContactNo']."', 
 '".$_POST['dateneed']."', '".$_POST['Payment']."', 
 '".$_POST['Claiming']."', '".$_POST['qtyBlackWhite']."', 
 '".$_POST['totalBlackWhite']."', '".$_POST['qtyChocnut']."', 
 '".$_POST['totalChocnut']."', '".$_POST['qtyHotMama']."', 
 '".$_POST['totalHotMama']."', '".$_POST['qtyMocha']."', 
 '".$_POST['totalMocha']."', '".$_POST['qtyUbeKeso']."', 
 '".$_POST['totalUbeKeso']."', '".$_POST['GrandTotal']."')");   

}

  • the first column Dateis to insert a date automatically when the form is submitted.the dateneed is a different field. – MarkTu Feb 04 '15 at 12:58
0

YOu can manipulate the dateneed value into require format then we can store it to database.

 if(isset($_POST['subButton']))
 {
    $dateneedExplode = explode('-',$_POST['dateneed']);
    $dateneedValue = $dateneedExplode[2].'-'.$dateneedExplode[0].'-  '.$dateneedExplode[1];

 mysql_query("INSERT INTO order_queue (Date, Tracking, Name, Address,
 ContactNo, dateneed, Payment, Claiming, qtyBlackWhite,
 totalBlackWhite, qtyChocnut, totalChocnut, qtyHotMama, totalHotMama,
 qtyMocha, totalMocha, qtyUbeKeso, totalUbeKeso, GrandTotal) 
 VALUES (NOW(), '".$_POST['Tracking']."', '".$_POST['Name']."',
 '".$_POST['Address']."', '".$_POST['ContactNo']."', 
 '".$dateneedValue."', '".$_POST['Payment']."', 
 '".$_POST['Claiming']."', '".$_POST['qtyBlackWhite']."', 
 '".$_POST['totalBlackWhite']."', '".$_POST['qtyChocnut']."', 
 '".$_POST['totalChocnut']."', '".$_POST['qtyHotMama']."', 
 '".$_POST['totalHotMama']."', '".$_POST['qtyMocha']."', 
 '".$_POST['totalMocha']."', '".$_POST['qtyUbeKeso']."', 
 '".$_POST['totalUbeKeso']."', '".$_POST['GrandTotal']."')");   

}

  • does that change the input type="date" format to yyyy-mm-dd? copied it and it's not inserting anything to the db T_T – MarkTu Feb 04 '15 at 13:18
  • what is your DB field and form field name ? also give me your code here so i can check. also date fromat for both. – Ghanshyam Dekavadiya Feb 04 '15 at 13:21
  • the dateneed input type should insert to dateneed field in DB.the mysql format is yyyy-mm-dd right? maybe it's not inserting anything because the input type date format in php is mm-dd-yyyy The codes are in the question. – MarkTu Feb 04 '15 at 13:25
  • Then My code is working. No need to change the format of your input. 1) Form date format is mm-dd-yyyy – Ghanshyam Dekavadiya Feb 04 '15 at 13:28
  • wait. it should be yyyy-mm-dd in the input type. because in mysql its yyyy-mm-dd – MarkTu Feb 04 '15 at 13:33
  • But i have manage the format into code if you can see $dateneedExplode = explode('/',$_POST['dateneed']); $dateneedValue = $dateneedExplode[2].'-'.$dateneedExplode[0].'- '.$dateneedExplode[1]; – Ghanshyam Dekavadiya Feb 04 '15 at 13:41
  • i'm hopeless. I don't know why it's not inserting anything. – MarkTu Feb 04 '15 at 13:46