Drezard Posted August 28, 2006 Share Posted August 28, 2006 Hello, I get this error: [QUOTE]Error in query: INSERT INTO users (name, email1, email2, daytime, nighttime, mobile, streetnum, streetname, suburb, state, postcode, askprice, bedrooms, bathrooms) VALUES ('Daniel', 'ashis', 'hioahiodf', '12412', '1345145', '15151515', '15123', 'suburb', 'state', 'postcode', 'askprice', 'bedrooms', 'bathrooms'). Column count doesn't match value count at row 1 [/QUOTE]When i try and execture this code: (I cant work out whats wrong)[CODE]<html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><?php if (!isset($_POST['submit'])) { // if the form has not been submitted before ?><form action="<?=$_SERVER['PHP_SELF']?>" method="post"> Name(s): <input type="text" name="name"> <br> Email: <input type="text" name="email1"> @<input type="text" name="email2"> Daytime Phone Number:<input type="text" name="daytime"> Nighttime Phone Number:<input type="text" name="nighttime"> Mobile Number:<input type="text" name="mobile"> Street Number:<input type="text" name="streetnum"> <br> Street Name: <input type="text" name="streetname"><br> Suburb: <input type="text" name="suburb"><br> State: <input type="text" name="state"> Postcode: <input type="text" name="postcode"> Asking Price: <input type="text" name="askprice"> Bedrooms: <input type="text" name="bedrooms"> Bathrooms: <input type="text" name="bathrooms"> <input type="submit" name="submit"></form> <?php } else {// set database server access variables:$host = "localhost";$user = "Drezard";$pass = "250291";$db = "sellyourownhome";// open connection$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");// select databasemysql_select_db($db) or die ("Unable to select database!"); // Start a connection to the MySQL Database $name = empty($_POST['name']) ? die ("Please Enter Your Name") : mysql_escape_string($_POST['name']); $email1 = empty($_POST['email1']) ? die ("Please Enter Your Email Address") : mysql_escape_string($_POST['email1']); $email2 = empty($_POST['email2']) ? die ("Please Enter Your Email Address") : mysql_escape_string($_POST['email2']); $daytime = empty($_POST['daytime']) ? die ("Please Enter Your Daytime Phone Number") : mysql_escape_string($_POST['daytime']); $nighttime = empty($_POST['nighttime']) ? die ("Please Enter Your Nighttime Phone Number") : mysql_escape_string($_POST['nighttime']); $mobile = empty($_POST['mobile']) ? die ("Please Enter Your Mobile Number") : mysql_escape_string($_POST['mobile']); $streetnum = empty($_POST['streetnum']) ? die ("Please Enter Your Streetnumber") : mysql_escape_string($_POST['streetnum']); $streetname = empty($_POST['streetname']) ? die ("Please Enter Your Streetname") : mysql_escape_string($_POST['streetname']); $suburb = empty($_POST['suburb']) ? die ("Please Enter Your Suburb") : mysql_escape_string($_POST['suburb']); $state = empty($_POST['state']) ? die ("Please Enter Your State") : mysql_escape_string($_POST['state']); $postcode = empty($_POST['postcode']) ? die ("Please Enter Your Postcode") : mysql_escape_string($_POST['postcode']); $askprice = empty($_POST['askprice']) ? die ("Please Enter Your Asking Price") : mysql_escape_string($_POST['askprice']); $bedrooms = empty($_POST['bedrooms']) ? die ("Please Enter How Many Bedrooms Your House Has") : mysql_escape_string($_POST['bedrooms']); $bathrooms = empty($_POST['bathrooms']) ? die ("Please Enter How Many Bathrooms Your House Has") : mysql_escape_string($_POST['bathrooms']); /* The above code is to check whether the user has or has not filled in all of the form. This means the user is forced to fill out the wholeform instead of just half of it. This also puts all of the information from the form into Variables so we can use them later. This code alsoemptys all of the posts, so that it frees up memory so we can do other things faster. */ if(!empty($_POST)){ // This code checks to see if the form has been emptied. $query = "INSERT INTO users (name, email1, email2, daytime, nighttime, mobile, streetnum, streetname, suburb, state, postcode, askprice, bedrooms, bathrooms) VALUES ('$name', '$email1', '$email2', '$daytime', '$nighttime', '$mobile', '$streetnum', 'suburb', 'state', 'postcode', 'askprice', 'bedrooms', 'bathrooms')";/* This is the query, this is what we are asking the MySQL database to do. This specific query asks the database to add the Variables we tookout of that form into the database. So we can later use those variables in different scripts. We can also use them to store user information suchas: how much money a user has. */ $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); /* This code above executes the query. */ echo "Account Created"; // This is the message the user gets if the process completed and their account was sucess fully added.mysql_close($connection);/* Finally we close the MySQL connection that we opened using Connect.php. This is the end of the hard bit of the script. Below is the tying upof loss ends. The loss ends of else { and if { statements. */}}?></body></html>[/CODE]Im kinda newbie and help would be very very appreciated.Thanks, Daniel Link to comment Share on other sites More sharing options...
superhoops Posted August 28, 2006 Share Posted August 28, 2006 I also get the error Column count doesn't match value count at row 1. Link to comment Share on other sites More sharing options...
Satria Ox41464b Posted August 28, 2006 Share Posted August 28, 2006 [b]Column count doesn't match value count[/b]INSERT INTO users [i]//this section is COLUMN count[/i](name, email1, email2, daytime, nighttime, mobile, streetnum, streetname, suburb, state, postcode, askprice, bedrooms, bathrooms) [i]//total 14 column[/i]VALUES [i]//this section is VALUE count[/i]('Daniel', 'ashis', 'hioahiodf', '12412', '1345145', '15151515', '15123', 'suburb', 'state', 'postcode', 'askprice', 'bedrooms', 'bathrooms')[i]//total 13 column[/i] Link to comment Share on other sites More sharing options...
superhoops Posted August 28, 2006 Share Posted August 28, 2006 This is part of the code of my page:$sql="INSERT INTO Market (Player, Price, Type, Position, Age, Ka, Ta, Pa, Sa)VALUES ('$_POST[Player]', '$_POST[Price]', '$_POST[Type]' '$_POST[Position]', '$_POST[Age]', '$_POST[GK]', '$_POST[DEF]', '$_POS[MID]', '$_POST[ATT]')";In each count there is 9 in column count and value count. Do you know what i need to do? Link to comment Share on other sites More sharing options...
Drezard Posted August 28, 2006 Author Share Posted August 28, 2006 Soz I cant help you. But thanks for helping me.- Cheers, Daniel Link to comment Share on other sites More sharing options...
superhoops Posted August 28, 2006 Share Posted August 28, 2006 The code is now:$sql="INSERT INTO Market (id, Player, Price, Type, Position, Age, Ka, Ta, Pa, Sa)VALUES ('','$_POST[Player]','$_POST[Price]','$_POST[Type]''$_POST[Position]','$_POST[Age]','$_POST[GK]','$_POST[DEF]','$_POS[MID]','$_POST[ATT]')";What is the problem with this? Link to comment Share on other sites More sharing options...
Satria Ox41464b Posted August 28, 2006 Share Posted August 28, 2006 @superhoops: there is several MAGIC can help you debugging[code]<?php//Magic #1error_reporting(E_ALL);//Magic #2echo $sql;//Magic #3mysql_query($sql) or die (mysql_error());?>[/code] Link to comment Share on other sites More sharing options...
superhoops Posted August 28, 2006 Share Posted August 28, 2006 so i post one/all of them in my script and what will it do? Link to comment Share on other sites More sharing options...
Satria Ox41464b Posted August 28, 2006 Share Posted August 28, 2006 If you not sure with something... consult Manualits simply easy: http://php.net/REPLACE_ME_WITH_YOUR_UNKNOWN_FUNCTIONExample: http://php.net/error_reporting Link to comment Share on other sites More sharing options...
superhoops Posted August 28, 2006 Share Posted August 28, 2006 I don't understand that tutorial at all sorry. Im a newbie with sql and php. Link to comment Share on other sites More sharing options...
AndyB Posted August 28, 2006 Share Posted August 28, 2006 You're missing a comma between the Type and Position in the VALUES section ... change it to this:[code]$sql="INSERT INTO Market (Player, Price, Type, Position, Age, Ka, Ta, Pa, Sa)VALUES ('$_POST[Player]', '$_POST[Price]', '$_POST[Type]', '$_POST[Position]', '$_POST[Age]', '$_POST[GK]', '$_POST[DEF]', '$_POS[MID]', '$_POST[ATT]')";[/code] Link to comment Share on other sites More sharing options...
AndyB Posted August 28, 2006 Share Posted August 28, 2006 Since this is essentially the same problem as you have being discussed in another thread I'm closing this one.Please do not post virtually identical problems in different threads. Link to comment Share on other sites More sharing options...
Recommended Posts