Highlighted

Problem with a date format

New Here ,
Aug 06, 2017

Copy link to clipboard

Copied

once i submit this form, i got error on GetSQLValueString($_POST['tarikh'], "date")); the error shows

Warning: sprintf(): Too few arguments in  on line 53

Query was empty

How can i solve this problem?

so, this is my php file

<?php require_once('Connections/athira.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

   

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . date('Y-m-d',$theValue) . "'" : "NULL";

      break;

    

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {

  $insertSQL = sprintf("INSERT INTO tempahan (nama, matrik, ic, jabatan, pejabat, faks, telefon, emel, tempat, tujuan, tarikh) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW())",

                       GetSQLValueString($_POST['nama'], "text"),

                       GetSQLValueString($_POST['matrik'], "int"),

                       GetSQLValueString($_POST['ic'], "varchar"),

                       GetSQLValueString($_POST['jabatan'], "varchar"),

                       GetSQLValueString($_POST['pejabat'], "int"),

                       GetSQLValueString($_POST['faks'], "int"),

                       GetSQLValueString($_POST['telefon'], "int"),

                       GetSQLValueString($_POST['emel'], "varchar"),

                       GetSQLValueString($_POST['tempat'], "varchar"),

                       GetSQLValueString($_POST['tujuan'], "text"),

                       GetSQLValueString($_POST['tarikh'], "date"));

  mysql_select_db($database_athira, $athira);

  $Result1 = mysql_query($insertSQL, $athira) or die(mysql_error());

  $insertGoTo = "tempahan_list_user.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

    $insertGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $insertGoTo));

}

mysql_select_db($database_athira, $athira);

$query_register = "SELECT * FROM tempahan";

$register = mysql_query($query_register, $athira) or die(mysql_error());

$row_register = mysql_fetch_assoc($register);

$totalRows_register = mysql_num_rows($register);

    session_start();

    $role = $_SESSION['sess_userrole'];

    if(!isset($_SESSION['sess_username']) && $role!="tempahan"){

      header('Location: index.php?err=2');

    }

?>

and this is my insert form

<td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif ">Nama:</font></td>

            <td><input name="nama" type="text" id="nama" size="65" maxlength="80" pattern="[a-z A-Z /]*" required></td></tr>

                <tr>

               

                    <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">No.Staf/Matrik:</font></td>

                <td><input name="matrik" type="text" id="matrik" size="20" maxlength="12"  pattern="[0-9]*" required></td></tr>

                <tr>

              

                  <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">Kad Pengenalan:</font></td>

                <td><input name="ic" type="text" id="ic" size="40" maxlength="12" pattern="[0-9]*" required></td></tr>

               

               

               

                   

               

                <tr>

                  <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">Jabatan/Kolej/Inasis/Unit:</font></td>

                <td><TEXTAREA name="jabatan" rows=2 cols=60 required></TEXTAREA></td></tr>

                <tr>

               

                <tr>

                  <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">No.Tel(Pej):</font></td>

                <td><input name="pejabat" type="text" id="pejabat" size="20" maxlength="11" pattern="[0-9]*" ></td></tr>

                <tr>

                <tr>

                  <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">No.Faks:</font></td>

                <td><input name="faks" type="text" id="faks" size="20" maxlength="11" pattern="[0-9]*" ></td></tr>

                <tr>

                <tr>

                  <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">No.H/P:</font></td>

                <td><input name="telefon" type="text" id="telefon" size="20" maxlength="11" pattern="[0-9]*" required></td></tr>

                <tr>

               

                 <tr>

                   <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif ">Emel:</font></td>

                <td><input name="emel" type="text" id="emel" size="40" maxlength="60" pattern="[a-zA-Z,@,.,0-9,_]*" required></td></tr>

          

                <tr>

               

                <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">Butiran Tempahan:</font></td>

                <td><SELECT name="tempat" required="required"/>

                       <OPTION>-sila pilih-</OPTION>

                       <OPTION>Dewan Seminar</OPTION>

                       <OPTION>Bilik Kuliah</OPTION>

                       <OPTION>Bilik Komputer</OPTION>

                       <OPTION>Bilik Kuliah Masjid Sultan Badlishah</OPTION>

                      

                     

           </SELECT></td></tr>

               

                <tr>

               

                <tr>

                  <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">Tujuan/Program:</font></td>

                <td><TEXTAREA name="tujuan" rows=5 cols=60 required></TEXTAREA><br><font color="#FF0000">*100 patah perkataan sahaja</font></td></tr>

                <tr>

                <tr>

                  <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">Tarikh Program:</font></td>

                <td><input type = "date" name="tarikh" value=" <?php echo date('Y-m-d'); ?>

Views

185

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Problem with a date format

New Here ,
Aug 06, 2017

Copy link to clipboard

Copied

once i submit this form, i got error on GetSQLValueString($_POST['tarikh'], "date")); the error shows

Warning: sprintf(): Too few arguments in  on line 53

