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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:04:16+00:00 2026-06-10T03:04:16+00:00

I am trying to add user info into a database from a user input

  • 0

I am trying to add user info into a database from a user input form. The data from the form is being recognized and if I do test print statements for the variables for all inputs the information is showing up. When it goes through the insert statement though, it is missing the first column data (lastname) and pushing all the other data into the wrong columns.

The lastname ends up in the firstname column, firstname ends up in contact type, contact type ends up in contact info, contact info ends up in city, comments don’t show up anywhere, and date added is correct.

I have added the local code that is most relevant, but if you need the common functions I could also add. There is also the table structure at the bottom.

THANKS!

    <html>
<head>
<title>Submitted Guestbook Info</title>
<link rel="stylesheet" type="text/css" href="css/king.css" />
</head>

<body>
<img src="images/KingLogo.jpg"><br>

<div id="guestlist">

<?php

include "king_common_functions.php";

//*******************************************************
//Variables for Guestbook Submissions
//*******************************************************

//*******************************************************
//Call Functions
//*******************************************************

setUserInfo();

?>

<?php

function setUserInfo()
{

//******************************************************
//Validate Input Fields, Define Variables
//******************************************************
$mycontact_type = $_POST['mycontact'];
$mycity = $_POST['city'];

    if (isset($_POST['mylastname']))
    {
        $mylastname = trim($_POST['mylastname']);
    } else {
        $mylastname ='';
    }

    if (isset($_POST['myfirstname']))
    {
        $myfirstname = trim($_POST['myfirstname']);
    } else {
        $myfirstname ='';
    }

    if (isset($_POST['mycontactinfo']))
    {
        $mycontactinfo = trim($_POST['mycontactinfo']);
    } else {
        $mycontactinfo ='';
    }

    if (isset($_POST['comments']))
    {
        $mycomments = trim($_POST['comments']);
    } else {
        $mycomments ='';
    }

    $rtnmsg = doGuestValidation($myfirstname, $mylastname, $mycontactinfo, $mycity);

        if ($rtnmsg == '')
        {
            $rtncode = insertData($db, $mylastname, $myfirstname, $mycontact_type, $mycontactinfo, $mycity, $mycomments);
        } else {
            $rtncode = '';
            print $rtnmsg;
            print '<br />Go <a href ="assignment_6_guest_calc.php">BACK</a> and try again!';
        }


}

function insertData($mylastname, $myfirstname, $mycontact_type, $mycontactinfo, $mycity, $mycomments)
{
    $mydate = date("Y-m-d");

    $db = connectDatabase();

    $statement = "insert into u1585_guestbook (lastname, firstname, contact_type, contact_info, city, comments, date_added)
    values ('".$mylastname."', '".$myfirstname."', '".$mycontact_type."', '".$mycontactinfo."', '".$mycity."', '".$mycomments."', '".$mydate."')";

    $result = mysql_query($statement);

    print "TEST: $mylastname"
                if ($result)
                {
                    print "<h4>Thank You! A representative will contact you soon.</h4>";
                    print "Information Submitted for: ".$myfirstname." ".$mylastname;
                    print "<br/><br/>Your name ".$mycontact_type. " is " .$mycontact_info;
                    print "<br/>and you are interested in living in ".$mycity;
                    print "<br/><br/>Our representative will review your comments below:";
                    print "<br/><br/><textarea name='comments' rows='7' cols='60' disabled='disabled' class='textdisabled'>";
                    print $mycomments;
                    print "</textarea>";
                } else {
                        $errno = mysql_errno($db);

                        if ($errno == '1062') {
                            echo "<br>User is already in Guestbook: <br />".$mylastname.", ".$myfirstname;
                        } else {
                            echo("<h4>MySQL No: ".mysql_errno($result)."</h4>");
                            echo("<h4>MySQL Error: ".mysql_error($result)."</h4>");
                            echo("<h4>SQL: ".$statement."</h4>");
                            echo("<h4>MySQL Affected Rows: ".mysql_affected_rows($result)."</h4>");
                        }
                        return 'NotAdded';
                    }
}

?>

</div>

</body>
</html>

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-10T03:04:18+00:00Added an answer on June 10, 2026 at 3:04 am

    Your call to the method insertData() is passing the parameters incorrectly:

    $rtncode = insertData($db, $mylastname, $myfirstname, $mycontact_type, $mycontactinfo, $mycity, $mycomments);
    ...
    function insertData($mylastname, $myfirstname, $mycontact_type, $mycontactinfo, $mycity, $mycomments) {
    

    You’re passing $db as the first argument, but the function’s first argument should be the last name. Simply update the call to remove $db and you should be good:

    $rtncode = insertData($mylastname, $myfirstname, $mycontact_type, $mycontactinfo, $mycity, $mycomments);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to add a new user to my database via a form i
I'm trying to add the distance from the user's position to a selected annotation's
I am trying to add a custom field to the user form in the
I'm trying to add text input's element to my array when user pressed enter
I'm trying to add input boxes based on a number provided by the user.
I'm trying to add data into an attribute of a core data entity. Contents
I'm trying to add a feature into my app that allows the user to
I was trying to add a User in my database using Java with Spring
Im trying to add a timer to my game so that the user knows
So I'm trying to add some ability to my project to allow user-defined properties

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.