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 8677223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:24:09+00:00 2026-06-12T20:24:09+00:00

I am using a MySQL database. I am completely sure that the ID does

  • 0

I am using a MySQL database. I am completely sure that the ID does actually exist in the database. Why is it going to the last else (where is says //incorrect id) ?

<?php
            //Localise user id.
            $userid = $_SESSION['userid'];

            //Get content of the article.
            $sql = "SELECT * FROM articles WHERE creatorid = '$userid'";
            $result = mysql_query($sql) or die(mysql_error()); //Execute. If fails, show error.
            $array = mysql_fetch_array($result);

            if(in_array($articleid, $array)) //If the URL id exists in the database (array)
            {
                //The article does actually exist for that user. They requested it.
                $sql = "SELECT * FROM articles WHERE id = '$articleid'";                
                $result = mysql_query($sql) or die(mysql_error()); //Execute. If fails, show error. 
                $array = mysql_fetch_array($result);

                        $content = $array['content'];

                        if($content != '') //If the article has actually been written.
                        {
                            include($_SERVER['DOCUMENT_ROOT'] . '/includes/renderimage.php');
                        }   else
                            {
                                //Article actually hasn't been written.
                            }
            }   else
                {
                    //Incorrect ID.
                }
                ?>
  • 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-12T20:24:14+00:00Added an answer on June 12, 2026 at 8:24 pm

    You’re only looking in the first row that’s returned. You need to call mysql_fetch_array in a loop to get each row. Also, you shouldn’t use in_array(), since the article ID might appear in some other column (what if you’re checking for article #3 and user #3?).

    But if you just want to see if the article was created by this user, you can use a different query:

    SELECT * FROM articles WHERE creatorid = '$userid' AND articleid = '$articleid';
    

    This should return either 0 or 1 row depending on whether the user created the article. You can then use mysql_num_rows() to test for this.

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

Sidebar

Related Questions

I have a webapp written in PHP using a MySQL database backend. This question
I am using a MySQL database and I have a big mysql_query that works
I'm using Mysql database and neatbeans IDE conncting by mysql-connector-java-5.1.21 jdbc , and I
I was using Mysql database before and decided to switch to Postgresql and now,
I am using Mysql database. I have 3 table-: table Column tier_price customer_id,sku(Unique),price,website catalog_product
I am using MySQL database and JSP for a project. In my project there
I have created a MySQL database using MySQL Workbench. It has about 20 tables.
I'm using a MySQL database and accessing it through Java. PreparedStatement prep1 = this.connection.prepareStatement(
I'm using a MySQL database to store scores for my game. A very simplified
I am using MySQL as database. I need to update some data. However the

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.