Jump to content

Archived

This topic is now archived and is closed to further replies.

nikkicade

Calling mysql store procedure to enter information from a form using PHP.

Recommended Posts

Hi

I am new to this but have a database with a stored procedure to add a new product to the database. I have a form in which the user enters the new product information and click a submit button. The submit button then opens a new php page which calls the store procedure. I know everything is working as it should because the users have to login in order to get to the page with the form to add the new product. The form works fine and I can define the variables from the form and echo them out to the page called from the submit button using $ProductName = $_POST['ProductCode']; and echo $ProductName;. The problem I have is binding the parameters for the stored procedure. Does anyone know the correct method of binding the parameters to use with $query? Is it that I have to prepare, bind_param and execute? I have found the syntax for mysqli and have tried this


$stmt = $mysqli->prepare("call usp_NewProduct(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");

$stmt->bind_param('ssssssssissdi', $ProductName, $ProductSubCategory, $ProductSubCategory2, $ProductSubCategory3, $ProductDesign, $ProductColour, $ProductSize, $ProductFragrance, $DeliveryBand, $ProductCode, $ProductDescription, $ProductPrice, $StockLevel);

$ProductName = $_POST['ProductName'];
$ProductSubCategory = $_POST['ProductSubCategory'];
$ProductSubCategory2 = $_POST['ProductSubCategory2'];
$ProductSubCategory3 = $_POST['ProductSubCategory3'];
$ProductDesign = $_POST['ProductDesign'];
$ProductColour = $_POST['ProductColour'];
$ProductSize = $_POST['ProductSize'];
$ProductFragrance = $_POST['ProductFragrance'];
$DeliveryBand = $_POST['DeliveryBand'];
$ProductCode = $_POST['ProductCode'];
$ProductDescription = $_POST['ProductDescription'];
$ProductPrice = $_POST['ProductPrice'];
$StockLevel = $_POST['StockLevel'];

/* execute prepared statement */
$stmt->execute();

/* close statement and connection */
$stmt->close();


but cannot get it to work.

Any help would be gratefully received.

Thanks

Nikki

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.