Updating quantities in database
Posted: Wed Feb 18, 2009 11:19 am
I always preface these posts asking for patience because I'm a newbie to php, so here goes ...
I have a database that I ultimately want to use to store a wine inventory. I currently have the following fields: 'quantity', 'vintage', 'name', 'variety', 'price', 'redOrWhite'. I have figured out how to search for a match based on HTML input from a form using (abbreviated):
<?php
$quantity=$_POST['quantity'];
$vintage=$_POST['vintage'];
//name, variety, price, redWhite ..
$userInput=$vintage.$name.$variety
$dupe=false;
@ $db=new mysqli('localhost', 'root', mypassword, 'wine');
$query=//need assistance here;
$result=$db->query($query);
$numRows=$result->num_rows;
for($i=0; $i<$numRows; $i++) {
$row=$result->fetch_assoc();
$checkDupe=$row['vintage'].$row['name'].$row['variety'];
if($checkDupe==$userInput) {
$dupe=true;
/// NOW WHAT??
}
}
$db->close();
$result->free();
I'm trying to learn php using OO rather than procedural, so I'd appreciate answer(s) using OO if possible. Don't mean to sound snooty, just that my programmer friends say I'm best off learning this way based on my future endeavors using PHP.
Many thanks in advance to all.
sleepydad
I have a database that I ultimately want to use to store a wine inventory. I currently have the following fields: 'quantity', 'vintage', 'name', 'variety', 'price', 'redOrWhite'. I have figured out how to search for a match based on HTML input from a form using (abbreviated):
<?php
$quantity=$_POST['quantity'];
$vintage=$_POST['vintage'];
//name, variety, price, redWhite ..
$userInput=$vintage.$name.$variety
$dupe=false;
@ $db=new mysqli('localhost', 'root', mypassword, 'wine');
$query=//need assistance here;
$result=$db->query($query);
$numRows=$result->num_rows;
for($i=0; $i<$numRows; $i++) {
$row=$result->fetch_assoc();
$checkDupe=$row['vintage'].$row['name'].$row['variety'];
if($checkDupe==$userInput) {
$dupe=true;
/// NOW WHAT??
}
}
$db->close();
$result->free();
I'm trying to learn php using OO rather than procedural, so I'd appreciate answer(s) using OO if possible. Don't mean to sound snooty, just that my programmer friends say I'm best off learning this way based on my future endeavors using PHP.
Many thanks in advance to all.
sleepydad