Query was empty

How can i solve this problem?

so, this is my php file

<?php require_once('Connections/athira.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

   

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . date('Y-m-d',$theValue) . "'" : "NULL";

      break;

    

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {

  $insertSQL = sprintf("INSERT INTO tempahan (nama, matrik, ic, jabatan, pejabat, faks, telefon, emel, tempat, tujuan, tarikh) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW())",

                       GetSQLValueString($_POST['nama'], "text"),

                       GetSQLValueString($_POST['matrik'], "int"),

                       GetSQLValueString($_POST['ic'], "varchar"),

                       GetSQLValueString($_POST['jabatan'], "varchar"),

                       GetSQLValueString($_POST['pejabat'], "int"),

                       GetSQLValueString($_POST['faks'], "int"),

                       GetSQLValueString($_POST['telefon'], "int"),

                       GetSQLValueString($_POST['emel'], "varchar"),

                       GetSQLValueString($_POST['tempat'], "varchar"),

                       GetSQLValueString($_POST['tujuan'], "text"),

                       GetSQLValueString($_POST['tarikh'], "date"));

  mysql_select_db($database_athira, $athira);

  $Result1 = mysql_query($insertSQL, $athira) or die(mysql_error());

  $insertGoTo = "tempahan_list_user.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

    $insertGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $insertGoTo));

}

mysql_select_db($database_athira, $athira);

$query_register = "SELECT * FROM tempahan";

$register = mysql_query($query_register, $athira) or die(mysql_error());

$row_register = mysql_fetch_assoc($register);

$totalRows_register = mysql_num_rows($register);

    session_start();

    $role = $_SESSION['sess_userrole'];

    if(!isset($_SESSION['sess_username']) && $role!="tempahan"){

      header('Location: index.php?err=2');

    }

?>

and this is my insert form

<td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif ">Nama:</font></td>

            <td><input name="nama" type="text" id="nama" size="65" maxlength="80" pattern="[a-z A-Z /]*" required></td></tr>

                <tr>

               

                    <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">No.Staf/Matrik:</font></td>

                <td><input name="matrik" type="text" id="matrik" size="20" maxlength="12"  pattern="[0-9]*" required></td></tr>

                <tr>

              

                  <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">Kad Pengenalan:</font></td>

                <td><input name="ic" type="text" id="ic" size="40" maxlength="12" pattern="[0-9]*" required></td></tr>

               

               

               

                   

               

                <tr>

                  <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">Jabatan/Kolej/Inasis/Unit:</font></td>

                <td><TEXTAREA name="jabatan" rows=2 cols=60 required></TEXTAREA></td></tr>

                <tr>

               

                <tr>

                  <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">No.Tel(Pej):</font></td>

                <td><input name="pejabat" type="text" id="pejabat" size="20" maxlength="11" pattern="[0-9]*" ></td></tr>

                <tr>

                <tr>

                  <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">No.Faks:</font></td>

                <td><input name="faks" type="text" id="faks" size="20" maxlength="11" pattern="[0-9]*" ></td></tr>

                <tr>

                <tr>

                  <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">No.H/P:</font></td>

                <td><input name="telefon" type="text" id="telefon" size="20" maxlength="11" pattern="[0-9]*" required></td></tr>

                <tr>

               

                 <tr>

                   <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif ">Emel:</font></td>

                <td><input name="emel" type="text" id="emel" size="40" maxlength="60" pattern="[a-zA-Z,@,.,0-9,_]*" required></td></tr>

          

                <tr>

               

                <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">Butiran Tempahan:</font></td>

                <td><SELECT name="tempat" required="required"/>

                       <OPTION>-sila pilih-</OPTION>

                       <OPTION>Dewan Seminar</OPTION>

                       <OPTION>Bilik Kuliah</OPTION>

                       <OPTION>Bilik Komputer</OPTION>

                       <OPTION>Bilik Kuliah Masjid Sultan Badlishah</OPTION>

                      

                     

           </SELECT></td></tr>

               

                <tr>

               

                <tr>

                  <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">Tujuan/Program:</font></td>

                <td><TEXTAREA name="tujuan" rows=5 cols=60 required></TEXTAREA><br><font color="#FF0000">*100 patah perkataan sahaja</font></td></tr>

                <tr>

                <tr>

                  <td><font size="2" color="#000000" face="Geneva, Arial, Helvetica, sans-serif">Tarikh Program:</font></td>

                <td><input type = "date" name="tarikh" value=" <?php echo date('Y-m-d'); ?>

Views

186

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 06, 2017 0
Engaged ,
Aug 07, 2017

Copy link to clipboard

Copied

Probably a ColdFusion forum is a poor place to ask a PHP question.  Might want to try over in a PHP forum.  If I had to guess though, you are replacing 12 %s parameters with only 11 values.  That being said, your input descriptor lists 11 columns, and your values descriptor tries to insert 13.

Nic

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 07, 2017 0