Hi. I am adding 8 fields into a table. I supply 5 of them and the other 3 are added on insertion. The function AddRecord is called using AddRecord($EntryDate,$input,$out,$Reason,$Comment);
My function file has the same number of parameters.

function AddRecord($EntryDate,$input,$out,$Reason,$Comment) // E2002
{
	$pdo = connectDB();
	$AddDateStamp = time();
	$AddDate = date("Y-m-d H:i", $AddDateStamp);
	$Transaction = dechex(strtotime($EntryDate));
	$Insertion = dechex(time());
	$package = md5($Transaction . $Insertion);
	$Hilight = 0;
	
$sqlGetCount = "Select * FROM Bank_Data as Value";	
//$QCount = $pdo->query($sqlGetCount);	
$stmt = $pdo->prepare($sqlGetCount);
$stmt->execute();
$Count = $stmt->rowCount();	
$Count = dechex($Count += 256);
$Tag =  substr(($Count . $Transaction . $Insertion . $package),0,32);

$sqlList = "
INSERT INTO Bank_Data SET 
EntryDate = :Entry, 
Input = :In, 
Output = :Out, 
Reason = :Reason, 
Comment = :Coment, 
AddDate = :AddDate,
Tag = :Tag,
B = :B
";		
$stmt = $pdo->prepare($sqlList);
$stmt->execute([
':EntryDate' => $EntryDate,
':input' => $input,
':out' => $out,
':Reason' => $Reason,
':Comment' => $Comment,
':AddDate' => $AddDate,
':Tag' => $Tag,
':B' => $Hilight
]);
return;
}
// Up to here
/*
function GetReason() // E2001
{
	$sqlList = "SELECT * FROM Bank_Reason Order by Reason ASC";
	$qList = mysql_query($sqlList) or die ("E2001-01A");
	return $qList;
}[code]
Table
[code]CREATE TABLE `Bank_Data` (
  `EntryDate` date DEFAULT NULL,
  `Input` decimal(6,2) NOT NULL DEFAULT '0.00',
  `Output` decimal(6,2) NOT NULL DEFAULT '0.00',
  `Reason` tinyint(1) NOT NULL DEFAULT '0',
  `Comment` varchar(32) NOT NULL DEFAULT '',
  `AddDate` datetime NOT NULL,
  `Tag` varchar(45) NOT NULL DEFAULT '',
  `B` tinyint(1) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

    This is the error

    Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in /vhost/vhost15/d/e/s/desmond-otoole.co.uk/www/bank2/secure/SecureFunctionsBank.php:201 Stack trace: #0 /vhost/vhost15/d/e/s/desmond-otoole.co.uk/www/bank2/secure/SecureFunctionsBank.php(201): PDOStatement->execute(Array) #1 /vhost/vhost15/d/e/s/desmond-otoole.co.uk/www/bank2/DataInputUpdate.php(64): AddRecord('2023/3/25', '0.00', '1.00', '4', 'Comment') #2 {main} thrown in /vhost/vhost15/d/e/s/desmond-otoole.co.uk/www/bank2/secure/SecureFunctionsBank.php on line 201
    

      Is the parameter supposed to be :Entry or :EntryDate?

      P.S. This bit is still wrong:

      $sqlGetCount = "Select * FROM Bank_Data as Value";
      $stmt = $pdo->prepare($sqlGetCount);
      $stmt->execute();
      $Count = $stmt->rowCount();	

      For the reasons already discussed.

        Okay it should be :Entry but as for
        $stmt->execute();
        $Count = $stmt->rowCount();
        execute does not have any parameter array to add to it.
        and if I coment out the rest of the code
        $count returns a value. 1d0

        	$sqlGetCount = "Select * FROM Bank_Data as Value";		
        	$stmt = $pdo->prepare($sqlGetCount);
        	$stmt->execute();
        	$Count = $stmt->rowCount();	
        	$Count = dechex($Count += 256);
        	echo $Count;
        	exit;

        Thanks for spotting the typo on the place holders. That bit is fixed and works fine. Still need to know why $stmt->execute(); no parameters given / needed.

        otuatail
        I'm not understanding what you're saying or doing, but here's an earlier post.
        https://board.phpbuilder.com/d/10403932-need-to-obtain-a-single-record-for-a-user-log-in/4
        If you want to get really clever, you'd get the database to count the number of rows in the table and return that, instead of asking the database to send you the entire table.

        otuatail Still need to know why $stmt->execute(); no parameters given / needed.

        I'm pretty sure this has also already been pointed out to you earlier, $pdo->query() would be a better choice of function to use there instead of prepare/execute, precisely because you have no parameters.

          $sqlGetCount = "Select * FROM Bank_Data as Value";
          should be $sqlGetCount = "Select * FROM Bank_Data";
          Incorrect SQL

            Write a Reply...