Jump to content

Archived

This topic is now archived and is closed to further replies.

Drezard

Cant work out this script

Recommended Posts

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 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>
[/CODE]

Im kinda newbie and help would be very very appreciated.

Thanks, Daniel

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
@superhoops: there is several MAGIC can help you debugging
[code]<?php
//Magic #1
error_reporting(E_ALL);

//Magic #2
echo $sql;

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

Share this post


Link to post
Share on other sites
If you not sure with something... consult Manual
its simply easy: http://php.net/REPLACE_ME_WITH_YOUR_UNKNOWN_FUNCTION

Example: http://php.net/error_reporting

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×

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.