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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:02:50+00:00 2026-05-16T15:02:50+00:00

Receiving Error message when performing Update Statement, but database is being updated. Error: You

  • 0

Receiving Error message when performing Update Statement, but database is being updated.

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1

Issue with function update():

function update($pUInput) {

    $sql = mysql_query("UPDATE tblStudents 
                        SET first_name = '$pUInput[1]', last_name = '$pUInput[2]', 
                                  major = '$pUInput[3]', 
                                  year = '$pUInput[4]'
                        WHERE id = '$pUInput[0]'");

    if (!mysql_query($sql))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record update";

}

Entire PHP Code:

//Call function mainline
mainline();

// Declare the function mainline
function mainline() {

    $uInput = getUserInput();

    $connectDb = openConnect(); // Open Database Connection
    selectDb($connectDb); // Select Database
    doAction($uInput);
    //display();
    //closeConnect();

}

//Declare function getUserInput ------------------------------------------------------------------------------------
function getUserInput() {

    echo "In the function getUserInput()" . "<br/>";

    // Variables of User Input
    $idnum = $_POST["idnum"];              // id (NOTE: auto increments in database)
    $fname = $_POST["fname"];             // first name
    $lname = $_POST["lname"];            // last name
    $major = $_POST["major"];           // major
    $year = $_POST["year"];            // year
    $action = $_POST["action"];       // action (select, insert, update, delete)

    $userInput = array($idnum, $fname, $lname, $major, $year, $action);

    return $userInput;
}

// function doAction ----------------------------------------------------------------------------------------------
function doAction($pUserInput) {
    echo "In function doAction()" . "<br/>";

    if ($pUserInput[5] == "select") {
        //IDorLastName();   
        selectById();


    } elseif ($pUserInput[5] == "insert") {


        //checkStudentFields();
        insert($pUserInput);

        //echo "I need to insert!";
    } elseif ($pUserInput[5] == "update") {
        //IDorLastName();       
        update($pUserInput);    
        //echo "I need to insert!";


    } elseif ($pUserInput[5] == "delete") {
        //IDorLastName();       
        deleteById($pUserInput);    
        //echo "I need to insert!";
    }

}

/*
function IDorLastName() {
    if (!empty($pUserInput[0]) || !empty($pUserInput[2])) {
                checkId();
                } else {
            echo "Please enter ID field or Last Name field";
            }
        }
}
*/
// function checkId -----------------------------------------------------------------------------------------------
/*
function checkId() {
    if (!empty($pUserInput[0])) {
        selectById();
        } else {
        selectByLastName();
    }
}*/

/*
function checkStudentFields() {
 // check if first name, last name, major and year exists
}*/

// Create a database connection ------------------------------------------------------------------------------------
function openConnect() {
    $connection = mysql_connect("localhost", "root_user", "password");
        echo "Opened Connection!" . "<br/>";    
    if(!$connection) {
        die("Database connection failed: " . mysql_error());
    }
    return $connection;
}

// Select a database to ------------------------------------------------------------------------------------------- 
function selectDb($pConnectDb) {
    $dbSelect = mysql_select_db("School", $pConnectDb);
    if(!$dbSelect) {
        die("Database selection failed: " . mysql_error());
    } else {
    echo "You are in the School database! <br/>";   
    }

}

// Close database connection ------------------------------------------------------------------------------------
function closeConnect() {
    mysql_close($connection);
}

// function selectById ---------------------------------------------------------------------------------------------
function selectById($pUInput) {
    $sql = mysql_query("SELECT * FROM tblStudents 
                        WHERE id='$pUInput[0]'");
    if (!$row = mysql_fetch_assoc($sql))
          {
          die('Error: ' . mysql_error());
          }       
        echo "selected" . "<br/>";
        //echo $pUInput[0];

}

// function selectByLastName ---------------------------------------------------------------------------------------------
function selectByLastName($pUInput) {
    $sql = mysql_query("SELECT * FROM tblStudents 
                        WHERE last_name='$pUInput[2]'");
    if (!$row = mysql_fetch_array($sql))
          {
          die('Error: ' . mysql_error());
          }       
        echo "selected" . "<br/>";
        echo $pUInput[2];

}

// function insert -------------------------------------------------------------------------------------------------
function insert($pUInput) {     
    $sql="INSERT INTO tblStudents (first_name, last_name, major, year)
          VALUES
         ('$pUInput[1]','$pUInput[2]','$pUInput[3]', '$pUInput[4]')";

        if (!mysql_query($sql))
          {
          die('Error: ' . mysql_error());
          }
        echo "1 record added";
}

// function update -------------------------------------------------------------------------------------------------
function update($pUInput) {
    // call select();
    $sql = mysql_query("UPDATE tblStudents 
                        SET first_name = '$pUInput[1]', last_name = '$pUInput[2]', 
                                  major = '$pUInput[3]', 
                                  year = '$pUInput[4]'
                        WHERE id = '$pUInput[0]'");

    if (!mysql_query($sql))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record update";

}

// function delete -------------------------------------------------------------------------------------------------
function deleteById($pUInput) {
        // call select();
        $sql="DELETE FROM tblStudents WHERE id='$pUInput[0]'";
        $result=mysql_query($sql);

        if($result){
            echo "Deleted Successfully";
        }else {
            echo "Error";
        }       
}

/*

function display() { 
}
*/



?> 

SQL Syntax:

CREATE TABLE `tblStudents` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(30) NOT NULL,
  `last_name` varchar(50) NOT NULL,
  `major` varchar(40) NOT NULL,
  `year` date NOT NULL,
  PRIMARY KEY (`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-05-16T15:02:51+00:00Added an answer on May 16, 2026 at 3:02 pm

    Try this:

    $sql = "UPDATE tblStudents 
            SET first_name = '{$pUInput[1]}',
                last_name = '{$pUInput[2]}', 
                major = '{$pUInput[3]}', 
                year = '{$pUInput[4]}'
            WHERE id = '{$pUInput[0]}'";
    
    if(!mysql_query($sql))
    {
        die('Error: ' . mysql_error());
    }
    echo "1 record update";
    

    And change this:

    // Variables of User Input
    $idnum = $_POST["idnum"];
    $fname = $_POST["fname"];
    $lname = $_POST["lname"];
    $major = $_POST["major"];
    $year = $_POST["year"];
    $action = $_POST["action"];
    

    To:

    // Variables of User Input
    $idnum = mysql_real_escape_string($_POST["idnum"]);
    $fname = mysql_real_escape_string($_POST["fname"]);
    $lname = mysql_real_escape_string($_POST["lname"]);
    $major = mysql_real_escape_string($_POST["major"]);
    $year = mysql_real_escape_string($_POST["year"]);
    $action = mysql_real_escape_string($_POST["action"]);
    

    You might want to read up on sql injection.

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

Sidebar

Ask A Question

Stats

  • Questions 535k
  • Answers 534k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I ended going with a custom button on this like… May 17, 2026 at 12:57 am
  • Editorial Team
    Editorial Team added an answer I worked on a similar problem a year ago. I… May 17, 2026 at 12:57 am
  • Editorial Team
    Editorial Team added an answer Just for the future, your self.view frame takes into account… May 17, 2026 at 12:57 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm using phoenix::bind and receiving this error message: error C2039: 'bind' : is not
I'm using mysql_real_escape_string to escape my content but I am receiving an error in
receiving error: PHP Notice: Undefined index: mode in /web/ee_web/include/form-modal.php on line 51 line 51
As a follow-up to cannot-bind-to-address-after-socket-program-crashes , I was receiving this error after my program
I am receiving an error that says The application was unable to start correctly
I'm trying to export the results of a SQL statement via the SQL Server
I am receiving this error: The ViewData item that has the key 'DepartmentId' is
When using(attempting) the SqlFileStream object, I am receiving an error System.ComponentModel.Win32Exception: Logon failure: unknown
I have been receiving errors when trying to save and run this Python 3.1
I am trying to crop an image. I have found multiple ways to do

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.