0

I'd like the user to book their appointment through the form. I used the datetimepicker jquery as follows:

<script src="jquery.js"></script>
<script src="jquery.datetimepicker.js"></script>
<script>
 $(function() {
     jQuery('#DateTime').datetimepicker({
        format:'D, d M Y H:i',

        });
    });
</script>

Previously i used the datepicker and i successfully inserted the data into the table. After changing to datetimepicker jquery and data type as datetime, i faced with a problem on inserting the data. I've tried the solutions but it still failed. My codes are as follows:

if (! $conn)

    die("Couldn't connect to MySQL");

$query = "SELECT from Client (Client_ID)";  

$sql = "INSERT INTO Appointment (Client_ID,Svc_ID,Appt_DateTime) 
VALUES ('$_POST[ClientID]','$_POST[ApptType]','$_POST[DateTime]')";


mysql_query($query,$sql,$conn);

dbDisconnect($conn);
Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
A.razali
  • 23
  • 6
  • Do you get any errors? Also, what's the value of `$_POST[DateTime]`? – ekad Nov 16 '14 at 15:07
  • 2
    `datetime` datatype need date format `YYYY-MM-DD H:i:s` – GBD Nov 16 '14 at 15:08
  • 3
    this code is suseptible to SQL Injection – Saic Siquot Nov 16 '14 at 15:09
  • 2
    What is `mysql_query($query,$sql,$conn);`? `mysql_query()` takes only 2 parameters - [`mysql_query ( string $query [, resource $link_identifier = NULL ] )`](http://php.net/manual/en/function.mysql-query.php) – Sean Nov 16 '14 at 15:15
  • **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Nov 16 '14 at 15:37
  • You aren't looking at the return value of `mysql_query`. You aren't calling `mysql_error`. You need to learn the basics of the APIs you use so you can find out what is going wrong when you use them. – Quentin Nov 16 '14 at 15:37
  • @ekad I did not get any errors just that data is could not be inserted in the database. The value of $_POST[DateTime] is the value client would see when they select a date to book appointment as follows (Mon, 20 Nov 2014 1500) – A.razali Nov 16 '14 at 17:31
  • @GBD the datetime appears as follows: jQuery('#DateTime').datetimepicker({ format:'D, d M Y H:i', is what the client will see on the site. so where could i add the codes to format it according to phpmyadmin – A.razali Nov 16 '14 at 17:34

1 Answers1

0

this works fine

 "INSERT INTO Appointment (Client_ID,Svc_ID,Appt_DateTime) 
VALUES ('$_POST[ClientID]','$_POST[ApptType]','".date('Y-m-d H:i:s', strtotime($_POST[DateTime]))."')");
A.razali
  • 23
  • 6