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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:56:30+00:00 2026-06-09T23:56:30+00:00

I have a database and this includes three tables as follows: -Player -Player Previous

  • 0

I have a database and this includes three tables as follows:

-Player

-Player Previous Clubs

-Previous Clubs

The ‘Player Previous Clubs’ table is a look up table as there is a many-to-many relationship between player and previous clubs.

Now I have the below code which successfully populates the ‘player’ table and ‘previous clubs table’ from a single form.

if (isset($_GET['addform']))
{
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';

//PLAYER TABLE INSERT
try
{
    $sql = 'INSERT INTO player SET
            name = :name,
            age = :age,
            position = :position,
            height = :height,
            weight = :weight,
            satscore = :satscore,
            gpa = :gpa';
    $s = $pdo->prepare($sql);
    $s->bindValue(':name', $_POST['name']);
    $s->bindValue(':age', $_POST['age']);
    $s->bindValue(':position', $_POST['position']);
    $s->bindValue(':height', $_POST['height']);
    $s->bindValue(':weight', $_POST['weight']);
    $s->bindValue(':satscore', $_POST['satscore']);
    $s->bindValue(':gpa', $_POST['gpa']);
    $s->execute();
}
catch (PDOException $e)
{
    $error = 'Error adding submitted player profile.' . $e->getMessage();
    include 'error.html.php';
    exit();
}

//PREVIOUS CLUBS TABLE INSERT
try
{
    $sql = 'INSERT INTO previousclubs SET
            name = :previousclubs';
    $s = $pdo->prepare($sql);
    $s->bindValue(':previousclubs', $_POST['previousclubs']);
    $s->execute();
}
catch (PDOException $e)
{
    $error = 'Error adding previous club.' . $e->getMessage();
    include 'error.html.php';
    exit();
}

header('Location: .');
exit();
}

I am unsure of how to populate the look up table (player previous clubs) as the values that it requires are not passed in via the form, they are generated via the auto increment functionality.

The table consists of two fields. One is the primary key value of the player table and the other is the primary key of the previous clubs table.

Together these two fields form a joint primary key.

Any help on how to do this is greatly appreciated.

Thanks

UPDATE

Okay I now have the below code:

if (isset($_GET['addform']))
{
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';

//PLAYER TABLE INSERT
try
{
    $sql = 'INSERT INTO player SET
            name = :name,
            age = :age,
            position = :position,
            height = :height,
            weight = :weight,
            satscore = :satscore,
            gpa = :gpa';
    $s = $pdo->prepare($sql);
    $s->bindValue(':name', $_POST['name']);
    $s->bindValue(':age', $_POST['age']);
    $s->bindValue(':position', $_POST['position']);
    $s->bindValue(':height', $_POST['height']);
    $s->bindValue(':weight', $_POST['weight']);
    $s->bindValue(':satscore', $_POST['satscore']);
    $s->bindValue(':gpa', $_POST['gpa']);
    $s->execute();

    $one = $pdo->lastInsertId();
}
catch (PDOException $e)
{
    $error = 'Error adding submitted player profile.' . $e->getMessage();
    include 'error.html.php';
    exit();
}

//PREVIOUS CLUBS TABLE INSERT
try
{
    $sql = 'INSERT INTO previousclubs SET
            name = :previousclubs';
    $s = $pdo->prepare($sql);
    $s->bindValue(':previousclubs', $_POST['previousclubs']);
    $s->execute();

    $two = $pdo->lastInsertId();
}
catch (PDOException $e)
{
    $error = 'Error adding previous club.' . $e->getMessage();
    include 'error.html.php';
    exit();
}

//PLAYER PREVIOUS CLUB INSERT
try
{
    $sql = "INSERT INTO playerpreviousclubs SET
            playerid = '$one',
            previousclubid = '$two'";
    $s = $pdo->prepare($sql);
    $s->bindValue(':playerid', $_POST['playerid']);
    $s->bindValue(':previousclubid', $_POST['previousclubid']);
    $s->execute();
}
catch (PDOException $e)
{
    $error = 'Error adding player previous club look up data.' . $e->getMessage();
    include 'error.html.php';
    exit();
}

//LINKS TABLE INSERT
try
{
    $sql = "INSERT INTO links SET
            link = :link,
            playerid = '$one'";
    $s = $pdo->prepare($sql);
    $s->bindValue(':link', $_POST['link']);
    $s->bindValue(':playerid', $_POST['playerid']);
    $s->execute();
}
catch (PDOException $e)
{
    $error = 'Error adding link for player.' . $e->getMessage();
    include 'error.html.php';
    exit();
}

header('Location: .');
exit();
}

This gives me the following errors:

Notice: Undefined index: playerid in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\players\index.php on line 84

Notice: Undefined index: previousclubid in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\players\index.php on line 85

Notice: Undefined index: playerid in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\connect\players\index.php on line 103

Error adding link for player.SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

If I remove all of the code under ‘//LINKS TABLE INSERT’ then it works so I assume the problem is here but I need this table to store the $one value also.

Any ideas?

  • 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-09T23:56:31+00:00Added an answer on June 9, 2026 at 11:56 pm

    The ID generated for the inserted player and club rows are available in $pdo->lastInsertId() after you execute each of those queries. So after each execute(), store the inserted ID in a variable to use in the later query.

    http://php.net/manual/en/pdo.lastinsertid.php

    http://dev.mysql.com/doc/refman/5.5/en/information-functions.html#function_last-insert-id

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

Sidebar

Related Questions

I have a database that has two tables, these tables look like this codes
My Database contains three tables: PermissionCategories, Permissions, and Users. There is a many to
I have this database structure, SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO; CREATE TABLE IF NOT EXISTS `announces` (
i have database table like this +-------+--------------+----------+ | id | ip | date |
In my database, assume we have a table defined as follows: CREATE TABLE [Chemical](
I have a database containing three tables: practices - 8 fields patients - 47
I have a database schema that includes the following tables: People Organisations RelationshipTypes What
I have the following three tables in a MySQL database in order to give
I have set up Sphinx to index three tables in a MySQL database, each
I have a SQL Server 2008 database. This database has a table called Product,

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.