antatiana
asked on
PHP script
What's the problem with PHP script, it doesn't work.
<?php
include "db.inc";
include "prodlist.class";
?>
<html>
<head>
<title>
Add a Simgle Product
</title>
</head>
<body>
<b><font color="#000099"><font size=+2>Flamingo Add Product Form</font></font></b> <img SRC="pinkflamingo.gif" NOSAVE height=85 width=61>
<br>
<br>
<?php
$product = new ProdList;
$product ->addProdCode($_POST["prodCode"]); //get product code from posted form
$product ->addProdName($_POST["prodName"]; //get product Name code from posted form
$product ->addProdDesc($_POST["proddesc"]; //get product Description code from posted form
$product ->addProdPrice($_POST["prodprice"]; //get product price from posted form
if (!$product->getResult())
{
echo("<p> The product with code " . $code . " does not exist in the products table or could not be updated");
echo("<p><a href='main.html'>Continue</a>");
die("<br><br>");
}
else{
echo("<p> The product with code " . $code . " exists in the products table !!");
echo("<p><a href='addProduct.html'>Please Try Again</a>");
die("<br><br>");
}
?>
<p> The Product details were successfully added, <a href="main.html">Continue</a>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your first page above is the target of a form page that is supposed to send the $_POST data to it. What is the error message you are getting?
ASKER
This is my error massage:
PHP Fatal error: Call to undefined method ProdList::addProdCode()
PHP Fatal error: Call to undefined method ProdList::addProdCode()
There is a method/function called setProdCode() but not addProdCode() . Try changing your 'add' calls starting at line 30 to 'set' calls. After that, you will probably have to change $product->getResult() to $product->getRecord($code) . Note the $code variable. That is needed to access the database.
ASKER
Thanks, but I still have another error. PHP Parse error: syntax error, unexpected T_ELSE
I got attached code
I got attached code
<?php
include "db.inc";
include "prodlist.class";
?>
<html>
<head>
<title>
Add a Simgle Product
</title>
</head>
<body>
<b><font color="#000099"><font size=+2>Flamingo Add Product Form</font></font></b> <img SRC="pinkflamingo.gif" NOSAVE height=85 width=61>
<br>
<br>
<?php
$product = new ProdList;
$code = $_POST["prodcode"];
$name = $_POST["prodname"];
$desc = $_POST["proddesc"];
$price = $_POST["prodprice"];
$product ->setProdCode($_POST["prodcode"]); //get product code from posted form
$product ->setProdName($_POST["prodname"]); //get product Name code from posted form
$product ->setProdDesc($_POST["proddesc"]); //get product Description code from posted form
$product ->setProdPrice($_POST["prodprice"]); //get product price from posted form
if (!$product->getRecord($code, $name, $desc, $price))
else{
echo("<p> The product with code " . $code . " exists in the products table !!");
echo("<p><a href='addProduct.html'>Please Try Again</a>");
die("<br><br>");
}
?>
<p> The Product details were successfully added, <a href="main.html">Continue</a>
</body>
</html>
You left out this part of the code...
{
echo("<p> The product with code " . $code . " does not exist in the products table or could not be updated");
echo("<p><a href='main.html'>Continue</a>");
die("<br><br>");
}
line 37... what does if contains ..."else" ... fix that...
if (!$product->getRecord($code, $name, $desc, $price))
else{
ASKER
anyway I have some error. I need to finish here code in right way to get data to database. What's function after if I should put?
Line 37
Should read
if (!$product->getRecord($code, $name, $desc, $price))
else{
Should read
if (!$product->getRecord($code, $name, $desc, $price))
{
// code in here if statement is NOT true
}else{
ASKER
Open in new window