?
Solved

PHP script

Posted on 2011-10-19
10
Medium Priority
?
468 Views
Last Modified: 2013-12-12
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

0
Comment
Question by:antatiana
10 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 36997262
"doesn't work" is not an error message and most of the code is probably in "prodlist.class" which you didn't post.
0
 

Author Comment

by:antatiana
ID: 36997305
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

0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36997328
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?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:antatiana
ID: 36997341
This is my error massage:
PHP Fatal error: Call to undefined method ProdList::addProdCode()
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36997379
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.
0
 

Author Comment

by:antatiana
ID: 36997422
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

0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36997437
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

0
 
LVL 7

Expert Comment

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

   else{

Open in new window

0
 

Author Comment

by:antatiana
ID: 36997464
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?
0
 
LVL 11

Expert Comment

by:maeltar
ID: 36999668
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

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question