PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Tue Mar 26, 2019 8:56 pm

All times are UTC - 5 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Mar 16, 2018 5:26 am 
Forum Newbie

Joined: Fri Mar 16, 2018 5:21 am
Posts: 1
Syntax: [ Download ] [ Hide ]
   // including connection file
   // intialize the session
   // Check if the session is set
  // If session variable is not set it will redirect to login page
  if (!isset($_SESSION['username']) ||
     header("location: login.php");
    $sql = "SELECT * FROM campaigns WHERE id=:id";
    $stmt = $pdo->prepare($sql);
    $campaign = $stmt->fetchObject();
    if(isset($_POST['update'])) {
$title = $_POST['title'];
$url = $_POST['url'];
$region = $_POST['region'];
$target = $_POST['target'];
$description = $_POST['description'];
$campaign_budget = $_POST['campaignBudget'];
$sql = "UPDATE campaigns SET title=:title, url=:url,
 region=:region, target=:target, description=:description,
 campaign_budget=:campaign_budget WHERE id=:id"
$stmt = $pdo->prepare($sql);

if($stmt->execute()) {
header("Location: list_campaign.php");

<?php include_once "inc/header.php"; ?>

<?php include_once "inc/nav.php"; ?>

<section id="main-content">
<div class="page-header">
    <div class="page-title"><h1>Hi, <b><?php echo
    htmlspecialchars($_SESSION['username']); ?></b>. Update
    your delicious campaign.</h1>
    <?php if (isset($successAlert)){ ?>

        <?php echo '<div class="alert alert-success">' .
        $successAlert . '</div>'; ?>
        <?php }; ?>
    <?php if (isset($failAlert)) { ?>
            <?php echo '<div class="alert alert-danger">' .
     $failAlert . '</div>'; ?>
     <?php }; ?>
  <div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-title text-center mb-4">New
            <div class="card-body">
              <form action="<?php echo
 htmlspecialchars($_SERVER["PHP_SELF"]); ?>"
                  <div class="form-group">
                    <input type="text" class="form-control input-flat"
 name="title" value="<?= $campaign->title; ?>"
 placeholder="Title" required>
                  <div class="form-group">
                    <input type="url" class="form-control input-flat"
 name="url" value="<?= $campaign->url; ?>"
placeholder="URL" required>
                  <div class="form-group">
                    <select class="form-control" name="region">
                    <option value="<?= $campaign->region; ?>">
 <?= $campaign->region; ?></option>
                    <option value="World Wide" selected>World
                    <option value="United Kingdom">United
                    <option value="United States of America">United
 States of America</option>
                    <option value="Uraguay">Uruguay</option>
                    <option value="Vanuatu">Vanuatu</option>
                    <option value="Zimbabwe">Zimbabwe</option>
                  <div class="form-group">
                      <input type="checkbox" value="Windows"
 name="target" checked> Windows <br>
                      <input type="checkbox" value="Mac"
 name="target" checked> Mac <br>
                      <input type="checkbox" value="Linux"
 name="target" checked> Linux<br>
                      <input type="checkbox" value="Smartphone
 iOS" name="target" checked> Smartphone iOS<br>
                      <input type="checkbox" value="Smartphone
 Android" name="target" checked> Smartphone Android<br>
                  <div class="form-group">
                    <textarea class="form-control input-flat"
 placeholder="Describe your campaign here..."
 name="description"><?= $campaign->description; ?>
                  <div class="form-group">
                    <input type="text" class="form-control input-flat"
   value="<?= $campaign->campaign_budget; ?>"
  name="campaignBudget" required>
                  <button class="btn btn-primary" type="submit"
 name="update"><i class="ti-rocket"></i> Update</button>
  <?php include_once "inc/footer.php" ?>

Please check the code and point me what probably I am doing wrong.

I can't figure out why my code is not updating and the table and I keep getting errors back or sometime no error but table is not updating.

PostPosted: Sat Mar 17, 2018 12:15 pm 
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13590
Location: New York, NY, US
Check to see what error you are getting. See:
Syntax: [ Download ] [ Hide ]
$success = $stmt->execute();
echo '<pre>' . print_r($stmt->errorInfo(), 1) . '</pre>';
if($success) {
#header("Location: list_campaign.php");


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 5 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group