Jump to content


Photo

Cant work out this script


  • This topic is locked This topic is locked
11 replies to this topic

#1 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 28 August 2006 - 11:21 AM

Hello, I get this error:

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


When i try and execture this code: (I cant work out whats wrong)

<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 database
mysql_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 whole
form 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 also
emptys 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 took
out 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 such
as: 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 up
of loss ends. The loss ends of else { and if { statements. */
}
}


?>
</body>
</html>

Im kinda newbie and help would be very very appreciated.

Thanks, Daniel

#2 superhoops

superhoops
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 28 August 2006 - 11:25 AM

I also get the error Column count doesn't match value count at row 1.


#3 Satria Ox41464b

Satria Ox41464b
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 28 August 2006 - 11:29 AM

Column count doesn't match value count

INSERT INTO users
//this section is COLUMN count
(name, email1, email2,
daytime, nighttime, mobile,
streetnum, streetname, suburb,
state, postcode, askprice,
bedrooms, bathrooms)
//total 14 column
VALUES

//this section is VALUE count
('Daniel', 'ashis', 'hioahiodf',
'12412', '1345145', '15151515',
'15123', 'suburb', 'state',
'postcode', 'askprice', 'bedrooms',
'bathrooms')
//total 13 column



#4 superhoops

superhoops
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 28 August 2006 - 11:33 AM

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?

#5 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 28 August 2006 - 11:38 AM

Soz I cant help you. But thanks for helping me.

- Cheers, Daniel

#6 superhoops

superhoops
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 28 August 2006 - 12:02 PM

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?

#7 Satria Ox41464b

Satria Ox41464b
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 28 August 2006 - 12:06 PM

@superhoops: there is several MAGIC can help you debugging
<?php
//Magic #1
error_reporting(E_ALL);

//Magic #2
echo $sql;

//Magic #3
mysql_query($sql) 
   or die (mysql_error());
?>


#8 superhoops

superhoops
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 28 August 2006 - 12:25 PM

so i post one/all of them in my script and what will it do?

#9 Satria Ox41464b

Satria Ox41464b
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 28 August 2006 - 12:34 PM

If you not sure with something... consult Manual
its simply easy: http://php.net/REPLA...NKNOWN_FUNCTION

Example: http://php.net/error_reporting

#10 superhoops

superhoops
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 28 August 2006 - 12:49 PM

I don't understand that tutorial at all sorry. Im a newbie with sql and php.

#11 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 August 2006 - 01:26 PM

You're missing a comma between the Type and Position in the VALUES section ... change it to this:

$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]')";

Legend has it that reading the manual never killed anyone.
My site

#12 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 August 2006 - 02:55 PM

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.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users