www.webdeveloper.com
Results 1 to 4 of 4

Thread: PHP for weblog

  1. #1
    Join Date
    Jul 2014
    Posts
    6

    PHP for weblog

    Hello!

    So I'm trying to incorporate this weblog on my website, but for some reason it isn't posting to myPHPadmin nor redirecting to another page.
    Here is the code -
    many thanks!

    <?php

    // Variables
    $topic = "";
    $title = "";
    $blog = "";
    $msg = "";

    //IF FORM SUBMITTED
    if (isset($_POST['blog'])) {
    //PICK UP FORM POSTS
    $topic = $_POST['topic'];
    $title = $_POST['title'];
    $blog = $_POST['blog'];

    //filter here, one example
    $topic = mysqli_real_escape_string($db_conx, $topic);
    $title = mysqli_real_escape_string($db_conx, $title);
    $blog = mysqli_real_escape_string($db_conx, $blog);



    ALL FIELDS NOT FILLED IN, GIVE THIS
    if (($topic == " ") || ($title == "" || ($blog == ""))
    { $msg = '<h1 style="color: #F00;">PLEASE FILL IN ALL FIELDS</h1>';

    }
    else {

    //FORM FILLED IN, SO GRAB THEIR SESSION NAME AND ID
    $id = $_SESSION['id'];
    $author = $_SESSION['username'];
    //INSERT NEW BLOG INTO MYSQL AND GRAB THE INSERTED ID
    $sql = "INSERT INTO blog(blog_cat, blog_title, blog_body, authid, authname, datetime) VALUES('$topic','$title','$blog','$id','$author',now())";
    $query = mysqli_query($db_conx, $sql);
    $blPid = mysqli_insert_id($db_conx);

    // SET DATA FOR PRIVATE MESSAGES TO SUBSCRIBERS
    $from_id = $id;
    $subject = "Subscription Notice";
    $message = "Hey, I just wrote a new blog!";
    $opened = 0;
    $recipientDelete = 0;
    $senderDelete = 0;

    //GRAB SUBSCRIBERS LIST FOR THIS AUTHOR
    $subArray = mysqli_query($db_conx, "SELECT subscribers FROM users WHERE id='$id' LIMIT 1");
    while ($subrow = mysqli_fetch_array($subArray, MYSQLI_ASSOC)) {
    $subscription_array = $subrow["subscribers"];
    }

    //IF THE AUTHOR HAS SUBSCRIBERS
    if ($subscription_array != "") {

    //PUT THE SUBSCRIBERS IN A WORKABLE ARRAY
    $subscription_array2 = explode(",", $subscription_array);
    //CREATE LOOP FIRE OFF A PM TO EACH SUBSCRIBER
    foreach ($subscription_array2 as $key => $value) {
    //INSERT PM FOR EACH SUBSCRIBER INTO PM TABLE USING $VALUE TO THEIR ID
    $notify = mysqli_query($db_conx, "INSERT INTO notifications (username, initiator, note, did_read)
    VALUES('$value','$from_id','$message','$opened')");

    //SEND THEM SOMEWHERE
    header("location: blog.php?blPid=$blPid");exit();
    }
    }
    }
    ?>

  2. #2
    Join Date
    Jul 2014
    Posts
    6
    okay so I got the blog entries to post to myPHPadmin, but im not being headered away by this - header("location: blog.php?blPid=$blPid");exit();

  3. #3
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    780
    What happens when you run the script? At what step is it failing to do what you want? Turn on php error checking to ensure there are no errors and to get any messages if there are. Put in some echo statements to show important steps as they occur. This is called debugging.

    PS - You do realize that phpadmin has absolutely nothing to do with this code?
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    780
    1 - phpadmin is not involved here.
    2 - turn on error checking. Perhaps your final query is not executing and since you DON"T have a proper check of that possibility, you could be having a problem that aborts your script before it gets to the header line.
    3 - please post any future code samples properly, using the forum's preferred code tags.
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles