im是为了找出我剩下的php / sql / html代码。我只是想在满足特定条件的情况下更改数据库中的数字值。请详细说明以免将其标记为重复。
W3SCHOOLS示例:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE MyGuests SET lastname='Doe' WHERE id=2";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
?>
更改设置:(名为“ settings-profile.vc.php”)
<?php
$routePath = "../";
require_once($routePath . "_config/db.php");
$dbConfig = new config_db();
$db = $dbConfig->init();
require_once($routePath . "_config/app.php");
require_once($routePath . "_lib/c/Photo_Resizer.php");
require_once($routePath . "_mc/UsrCustomerMembershipOrder.mc.php");
$mcUsrCustomerMembershipOrder = new UsrCustomerMembershipOrder_MC();
require_once($routePath . "_mc/UsrCustomer.mc.php");
$mcUsrCustomer = new UsrCustomer_MC();
require_once($routePath . "_mc/UsrCustomerProfile.mc.php");
$mcUsrCustomerProfile = new UsrCustomerProfile_MC();
require_once($routePath . "_mc/Product.mc.php");
$mcProduct = new Product_MC();
require_once($routePath . "_mc/ProductTag.mc.php");
$mcProductTag = new ProductTag_MC();
require_once($routePath . "_mc/Merchant.mc.php");
$mcMerchant = new Merchant_MC();
require_once($routePath . "_mc/ProductTagLink.mc.php");
$mcProductTagLink = new ProductTagLink_MC();
/********** Implementation **********/
// Check Session Credentials and auto-login
if ($_SESSION['usrcustomerid'] == '') {
header('Location: signout.php'); die();
}
$usrcustomerid = $_SESSION['usrcustomerid'];
$rowUsrCustomerProfile = $mcUsrCustomerProfile->SelectObj_ByUsrCustomerId($db, $usrcustomerid);
// On Register Click
if (isset($_POST['save']) && $_POST['save'] == 'SAVE')
{
$err_msg = '';
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$birthdate = $_POST['birthdate'];
$birthdate = date('Y-m-d H:i:s', strtotime($birthdate));
$country = $_POST['country'];
$address = $_POST['address'] . ' ';
$contact = $_POST['contact'];
if ($birthdate == '') { $err_msg .= '<li>Enter your Birth Date. </li>'; }
if ($lname == '') { $err_msg .= '<li>Enter your last name. </li>'; }
if ($fname == '') { $err_msg .= '<li>Enter your first name. </li>'; }
if ($contact == '') { $err_msg .= '<li>Enter your contact number. </li>'; }
/**** If form is valid then Save to database ****/
if($err_msg == '')
{
$mcUsrCustomerProfile->UpdateObj($db, $usrcustomerid, $fname, $lname, $birthdate, $country, $address, $contact);
}
} ?>
它正在使用文件“ UsrCustomerProfile.mc.php”中的公共功能
public function UpdateObj($db, $usrcustomerid, $fname, $lname, $birthdate, $country, $address, $contact) {
$stmt = $db->prepare(
" UPDATE usr_customer_profile
SET fname = :fname, lname = :lname, birthdate = :birthdate, country = :country, address = :address, contact = :contact
WHERE usrcustomerid = :usrcustomerid"
);
$stmt->bindValue(':usrcustomerid', $usrcustomerid, PDO::PARAM_INT);
$stmt->bindValue(':fname', $fname, PDO::PARAM_STR);
$stmt->bindValue(':lname', $lname, PDO::PARAM_STR);
$stmt->bindValue(':birthdate', $birthdate, PDO::PARAM_STR);
$stmt->bindValue(':country', $country, PDO::PARAM_STR);
$stmt->bindValue(':address', $address, PDO::PARAM_STR);
$stmt->bindValue(':contact', $contact, PDO::PARAM_STR);
$stmt->execute();
$rowAffected = $stmt->rowCount();
return $rowAffected;
}
现在我有一个php代码,其中用户的状态由他/她拥有的软件包ID决定
<?php
// Check Session Credentials and auto-login
$packageid = $_SESSION['usrcustomer_packageid'];
if ($packageid == 0) {
$ribbon = 'ribbon-guest';
} else if ($packageid <= 1) {
$ribbon = 'ribbon-elite';
} else if ($packageid == 2) {
$ribbon = 'ribbon-premium';
} else if ($packageid == 3) {
$ribbon = 'ribbon-luxury';
}
echo('Status: <a href="membership.php"><img src="../img/'.$ribbon.'.png" class="small-icon"></a> ');
if ($packageid == 0) {
echo ('Guest <br/>');
} else if($packageid == 1) {
echo('Elite Member <br/>');
} else if($packageid == 2) {
echo('Premium Member <br/>');
} else if($packageid == 3) {
echo('Luxury Member <br/>');
}
if ($_SESSION['usrexpirationdays'] <= 0) {
$_SESSION['usrcustomer_packageid'] = 0;
} else if (isset($_SESSION['usrexpirationdate'])) {
echo(' <small>(Expiry: ' . $_SESSION['usrexpirationdate'] . ', ' . $_SESSION['usrexpirationdays'] . ' days remaining)</small>');
}
?>
<?php } else { ?>
“ if($ _SESSION ['usrexpirationdays'] <= 0){ $ _SESSION ['usrcustomer_packageid'] = 0;“