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

  • Home
  • SEARCH
  • 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 7539085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:17:26+00:00 2026-05-30T07:17:26+00:00

I have a form for adding new students to a Database and a php

  • 0

I have a form for adding new students to a Database and a php script called NewStudentAddv2.php

when submitting the form i am met with

Parse error: syntax error, unexpected T_STRING, expecting ‘)’ in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11026991/public_html/NewStudentAddv2.php on line 40

NewStudentAddv2.php

<?php
require_once( "myfunctions.php" );
try {
    /**
     * ** connect using the getConnection function written in myfunctions.php **
     */
    $db = getConnection();

        // ********************************
        // *** SAVE THE STUDENT DETAILS ***
        // ********************************

        echo "<h2>New Student</h2>\n";

        $forename = $_POST['forename'];
        $surname = $_POST['surname'];
        $studytypeID = $_POST['studytypeID'];
        $startyear = $_POST['startyear'];

        // Determine the first character for a new student code.

        $yrCodes = array('07' => 'S', '08' => 'T', '09' => 'V', '10' => 'W);
        $yr = substr($startyear, 3, 2);     // Extract the last 2 digits from the year.
        $code = $yrCodes[$yr];      // Get the corresponding letter from the array.
        $today = getdate();             // Get the current date (returns an associated array).

        // Extract the day, month and year from the date and pad each string
        // to 2 characters (leading zero).

        $day = str_pad($today['mday'], 2, "0", STR_PAD_LEFT); //SYNTAX ERROR
        $mth = str_pad($today['mon'], 2, "0", STR_PAD_LEFT);
        $year = substr($today['year'], 2,2);

        $code .= $day.$mth.$year;   // Create a new student code.


        // Formulate a string containing the SQL INSERT statement.
        // NOTE: Only the values corresponding to character fields in the
        // database table are delimited with ' '. Values for numeric
        //fields do not need to be delimited.

        $sql = "INSERT INTO student (studentCode, forename, surname, studytypeID, startyear) VALUES 
        (:code, :forename, :surname, :studytypeID, :startyear)";

        $stmt = $db->prepare($sql);
        $stmt->bindParam(':code', $code, PDO::PARAM_STR);
        $stmt->bindParam(':forename', $forename, PDO::PARAM_STR );
        $stmt->bindParam(':surname', $surname, PDO::PARAM_STR );
        $stmt->bindParam(':studytypeID', $studytypeID);
        $stmt->bindParam(':startyear', $startyear);

        // Parse the SQL statement.
        $stmt->execute();
        }
        catch( PDOException $e ) {
            // Handle an error, if any.
            echo "<p><strong>Error:</strong> The details for student '$forename $surname' \n";
            echo "have not be saved in the database. Please consult the system administrator \n";
            echo "with the error message '".$e->getMessage()."'.</p>\n";  
        }
                // Display 'success' message to the user.
        echo "<p>The details for student '$forename $surname: $code, $studytypeID, $startyear' have successfully been saved \n";
        echo "to the database.</p>\n";

        echo "<p><a href=\"NewStudentForm.php\">Enter a new student</a>\n</p>";
    ?>

Line 40

$day = str_pad($today['mday'], 2, "0", STR_PAD_LEFT); //SYNTAX ERROR

I am new to PHP and cant seem to see the error, any help would be appreciated.

  • 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-30T07:17:27+00:00Added an answer on May 30, 2026 at 7:17 am
    $yrCodes = array('07' => 'S', '08' => 'T', '09' => 'V', '10' => 'W); 
    

    missing quote

    $yrCodes = array('07' => 'S', '08' => 'T', '09' => 'V', '10' => 'W'); 
    

    PHP thinks that the quoted string that begins with “‘W” spans multiple lines, and ends at the closing quote of “$today[‘” in line 40, making mday the next code token…. as this ais not a valid code token but a string, you get the unexpected T_STRING error

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

Sidebar

Related Questions

I have a TreeView control on a form. I am dynamically adding new TreeNodes
I have created one form that extends zend form. For Adding New Record it
I have an ASP.NET MVC form for adding a module to a site. The
I have created a form that is used for both adding and editing a
I have an ASP.NET web form which I am adding a variable number User
having a bit of trouble adding some data to a database. I have the
Let's say I have a form for adding/editing products (with field 'user' being a
In my user's data edit form I have a boolean field, for adding/removing email
I have an MVC form for adding a simple entity. I am using TextBoxFor(model
I'm working with someone else's code, and I'm adding a new form So, I've

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.