Link to home
Start Free TrialLog in
Avatar of antatiana
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>&nbsp;&nbsp;&nbsp;&nbsp;<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>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of antatiana
antatiana

ASKER

I have attached prodlist.class
<?php

class ProdList
{
    var $dbname = "flamingo";
    var $tablename = "prodList";

    var $prodCode      = "";
    var $prodName     = "";
    var $prodDesc      = "";
    var $prodPrice      = 0;

    function ProdList() {   
   }

    function getRecord($code)  {
        $sqlQuery = "select * from " . $this->tablename . " WHERE prodCode='" . $code . "'";

        global $dbConn;
        if (!dbConnect($this->dbname)) return FALSE;
       $dbResult = odbc_exec($dbConn,$sqlQuery);

        if (odbc_fetch_row($dbResult)) {
            $this->prodCode     = odbc_result ($dbResult, "prodCode");
            $this->prodName    = odbc_result ($dbResult, "prodName");
            $this->prodDesc     = odbc_result ($dbResult, "prodDesc");
            $this->prodPrice     = odbc_result ($dbResult, "prodPrice");
            return true;
        } 
        else {
            return false;
        }
    }

   function updateRecord() {

        $sqlQuery = "update " . $this->tablename . " set ";
        $sqlQuery .= "prodName='" . $this->prodName . "', ";
        $sqlQuery .= "prodDesc='" . $this->prodDesc . "', ";
        $sqlQuery .= "prodPrice=" . $this->prodPrice . " ";
        $sqlQuery .= "where prodCode='" . $this->prodCode . "'";

        global $dbConn;
        if (!dbConnect($this->dbname)) return false;
       $dbResult = odbc_exec($dbConn,$sqlQuery);
        if (!$dbResult) {
           return false;
        }
        else {
           return true;
        }
   }

   // --------------------------------------------------------------------------------------------------

    // Standard get and Set methods

    function getProdCode() {
        return $this->prodCode;
    }
    function setProdCode($code) {
        $this->prodCode = $code;
    }

    function getProdName() {
        return $this->prodName;
    }
    function setProdName($name) {
        $this->prodName = $name;
    }

    function getProdDesc() {
        return $this->prodDesc;
    }
    function setProdDesc($desc) {
        $this->prodDesc = $desc;
    }

    function getProdPrice() {
        return $this->prodPrice;
    }
    function setProdPrice($price) {
        $this->prodPrice = $price;
    }
}

?>

Open in new window

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?
This is my error massage:
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.
Thanks, but I still have another error. PHP Parse error: syntax error, unexpected T_ELSE
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>&nbsp;&nbsp;&nbsp;&nbsp;<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>

Open in new window

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>");
   }

Open in new window

line 37... what does if contains ..."else" ... fix that...
if (!$product->getRecord($code, $name, $desc, $price))

   else{

Open in new window

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

	if (!$product->getRecord($code, $name, $desc, $price))

   else{

Open in new window


Should read

	if (!$product->getRecord($code, $name, $desc, $price))
        {
// code in here if statement is NOT true
        }else{

Open in new window