Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I need your help with this code please. I have tried a couple of things but none seem to work. I need to check that the client name from amcname input does not exist in the db. Please assist.
________________________________________________________________________________________
//My function code
public function insert($cname, $ccode, $cregno, $cvatno)
{
$sql = "INSERT INTO tbl_client (ccode, cname, cregno, cvatno) VALUES (:amcname,:amccode,:amcregno,:amcvatno)";
$stmt = $this->conn->prepare($sql);
$stmt->execute(['amcname' => $cname, 'amccode' => $ccode, 'amcregno' => $cregno, 'amcvatno' => $cvatno]);
return true;
}
________________________________________________________________________________________
//My Action Code
if (isset($_POST['action']) && $_POST['action'] == "insert") {
$cname = $_POST['amcname'];
$ccode = $_POST['amccode'];
$cregno = $_POST['amcregno'];
$cvatno = $_POST['amcvatno'];

$db->insert($cname, $ccode, $cregno, $cvatno);
}
________________________________________________________________________________________

What I have tried:

I have tried using JS and mysqli with no success.
Posted
Updated 28-Dec-21 10:53am
Comments
Richard MacCutchan 28-Dec-21 3:57am    
Use a SELECT statement to check if the name exists.

1 solution

Hmm.
You switched :amcname and :amccode

:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900