Jump to content

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


nikkicade

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.