Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8754665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:40:39+00:00 2026-06-13T13:40:39+00:00

I’ve got a php script as follows: function addPost(BlogPost $item, $tags) { $connection =

  • 0

I’ve got a php script as follows:

function addPost(BlogPost $item, $tags) {
        $connection = mysql_connect('localhost', '***', '***') or die(mysql_error());
        mysql_select_db('jschaible1') or die(mysql_error());

        $queryString = "insert into BlogPost values ( null, '" . $item->Title . "', '" . $item->Body . "', " . "now());";

        $result = mysql_query($queryString) or die(mysql_error());

        $dbResult = mysql_query('select * from blogpost where Title = "' . $item->Title . '";') or die(mysql_error());
        while ($row = mysql_fetch_array($dbResult)) {
            $tableID = $row['BlogPostID'];
        }

        foreach($tags as $t) {
            $queryString = "insert ignore into Tag values('" . strtolower($t) . "');";
            mysql_query($queryString) or die(mysql_error());

            $queryString = "insert into blogposttag values (" . $tableID . ", '" . strtolower($t) . "');";
            mysql_query($queryString) or die(mysql_error());
        }

        echo $connection;
        mysql_close($connection) or die(mysql_error());
    }

The function is being called like this:

<?php
    session_start();

    $errors = '';

    if (!isset($_SESSION['dadfg6d5f6df54']))
        header('Location:admin.php');
    else {
        include('Classes.php');
        include('mySql.php');
        include('utils.php');

        if(isset($_POST['Submit'])) {
            if ($_POST['Title'] == '') {
                $errors = 'Post must have a title!';
            }
            else if ($_POST['PostBody'] == '') {
                $errors = 'Post must be something!';
            }
            else if (strlen($_POST['PostBody']) < 10) {
                $errors = "Write something substantial, c'mon!";
            }
            else if ($_POST['Tags'] == '') {
                $errors = "At least one tag must be entered";
            }
            else {
                $newPost = new BlogPost(NULL, sanitize($_POST['Title']), sanitize($_POST['PostBody']), NULL);

                $newPost->Title = addEmoticons($newPost->Title);
                $newPost->Body = addEmoticons($newPost->Body);

                $tags = str_replace(',', '', $_POST['Tags']);
                $tags = str_replace(';', '', $tags);
                $tags = explode(' ', $tags);

                error_reporting(E_ALL); ini_set('display_errors', 1);
                addPost($newPost, $tags) or die();

                $errors = 'Post added successfully';
            }
        }
    }
?>

When it gets to mysql_close(), the page just stops executing and I get a blank page. This is really frustrating me, I don’t understand at all why it’s happening, especially seeing as how the echo on the PREVIOUS line puts out “resource id#6”. I get no error message, just a blank page! Please help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:40:40+00:00Added an answer on June 13, 2026 at 1:40 pm

    Your function has no return value. It therefore returns NULL which evaluates as a “falsy” value. Since you follow it with an or die() call, the false evaluation triggers the or die() and terminates your script.

    // Don't do this:
    addPost($newPost, $tags) or die();
    
    // Do this:
    addPost($newPost, $tags);
    

    In the end of your function, you could return TRUE, but it is entirely unnecessary unless you wish to return a value based on the success or failure of your post addition. The way you have it, the die() is just causing undue harm. Since all the potential failing points in your function are already going to terminate the script on error, there is no great purpose to returning TRUE. Just remove the die() after the function call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I want to count how many characters a certain string has in PHP, but
I have a small JavaScript validation script that validates inputs based on Regex. I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.