Jump to content

HELP!!!!!! Unknown column 'posted' in 'order clause'


flforlife

Recommended Posts

Ok I don't know if yall can handle this one but this is the deal! Again i'm a php/mysql newbie.

 

 

I keep getting an error message... if you don't see the table average_game_score ignore that this error will do it for the others also

 

Could not successfully run query (SELECT id, agsone, agstwo, agsthree, agsfour FROM average_game_score ORDER BY posted DESC LIMIT 0, 10 ) from DB: Unknown column 'posted' in 'order clause'

 

this is the database setup.... just a snippet theres more

 

 

CREATE TABLE age (

id INT NOT NULL AUTO_INCREMENT,

ageone VARCHAR(128) DEFAULT NULL,

agetwo VARCHAR(128) DEFAULT NULL,

agethree VARCHAR(128) DEFAULT NULL,

agefour VARCHAR(128) DEFAULT NULL,

PRIMARY KEY(id)

);

CREATE TABLE runs_scored (

id INT NOT NULL AUTO_INCREMENT,

rsone VARCHAR(128) DEFAULT NULL,

rstwo VARCHAR(128) DEFAULT NULL,

rsthree VARCHAR(128) DEFAULT NULL,

rsfour VARCHAR(128) DEFAULT NULL,

PRIMARY KEY(id)

);

 

 

This is the php thats inserting data

 

$sql = "INSERT INTO age ";

$sql .= "(ageone, agetwo, agethree, agefour) ";

$sql .= "VALUES('$ageone', NOW(), '$agetwo', '$agethree', '$agefour')";

 

$sql = "INSERT INTO runs_scored ";

$sql .= "(rsone, rstwo, rsthree, rsfour) ";

$sql .= "VALUES('$rsone', NOW(), '$rstwo', '$rsthree', '$rsfour')";

 

 

 

 

 

this is a snippit of the html inserts

<tr>

<td><input name="ageone" type="text" id="teamone" /></td>

<td><input name="agetwo" type="text" id="teamtwo" /></td>

<td><input name="agethree" type="text" id="teamthree" /></td>

<td><input name="agefour" type="text" id="teamfour" /></td>

 

</tr>

 

 

<tr>

<td><input name="rsone" type="text" id="rsone" /></td>

<td><input name="rstwo" type="text" id="rstwo" /></td>

<td><input name="rsthree" type="text" id="rsthree" /></td>

<td><input name="rsfour" type="text" id="rsfour" /></td>

</tr>

 

now I know something aint right here so do you think that I can create more than one table this way. It gotta be the tables man THE TABLES MAN!!!!!!!!!! help......

Link to comment
Share on other sites

You show us table definitions for age and runs_scored but not the one you're getting the error on which is average_game_score. You say to ignore that because it happens to the others too.

 

The error is what it says, you don't have a column named "posted" defined in your "average_game_score" table or the others you have listed here either.

 

Create a column called "posted"!

Link to comment
Share on other sites

Ok i did that and I get this error what i did is test the query by insert a conditional

 

this is the error i get now

 

Could not successfully run query (INSERT INTO average_game_score (agsone, agstwo, agsthree, agsfour) VALUES('t', NOW(), 'f', 't', 't')) from DB: Column count doesn't match value count at row 1

 

do i add the column posted to all the tables?

Link to comment
Share on other sites

Column count doesn't match value count at row 1 - explains all.

 

Look at your query - you're trying to put FOUR values into FIVE columns.

I think he meant to say FIVE values into FOUR columns.

 

 

INSERT INTO average_game_score (agsone, posted, agstwo, agsthree, agsfour) VALUES('t', NOW(), 'f', 't', 't')

Link to comment
Share on other sites

i took out posted and the NOW()  the error go away and now just get

 

Could not successfully run query (INSERT INTO average_game_score (agsone, agstwo, agsthree, agsfour) VALUES('t', 'f', 't', 't')) from DB:

 

I took out the NOW() function here is the snippet of that...

 

 

        $sql = "INSERT INTO runs_scored ";

$sql .= "(rsone, rstwo, rsthree, rsfour) ";

$sql .= "VALUES('$rsone', '$rstwo', '$rsthree', '$rsfour')";

 

$sql = "INSERT INTO runs_allowed ";

$sql .= "(raone, ratwo, rathree, rafour) ";

$sql .= "VALUES('$raone', '$ratwo', '$rathree', '$rafour')";

 

$sql = "INSERT INTO average_game_score ";

$sql .= "(agsone, agstwo, agsthree, agsfour) ";

