Jump to content

georgehowell

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

georgehowell's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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
  2. thanks for your reply. actually, my teacher wrote most of this. I'm just having problems with it now, in that the Administrator login isn't linking to that required section of the site. Attached is the "User.php" file, which may be the problem. It's for a school project which is due in two weeks. There's two others in my team as well, and we all would be very very appreciative towards any help that you may offer. Cheers,georgehowell [attachment deleted by admin]
  3. thanx a mil for your reply. Here's the code for "User.php" <?php class User extends ConnectToDb { public $username = ""; private $cart; private $products = array(); public function __construct() { parent::__construct(); } public function login($username,$password) { $ps = $this->db->prepare("Select username, password from sz_users where username = ? and password = ?"); $this->username = $username; $ps->execute(array($username,$password)); return ($ps->rowCount() == 1); } public function register($username,$password, $firstname,$lastname,$dob,$street,$city,$country, $zip,$homeAreaCode,$homeNo,$workAreaCode,$workNo, $email,$subscribe) { $ps = $this->db->prepare("Insert into SZ_users (username,password,firstname, lastname,dob,street,city,country,zip,homeAreaCode, homeNo,workAreaCode,workNo,email,subscribe) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); $ps->execute(array($username,$password, $firstname,$lastname,$dob,$street,$city, $country,$zip,$homeAreaCode,$homeNo, $workAreaCode,$workNo,$email,$subscribe)); return ($ps->rowCount() == 1); } function get_username() { return $this->username; } public function __sleep() { return array("username","cart","products"); } public function __toString() { return "user = " . $username; } } ?>
  4. hallo php freaks. the following code seems to have a problem differentiating between a user and administrator login: <?php @session_start(); function __autoload($class_name) { require_once $class_name . '.php'; } if(isset($_POST['username']) && isset($_POST['password'])) { $user = new User(); if($user->login($_POST['username'], $_POST['password'])) { $_SESSION['user'] = $user; include("home.php"); exit(); } } ?> The intention is, that the Administrator is redirected to the Admin section of the site upon login, while all other users surf as usual. The "status" column in the database differentiates all other users from the administrator by containing either a "1" or "0", one being the Administrator. Anyway, this is my attempt, which has errors. If anyone out there has a more efficient approach to login forms, please let me know. Thanks, georgehowell
  5. <form action="Search.php" method="get"> <input type="text" name="search" class="phpsearch_input" size="18" autocomplete="off" value="<?php echo (isset($_REQUEST['search']))?htmlspecialchars($_REQUEST['search']):'';?>"/> <input type="submit" name="go" value="<?php echo $this->label('Search Site');?>" class="serviceNav_button"/> </form>
  6. Hi thorpe ...Is the file this screenshot comes from a .php file? No, it's in HTML.
  7. hi gurus i've got this small problem with this HTML form, that the PHP code is appearing in some of the input-fields unintentionally. Does anyone know how to hide it? thanx, georgehowell [attachment deleted by admin]
  8. hi the following was written mostly by my college teacher, but i can't quite get it working. Does anyone out there know how i can make "RegoForm.php" recognize a user that is logged-in, and allow this user to edit his/her details (stored in the database) using the same form? Here's the code for the form: <?php ob_start(); require_once("lib/class_loader.php"); session_start(); ob_flush(); $user = $_SESSION['user']; $userDetails = null; if($user != null) { $userDetails = $user->getDetails(); } ?> <html> <body> <form name="join" id="client" name="client" action="register.php" onsubmit="return validate()" method="post"> username : <input type="username" name="username" id="userNameID" size=10 maxlength=15 value="<?php echo ($user != null)?$userDetails->username:"";?>" /> password : <input type="password" name="password" id="passwordID" size=10 maxlength=15 value="<?php echo ($user != null)?$userDetails->password:"";?>" /> </form> </body> </html> Here's the "register.php" (form action) code: <?php include("lib/ConnectToDb.php"); include("lib/User.php"); //print_r($_POST); if(isset($_POST['username']) && isset($_POST['password'])) { $user = new User(); if($user->register( $_POST['username'] ,$_POST['password'] } ?> <?php include("home.php"); ?> Any help would be much appreciated (by my team members as well) Thanx georgehowell [attachment deleted by admin]
  9. thanx ChemicalBlis it works! you're a very considerate gentleman. May you have decades of good fortune
  10. hi there there seems to be lots of code out there for saving email content to a database, but what about sourcing email addresses from a database to compile mailouts? Here's my first attempt (which doesn't work), but i'm just a student (sorry)... <?php $database = "skyzone"; $username = "root"; $password = ""; // connect to database $db = new PDO("mysql:host=localhost;dbname=$database",$username,$password); //query database $result = db_query("SELECT email FROM users WHERE subscribe = '1'", $emails); while ($row = db_fetch_object($result)) { $to = $emails; $subject = "SkyZone Newsletter"; $body = "Newsletter.pdf"; if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } } Does any body know? cheers, George
  11. sorry Cags, got you mixed up with some advert at the bottom of the page. I kept getting errors after placing the code you gave me into "register.php" - something i'm doing wrong. The attached files give me a result at least, but there's no differentiation between whether the checkbox is checked or not... Here's the html <form name="join" action="register.php" onsubmit="checkEmptyFields()" method="post"> <input name="subscribe" type="checkbox" id="subscribe"> <input name="submit" type="submit" id="submit" > </form> p.s. What do i owe you for helping me on this one? thanx, George [attachment deleted by admin]
  12. hi CodeCanyon I'm giving it ago in the following fashion: "User.php" <?php class User extends ConnectToDB { public function newsletter($subscribe = isset($_POST['subscribe']) ? 1 : 0; { $ps = $this->db->prepare("Insert into users (subscribe) values (?)"); $ps->execute(array($subscribe)); return ($ps->rowCount() == 1); } } ?> Anybody, please let me know if this looks totally wrong. Not sure what values to set the column within "users" table however. Thanx a mil CodeCanyon
  13. hi again, sorry that my first ever forum entry was so vaguely composed. my question is, if the target column in the MySQL DB is a "tiny init", will the following html checkbox give me a "1" if checked, or "0" unchecked? <input name="subscribe" type="checkbox" id="subscribe" value="true" property="boolean" > Here's my PHP: <?php include("lib/ConnectToDb.php"); include("lib/User.php"); print_r($_POST); if(isset($_POST['username']) && isset($_POST['password'])) { $user = new User(); if($user->register( $_POST['subscribe'])) { include("Welcome.php"); exit(); } } ?>
  14. dear PHP experts out there, I've been successful in populating a designated table in a MySQL database up until including a checkbox in the html form. Here's my code so far: "RegoForm.html" <form name="join" action="register.php" method="post"> NAME: <input name="name" type="text" > EMAIL: <input name="email" type="text" > NEWSLETTER: <input name="subscribe" type="checkbox" id="newsletter" value="true" property="boolean" > <input name="submit" type="submit" id="submit" > </form> "register.php" <?php include("lib/ConnectToDb.php"); include("lib/User.php"); print_r($_POST); if(isset($_POST['username']) && isset($_POST['password'])) { $user = new User(); if($user->register( $_POST['name'] $_POST['email'], $_POST['subscribe'])) { include("Welcome.php"); exit(); } } ?> "ConnectToDb.php" <?php class ConnectToDb { protected $db; public function __construct() { $this->connect(); } public function connect() { $database = "SkyZone"; $username = "root"; $password = ""; // connect to database $this->db = new PDO("mysql:host=localhost;dbname=$database",$username,$password); } } ?> "User.php" <?php class User extends ConnectToDb { public function __construct() { parent::__construct(); } public function login($username,$password) { $ps = $this->db->prepare("Select username, password from users where username = ? and password = ?"); $ps->execute(array($username,$password)); return ($ps->rowCount() == 1); } public function register($name,$email,$subscribe) { $ps = $this->db->prepare("Insert into users (name,email,subscribe) values (?,?,?)"); $ps->execute(array($name,$email,$subscribe)); return ($ps->rowCount() == 1); } } ?>
×
×
  • 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.