0

I've recently trying to add data into a database, (New to php), I've looked over what other people has with this error but yet still I cannot see where I have gone wrong. The error is:

Column count doesn't match value count at row 1

Code:

$dbhost = 'localhost';
$dbuser = 'evocityi_admin';
$dbpass = 'password';
$database = 'evocityi_stocks';
$conn = mysql_connect($dbhost, $dbuser, $dbpass, $database);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}


    $Dtime = "30/04/16";
    $StockName = "FUMUKU";
    $FUMUKUPrice = 1000;
    $sql = "INSERT INTO stocks".
           "(Stock,Price, TimeD) ".
           "VALUES ".
           "('$StockName,$FUMUKUPrice, $DTime')";
    mysql_select_db('evocityi_stocks');
    $retval = mysql_query( $sql, $conn );
    if(! $retval )
    {
      die('Could not enter data: ' . mysql_error());
    }
    echo "Entered data successfully\n";
    mysql_close($conn);
    ?>

SQL Database: https://gyazo.com/e74a6b9e87c18d60855424dcae647cdf

2
  • 1
    $Dtime not equal to $DTime Commented Apr 30, 2016 at 11:10
  • You really shouldn`t use mysql_connect and other mysql functions in PHP anymore since they are removed in PHP 7.0, rather replace them with mysqli equivalent, see php.net/manual/en/book.mysqli.php Commented Apr 30, 2016 at 11:32

2 Answers 2

1

Change the column type for Stock and TimeD to varchar in your table definition. On the link you posted, they are both int.

Sign up to request clarification or add additional context in comments.

Comments

1

as suggested by @PaulB12345, change column type to varchar and there is error in quotes.

ideally your query should be like (see quotes after values)

$sql = "INSERT INTO stocks".
           "(Stock,Price, TimeD) ".
           "VALUES ".
           "('$StockName','$FUMUKUPrice', '$DTime')";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.