PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Jul 22, 2018 5:03 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 
Offline
Forum Newbie

Joined: Fri Mar 16, 2018 5:21 am
Posts: 1
Syntax: [ Download ] [ Hide ]
<?php
   // including connection file
   include_once('inc/db.php');
   // intialize the session
   session_start();
   // Check if the session is set
  // If session variable is not set it will redirect to login page
  if (!isset($_SESSION['username']) ||
   empty($_SESSION['username']))
  {
     header("location: login.php");
     exit;
  }
    $id=$_GET['id'];
    $sql = "SELECT * FROM campaigns WHERE id=:id";
    $stmt = $pdo->prepare($sql);
    $stmt->execute([':id'=>$id]);
    $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);

$stmt->bindParam(':id',$id);
$stmt->bindParam(':title',$title);
$stmt->bindParam(':url',$url);
$stmt->bindParam(':region',$region);
$stmt->bindParam(':target',$target);
$stmt->bindParam(':description',$description);
$stmt->bindParam(':campaign_budget',$campaign_budget);
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>
    </div>
    <?php if (isset($successAlert)){ ?>

        <?php echo '<div class="alert alert-success">' .
        $successAlert . '</div>'; ?>
        </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
 Campaign</div>
            <div class="card-body">
              <form action="<?php echo
 htmlspecialchars($_SERVER["PHP_SELF"]); ?>"
 method="post">
                  <div class="form-group">
                    <label>Title</label>
                    <input type="text" class="form-control input-flat"
 name="title" value="<?= $campaign->title; ?>"
 placeholder="Title" required>
                  </div>
                  <div class="form-group">
                    <label>URL</label>
                    <input type="url" class="form-control input-flat"
 name="url" value="<?= $campaign->url; ?>"
placeholder="URL" required>
                  </div>
                  <div class="form-group">
                    <label>Region</label>
                    <select class="form-control" name="region">
                    <option value="<?= $campaign->region; ?>">
 <?= $campaign->region; ?></option>
                    <option value="World Wide" selected>World
 Wide</option>
                    <option value="United Kingdom">United
 Kingdom</option>
                    <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>
                    </select>
                  </div>
                  <div class="form-group">
                    <label>Target</label>
                    <br>
                      <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>
                  <div class="form-group">
                    <label>Description</label>
                    <textarea class="form-control input-flat"
 placeholder="Describe your campaign here..."
 name="description"><?= $campaign->description; ?>
 </textarea>
                  </div>
                  <div class="form-group">
                    <label>Budget</label>
                    <input type="text" class="form-control input-flat"
   value="<?= $campaign->campaign_budget; ?>"
  name="campaignBudget" required>
                  </div>
                  <button class="btn btn-primary" type="submit"
 name="update"><i class="ti-rocket"></i> Update</button>
              </form>
            </div>
        </div>
    </div>
  </section>
  <?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.


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

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

_________________
(#10850)


Top
 Profile  
 
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 12 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