Jump to content

Recommended Posts

Hi there

the following table that is populated dynamically from SQL table.

<?php

try{

      $database = "SkyZone";

    $username = "root";

    $password = "";

 

    // connect to database

$db = new PDO("mysql:host=localhost;dbname=$database",$username,$password);

$query = "SELECT id, title, on_hand FROM SZ_products order by on_hand asc;";

$table =$db->query($query);

echo "<form method='post' name='onHandID' action='updateInventory.php'>";

echo "<table width='550px' class='altrowstable' id='alternatecolor'>";

foreach($table as $row)

{

        echo "<tr id='row'>\n";

echo "<td style='text-align:center'>" . $row['id'] . "</td>";

echo "<td style='padding-left:5px'>" . $row['title'] . "</td>";

echo "<td style='text-align:right'>" . $row['on_hand'] . "</td>";

        echo "<td><input name='onHandID' type='submit' value='add'></td>";

echo "</tr>";

}

echo "</table></form>";

//destroy the PDO object

$db = null;

//if connection fails throw a PDO exception

}catch (PDOException $e) {

    print "Error!: " . $e->getMessage() . "<br/>";

    die();

}

?>

 

The "add" button is intended to increment the value "on_hand" by one. Here's the PHP files called on submit:

 

"updatedInventory.php"

 

<?php

ob_start();

require_once("lib/class_loader.php");

session_start();

ob_flush();

 

$user = $_SESSION['user'];

$user->updateInventory($_GET);

 

include("Admin_4.php");

?>

 

"Administrator.php"

 

<?php

class Administrator extends User

{

    public function __construct()  {

      parent::__construct();

    }

public function updateInventory($on_hand) {

  $ps = $this->db->prepare("UPDATE SZ_products SET on_hand= on_hand+1 WHERE onHandID = $on_hand");

  $ps->execute(array($on_hand));

  return ($ps->rowCount() == 1);

}

}

 

The "WHERE" /sql part of the query is not working here.

 

Any comments appreciated

cheers, George

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.