Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Senior Member
    Join Date
    Apr 2016
    Posts
    717
    Member #
    53891
    Liked
    11 times

    trying to insert into table but not working

    im not even getting any error messages its just not working. can anyone please look over the code?


    MAIN FILE

    PHP Code:
    <?php require_once("includes/db.php");?>
    <?php 
    require_once("includes/functions.php");?>
    <?php 
    require_once("includes/sessions.php");?>
    <?php

    if (isset($_POST["submit"])){
      
    $catagory $_POST["title"];
      
    $admin "Cole";

      
    date_default_timezone_set("Europe/Dublin");
      
    $currenttime time();
      
    $datetimestrftime("%B-%d-%Y %H:%M:%S"$currenttime);

      if (empty(
    $catagory)){
        
    $_SESSION["error"] = "please fill in the form correctly";
        
    redirect("catagory.php");
      } elseif (
    strlen($catagory)<3){
        
    $_SESSION["error"] = "catagory must be greater than two charachters";
        
    redirect("catagory.php");
      }elseif(
    strlen($catagory)>49){
        
    $_SESSION["error"] = "catagory is too long";
        
    redirect("catagory.php");
      }else {
        
    $sql "INSERT INTO catagory(title,author,datetime) VALUES(:catagoryname,:adminname,:dateTime)";
        
    $stmt $connect->prepare($sql);
        
    $stmt->bindValue(':catagoryname'$catagory);
        
    $stmt->bindValue(':adminname'$admin);
        
    $stmt->bindValue(':dateTime'$datetime);
        
    $Execute $stmt->execute();

        if(
    $Execute){
          
    $_SESSION["success"] = "data added successfully";
          
    redirect("basic.html");
        }else {
          
    $_SESSION["error"] = "something went wrong. data not added to table";
          
    redirect("catagory.php");
        }
      }
    }

    ?>
    <!doctype html>
    <html>

      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-compatible" content="ie=edge">
        <title>Catagories</title>
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
        <link rel="stylesheet" href="css/styles.css">
      </head>

      <body>

        <!-- NAVBAR START -->
        <div style="height:10px; background-color:rgb(100,100,100);"></div>
          <nav class="navbar navbar-expand-lg bg-dark navbar-dark">
            <div class="container">
              <a href="#" class="navbar-brand">jazebakram.com</a>
              <button class="navbar-toggler" data-toggle="collapse" data-target="#navbarcollapsecms"><span class="navbar-toggler-icon"></span></button>
              <div class="collapse navbar-collapse" id="navbarcollapsecms">
              <ul class="navbar-nav mr-auto">
                <li class="nav-item"><a href="myprofile.php" class="nav-link"> <i class="fas fa-user"></i> Profile</a></li>
                <li class="nav-item"><a href="dashboard.php" class="nav-link">Dashboard</a></li>
                <li class="nav-item"><a href="posts.hp" class="nav-link">Posts</a></li>
                <li class="nav-item"><a href="catagories.php" class="nav-link">Catagories</a></li>
                <li class="nav-item"><a href="admins.php" class="nav-link">Manage admins</a></li>
                <li class="nav-item"><a href="comments.php" class="nav-link">Comments</a></li>
                <li class="nav-item"><a href="blog.php?page=1" class="nav-link">Live blog</a></li>
              </ul>
              <ul class="navbar-nav ml-auto">
                <li class="nav-item"><a href="logout.php" class="nav-link"><i class="fas fa-user-times"></i> Log out</a></li>
              </ul>
              </div>
            </div>
          </nav>
        <div style="height:10px; background-color:rgb(100,100,100);"></div>
        <!-- NAVBAR END -->

        <!-- HEADER START -->
        <header class="bg-dark text-white">
          <div class="container">
            <div class="row">
              <h1> <i class="fas fa-edit style="color: #27aae1;"></i> Manage catagories</h1>
            </div>
          </div>
        </header>
        <!-- HEADER END -->

        <!-- MAIN AREA -->
        <section class="container py-2 mb-4">
          <div class="row">
            <div class="offset-lg-1 col-lg-10" style="min-height: 600px;">
              <?php
              
    echo errormessage();
              echo 
    successmessage();
              
    ?>
              <form action="catagory.php" method="post">
                <div class="card bg-secondary text-light ">
                  <div class="card-header">
                    <h1>Add new catagory</h1>
                  </div>
                </div>
                <div class="card-body bg-dark" >
                  <div class="form-group">
                    <label for="title"><span class="fieldinfo">Catagory title:</span></label>
                    <input class="form-control"  type="text" name="title" id="title" value="">
                  </div>
                  <div class="row">
                    <div class="col-lg-6 mb-2">
                      <a href="dashboard.php" class="btn btn-warning btn-lg btn-block"><i class="fas fa-arrow-left">Back to dashboard</i></a>
                    </div>
                    <div class="col-lg-6 mb-2">
                      <button type="submit" name="submit" class="btn btn-success btn-lg btn-block"><i class="fas fa-check">Publish</i></button>
                    </div>
                  </div>
                </div>
              </form>
            </div>
          </div>
        </section>


        <!-- FOOTER START -->
        <footer class="bg-dark text-white">
          <div class-"container">
            <div class="row">
              <div class="col">
                <p class="lead text-center">Theme by Cole Pratt</p>
              </div>
            </div>
          </div>
        </footer>

        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
      </body>



    </html>
    DB CONNECT FILE
    PHP Code:
    <?php

    $DSN 
    "mysql:host = localhost, dbname=cms";
    $connect = new PDO($DSN'root''');

    ?>
    REDIRECT FUNCTION FILE

    PHP Code:
    <?php

    function redirect($new_target){
      
    header("Location:".$new_target);
      exit;
    }

     
    ?>
    SESSION FILE

    PHP Code:
    <?php

    SESSION_START
    ();

    function 
    errormessage(){
      if (isset(
    $_SESSION["error"])){
        
    $output "<div class=\"alert alert-danger\">";
        
    $output .= htmlentities($_SESSION["error"]);
        
    $output .= "</div>";
        
    $_SESSION["error"] = null;
        return 
    $output;
      }
    }

    function 
    successmessage(){
      if (isset(
    $_SESSION["success"])){
        
    $output "<div class=\"alert alert-success\">";
        
    $output .= htmlentities($_SESSION["success"]);
        
    $output .= "</div>";
        
    $_SESSION["success"] = null;
        return 
    $output;
      }
    }

    ?>
    any help appreciated. thanks guys

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    datetime sometimes is small T and sometimes is capital T

    dateTime
    datetime

    which one is it? everything IS case-sensitive

    Check other column names too .... "catagory" is spelled "category" .... did you spell it differently in other places?



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 02:49 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com