$sql .= "VALUES('$agsone', '$agstwo', '$agsthree', '$agsfour')";

 

 

do you think its the id has an effect here is the sql file again....

 

 

CREATE TABLE place (

  id INT NOT NULL AUTO_INCREMENT,

  placeone VARCHAR(128) DEFAULT NULL,

  placetwo VARCHAR(128) DEFAULT NULL,

  placethree VARCHAR(128) DEFAULT NULL,

  placefour VARCHAR(128) DEFAULT NULL,

  PRIMARY KEY(id)

);

CREATE TABLE team (

  id INT NOT NULL AUTO_INCREMENT,

  teamone VARCHAR(128) DEFAULT NULL,

  teamtwo VARCHAR(128) DEFAULT NULL,

  teamthree VARCHAR(128) DEFAULT NULL,

  teamfour VARCHAR(128) DEFAULT NULL,

  PRIMARY KEY(id)

);

CREATE TABLE wl (

  id INT NOT NULL AUTO_INCREMENT,

  wlone VARCHAR(128) DEFAULT NULL,

  wltwo VARCHAR(128) DEFAULT NULL,

  wlthree VARCHAR(128) DEFAULT NULL,

  wlfour VARCHAR(128) DEFAULT NULL,

  PRIMARY KEY(id)

);

CREATE TABLE gb (

  id INT NOT NULL AUTO_INCREMENT,

  gbone VARCHAR(128) DEFAULT NULL,

  gbtwo VARCHAR(128) DEFAULT NULL,

  gbthree VARCHAR(128) DEFAULT NULL,

  gbfour VARCHAR(128) DEFAULT NULL,

  PRIMARY KEY(id)

);

CREATE TABLE age (

  id INT NOT NULL AUTO_INCREMENT,

  ageone VARCHAR(128) DEFAULT NULL,

  agetwo VARCHAR(128) DEFAULT NULL,

  agethree VARCHAR(128) DEFAULT NULL,

  agefour VARCHAR(128) DEFAULT NULL,

  PRIMARY KEY(id)

);

CREATE TABLE runs_scored (

  id INT NOT NULL AUTO_INCREMENT,

  rsone VARCHAR(128) DEFAULT NULL,

  rstwo VARCHAR(128) DEFAULT NULL,

  rsthree VARCHAR(128) DEFAULT NULL,

  rsfour VARCHAR(128) DEFAULT NULL,

  PRIMARY KEY(id)

);

CREATE TABLE runs_allowed (

  id INT NOT NULL AUTO_INCREMENT,

  raone VARCHAR(128) DEFAULT NULL,

  ratwo VARCHAR(128) DEFAULT NULL,

  rathree VARCHAR(128) DEFAULT NULL,

  rafour VARCHAR(128) DEFAULT NULL,

  PRIMARY KEY(id)

);

CREATE TABLE average_game_score (

  id INT NOT NULL AUTO_INCREMENT,

  agsone VARCHAR(128) DEFAULT NULL,

  agstwo VARCHAR(128) DEFAULT NULL,

  agsthree VARCHAR(128) DEFAULT NULL,

  agsfour VARCHAR(128) DEFAULT NULL,

  PRIMARY KEY(id)

);

 

 

 

CREATE TABLE users (

id int(4) NOT NULL auto_increment,

username varchar(65) NOT NULL default '',

password varchar(65) NOT NULL default '',

PRIMARY KEY (id)

) TYPE=MyISAM AUTO_INCREMENT=2 ;

 

INSERT INTO users (username, password)

VALUES ('admin', '1234')

 

 

 

Link to comment
Share on other sites

Could not successfully run query (INSERT INTO average_game_score (agsone, agstwo, agsthree, agsfour) VALUES('t', 'f', 't', 't')) from DB:

 

That looks like a 'custom' error message that really would have been better if it hadn't been customised thus. At least then you would know WHAT the error was.  Please show us the few lines that include a few lines before that particular query and a few beyond.

Link to comment
Share on other sites

ok here is the run down

 

I add values using these tables

 

<form name="form1" id="form1" method="post" action="addsb.php">

<table  border="1">

 

<tr>

<!--table place field placeone -->

<td>PLACE</td

</tr>

<tr>

<td>Teamone</td>

<td>Teamtwo</td>

<td>Teamthree</td>

<td>Teamfour</td>

</tr>

 

<tr>

<td><input name="placeone" type="text" id="placeone" /></td>

<td><input name="placetwo" type="text" id="placetwo" /></td>

<td><input name="placethree" type="text" id="placethree" /></td>

<td><input name="placefour" type="text" id="placefour" /></td>

</tr>

 

