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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:52:44+00:00 2026-06-10T00:52:44+00:00

I am coding a php page off of an mySQL database and the table

  • 0

I am coding a php page off of an mySQL database and the table is fully built with all the columns I am trying to have viewed on a website, but my select statement is returning an error. It won’t recognize the first column I input. I’ve taken out the “lastname” search and had it just start with “firstname” and had the same problem. On another use of this table I am also having trouble inputting stuff into the first column. Am I forming my statement wrong or something?

I am using a common functions php with this code:

function connectDatabase() {
    require('../DBtest.php');

    $host     = 'localhost';
    $userid   = '7an7';
    $password = '7dl7';

    $db = mysql_perry_pconnect($host, $userid, $password);

    if (!$db) {
        print "<h1>Unable to Connect to MySQL</h1>";
        exit;
    }

    $dbname = '7phpmysql7';
    $dbtest = mysql_perry_select_db($dbname);

    if (!$dbtest) {
        print "<h1>Unable to Select the Database</h1>";
    }

    return $db;
}

function selectResults($statement) {

    $output      = "";
    $outputArray = array();

    $db = connectDatabase();

    if ($db) {
        $result = mysql_query($statement);

        if (!$result) {
            $output .= "ERROR";
            $output .= "<br /><font color=red>MySQL No: " . mysql_errno();
            $output .= "<br />MySQL Error: " . mysql_error();
            $output .= "<br />SQL Statement: " . $statement;
            $output .= "<br />MySQL Affected Rows: " . mysql_affected_rows() . "</font><br />";

            array_push($outputArray, $output);
        } else {

            $numresults = mysql_num_rows($result);

            array_push($outputArray, $numresults);

            for ($i = 0; $i < $numresults; $i++) {
                $row = mysql_fetch_array($result);

                array_push($outputArray, $row);
            }
        }
    } else {

        array_push($outputArray, 'ERROR-No DB Connection');
    }

    return $outputArray;
}

Then local code that is utilizing the common functions is:

<?php
include "king_common_functions.php";

viewGuestbook();

//****************************************************************
//Display Admin Guestbook Data (All Submissions)
//****************************************************************

function viewGuestbook() {
    $outputDisplay = "";
    $myrowcount    = 0;

    $statement = "SELECT lastname, firstname, contact_type, contact_info, city, comments, date_added";
    $statement .= "FROM u1585_Guestbook ";
    $statement .= "ORDER BY lastname ";

    $sqlResults = selectResults($statement);

    $error_or_rows = $sqlResults[0];


    if (substr($error_or_rows, 0, 5) == 'ERROR') {
        print "<br />Error on DB";
        print $error_or_rows;
    } else {
        $arraySize = $error_or_rows;

        for ($i = 1; $i <= $error_or_rows; $i++) {
            $lastname     = $sqlResults[$i]['lastname'];
            $firstname    = $sqlResults[$i]['firstname'];
            $contact_type = $sqlResults[$i]['contact_type'];
            $contact_info = $sqlResults[$i]['contact_info'];
            $city         = $sqlResults[$i]['city'];
            $comments     = $sqlResults[$i]['comments'];
            $date_added   = $sqlResults[$i]['date_added'];

            $outputDisplay = "<h3>View Guestbook:</h3>";
            $outputDisplay .= '<table border=1 style="color: black;">';
            $outputDisplay .= '<tr><th>Last Name</th><th>First Name</th><th>Contact Type</th><th>Contact Info</th>';
            $outputDisplay .= '<th>City</th><th>Comments</th><th>Date Added</th></tr>';

            $numresults = mysql_num_rows($sqlResults);

            for ($j = 0; $j < $numresults; $j++) {
                if (!($j % 2) == 0) {
                    $outputDisplay .= "<tr style=\"background-color: #F5DEB3;\">";
                } else {
                    $outputDisplay .= "<tr style=\"background-color: white;\">";
                }

                $myrowcount++;

                $outputDisplay .= "<td>" . $lastname . "</td>";
                $outputDisplay .= "<td>" . $firstname . "</td>";
                $outputDisplay .= "<td>" . $contact_type . "</td>";
                $outputDisplay .= "<td>" . $contact_info . "</td>";
                $outputDisplay .= "<td>" . $city . "</td>";
                $outputDisplay .= "<td>" . $comments . "</td>";
                $outputDisplay .= "<td>" . $date_added . "</td>";
                $outputDisplay .= "</tr>";
            }
        }
    }

    $outputDisplay .= "</table>";
    $outputDisplay .= "<br /><br /><b>Number of Rows in Results: $myrowcount </b><br /><br />";
    print $outputDisplay;
}

Here is the table structure:

CREATE TABLE u1585_Guestbook (
    guest_id int(11) NOT NULL AUTO_INCREMENT,
    lastname varchar(40) NOT NULL,
    firstname varchar(30) NOT NULL,
    contact_type varchar(30) NOT NULL,
    contact_info varchar(40) NOT NULL,
    city varchar(40) NOT NULL,
    comments varchar(200) NOT NULL,
    date_added date NOT NULL,
    PRIMARY KEY (guest_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  • 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-10T00:52:44+00:00Added an answer on June 10, 2026 at 12:52 am

    Take a look at your code. If you’re having an issue with a query, echo it to the screen. In your case (just by looking at your code), the query you pass ($statement) looks like this:

    SELECT lastname, firstname, contact_type, contact_info, city,
    comments, date_addedFROM u1585_Guestbook ORDER BY lastname

    In PHP, you can define a string over multiple lines in order to avoid such mistakes. Like so:

    <?php
    .
    .
    .
    $statement = "SELECT lastname, firstname, contact_type, contact_info, city, comments, date_added
        FROM u1585_Guestbook 
        ORDER BY lastname ";
    

    UPDATE:

    In response to your comments below, I would recommend using PDO to set up your query:

    //connect to DB
    $db = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
    
    // prepare your statement
    $query = $db->prepare("INSERT INTO u1585_guestbook(lastname, firstname, contact_type, contact_info, city, comments, date_added) VALUES (?, ?, ?, ?, ?, ?, ?)");
    $data = array($mylastname, $myfirstname, $mycontact_type, $mycontactinfo, $mycity, $mycomments, $mydate);
    
    // execute your statement
    $query->execute($data);
    

    Take a look at this overview to learn more about PDO. It’s pretty awesome.

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

Sidebar

Related Questions

I have retrieved the database details from a database to a php page. i
I'm making a php page to draw information from a mysql database, and before
I'm building a website to learn coding. I have a claim.php which is a
This is about RAW php coding. I have a page - config.php and there
I have a table in a PHP page. It is a invoice. So I
As I was coding a php page building a MySQL request according to GET
I am working on some form coding in PHP, and I have everything working
I see this problem on and off again in my PHP coding, and I've
So, I am beginning the process of coding a PHP application website, which will
Ive never heard of this before, and I have been coding in PHP for

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.