<tr>

<td>TEAM</td

</tr>

<tr>

<td>Teamone</td>

<td>Teamtwo</td>

<td>Teamthree</td>

<td>Teamfour</td>

</tr>

<tr>

<td><input name="teamone" type="text" id="teamone" /></td>

<td><input name="teamtwo" type="text" id="teamtwo" /></td>

<td><input name="teamthree" type="text" id="teamthree" /></td>

<td><input name="teamfour" type="text" id="teamfour" /></td>

</tr>

 

 

 

 

 

 

</table>

<input type="submit" name="Submit" value="Submit" />

<input type="reset" value="Reset" class="button" />

</form>

 

 

It goes to php code....

 

 

<?php

 

//add the scores to database

 

$hostname = 'localhost';

$username = 'root';

$password = ''; //add later

$database = 'scoreboard';

 

$mysql = mysql_connect($hostname, $username, $password);

mysql_select_db($database);

 

if(count($_POST) > 0) {

$placeone = $_POST['placeone'];

$placetwo = $_POST['placetwo'];

$placethree = $_POST['placethree'];

$placefour = $_POST['placefour'];

 

$teamone = $_POST['teamone'];

$teamtwo = $_POST['teamtwo'];

$teamthree = $_POST['teamthree'];

$teamfour = $_POST['teamfour'];

 

 

 

$sql = "INSERT INTO place ";

$sql .= "(placeone, placetwo, placethree, placefour) ";

$sql .= "VALUES('$placeone', NOW(), '$placetwo', '$placethree', '$placefour')";

 

$sql = "INSERT INTO team ";

$sql .= "(teamone, teamtwo, teamthree, teamfour) ";

$sql .= "VALUES('$teamone', NOW(), '$teamtwo', '$teamthree', '$teamfour')";

 

 

 

 

mysql_query($sql);

if (!$result) {

    echo "Could not successfully run query ($sql) from DB: " . mysql_error();

    exit;

}

}

 

?>

 

Then I get error from this php file

 

Could not successfully run query (INSERT INTO team (teamone, teamtwo, teamthree, teamfour) VALUES('t', NOW(), 't', 't', 't')) from DB: Column count doesn't match value count at row 1

 

 

This is the php that suppose to fetch the query's and output it.

 

<?php

 

//this is the scores page

//mscores displays the scores in tables from the addsb.php file

 

$hostname = 'localhost';

$username = 'root';  //later change to root

$password = ''; //no password yet

$database = 'scoreboard';

 

 

$mysql = mysql_connect($hostname, $username, $password)

  or die("Could not connect to database: ".mysql_error());

mysql_select_db($database)

  or die("Could not select DB: ".mysql_error());

 

/*

$mysql = mysql_connect($hostname, $username, $password);

mysql_select_db($database);

*/

 

$sql = "SELECT id, placeone, placetwo, placethree, placefour ";

$sql .= "FROM place ";

$sql .= "ORDER BY posted DESC ";

$sql .= "LIMIT 0, 10 ";

 

$sql = "SELECT id, teamone, teamtwo, teamthree, teamfour ";

$sql .= "FROM team ";

$sql .= "ORDER BY posted DESC ";

$sql .= "LIMIT 0, 10 ";

 

 

 

 

$result = mysql_query($sql);

 

 

if (!$result) {

    echo "Could not successfully run query ($sql) from DB: " . mysql_error();

    exit;

}

 

while($row = mysql_fetch_assoc($result)) {

 

 

$placeone = $row['placeone'];

$placetwo = $row['placetwo'];

$placethree = $row['placethree'];

$placefour = $row['placefour'];

 

$teamone = $row['teamone'];

$teamtwo = $row['teamtwo'];

$teamthree = $row['teamthree'];

$teamfour = $row['teamfour'];

 

 

 

 

 

echo "<td>$placeone</td>";

echo "<td>$placetwo</td>";

echo "<td>$placethree</td>";

echo "<td>$placefour</td>";

 

echo "<td>$teamone</td>";

echo "<td>$teamtwo</td>";

echo "<td>$teamthree</td>";

echo "<td>$teamfour</td>";

 

 

 

}

 

 

 

?>

Link to comment
Share on other sites

  $sql = "INSERT INTO team ";

  $sql .= "(teamone, teamtwo, teamthree, teamfour) ";

  $sql .= "VALUES('$teamone', NOW(), '$teamtwo', '$teamthree', '$teamfour')";

 

four fields and five values - that's the problem. You either need to ADD a field to accept the value of NOW() or more likely, remove NOW(), from the VALUES statement

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.