Hallo vrienden, zit met het volgend probleem, heb een join_form gemaakt, heb in mijn database de nodige items aangemaakt die overeenkomen met de invul formulier. Heb de form geuploaded en om het te proberen heb ik zelf de gegevens ingebracht, maar krijg steeds de melding "Column count doesn't match value count at row 1".
Heb de volgende code gebruikt:
<?php
include_once "connect_to_mysql.php";


if (isset($_POST['username'])){


$username = $_POST['username'];
$country = $_POST['country'];
$state = $_POST['state'];
$city = $_POST['city'];
$your_age = $_POST['your_age'];
$adress1 = $_POST['adress1'];
$looking_for = $_POST['looking_for'];
$sexual_orientation = $_POST['sexual_orientation'];
$living_in = $_POST['living_in'];
$accounttype = $_POST['accounttype'];
$email = $_post['email'];
$password = $_POST['password'];
$humancheck = $_POST['humancheck'];

$username = stripslashes($username);
$country = stripslashes($country);
$state = stripslashes($state);
$city = stripslashes($city);
$your_age = stripslashes($your_age);
$adress1 = stripslashes($adress1);
$looking_for = stripslashes($looking_for);
$sexual_orientation = stripslashes($sexual_orientation);
$living_in = stripslashes($living_in);
$accounttype = stripslashes($accounttype);
$email = stripslashes($email);
$password = stripslashes($password);

$username = strip_tags($username);
$country = strip_tags($country);
$state = strip_tags($state);
$city = strip_tags($city);
$your_age = strip_tags($your_age);
$adress1 = strip_tags($adress1);
$looking_for = strip_tags($looking_for);
$sexual_orientation = strip_tags($sexual_orientation);
$living_in = strip_tags($living_in);
$accounttype = strip_tags($accounttype);
$email = strip_tags($email);
$password = strip_tags($password);


$sql_email_check = mysql_query("SELECT id FROM meetyourpal WHERE email='$email'");
$email_check = mysql_num_rows($sql_email_check);

if((!$username) || (!$country) || (!$state) || (!$city) || (!$your_age) || (!$sexual_orientation) || (!$adress1) || (!$looking_for) || (!$living_in) || (!$accounttype) || (!$email) || (!$password)){

$errorMsg = "You did not submit the following required information!<br /><br />";
if(!$username){
$errorMsg .= '* username<br />';
} if(!$country){
$errorMsg .= '* country<br />';
} if(!$adress1){
$errorMsg .= '* adress1<br />';

} if(!$state){
$errorMsg .= '* state<br />';
} if(!$city){
$errorMsg .= '* city<br />';

} if(!$your_age){
$errorMsg .= '* your_age<br />';
} if(!$looking_for){
$errorMsg .= '* looking_for<br />';
} if(!$sexual_orientation){
$errorMsg .= '* sexual_orientation<br />';
} if(!$living_in){
$errorMsg .= '* living_in<br />';
} if(!$accounttype){
$errorMsg .= '* accounttype<br />';
} if(!$email){
$errorMsg .= '* email<br />';
} if(!$password){
$errorMsg .= '* password<br />';
}
}
$sql_username_check = mysql_query("SELECT id FROM meetyourpal WHERE username='$username' LIMIT 1");
$username_check = mysql_num_rows($sql_username_check);

if ($username_check > 0){
$errorMsg = "<u>ERROR:</u>Your User Name is already in use inside our system. Please try another.<br />";
} else if ($email_check > 0){
$errorMsg = "<u>ERROR:</u>Your Email address is already in use inside our system. Please try another.<br />";
} else if ($human_check!=""){
$errorMsg = "ERROR The human check field must be cleared to be sure you are human<br/>";
} else {
$username = mysql_real_escape_string($username);
$country = mysql_real_escape_string($country);
$state = mysql_real_escape_string($state);
$city = mysql_real_escape_string($city);
$your_age = mysql_real_escape_string($your_age);
$adress1 = mysql_real_escape_string($adress1);
$looking_for = mysql_real_escape_string($looking_for);
$sexual_orientation = mysql_real_escape_string($sexual_orientation);
$living_in = mysql_real_escape_string($living_in);
$accounttype = mysql_real_escape_string($accounttype);
$email = mysql_real_escape_string($email);

$username = ereg_replace("[^A-Za-z0-9]", "", $_POST['username']);
$country = ereg_replace("[^A-Z a-z0-9]", "", $_POST['country']);
$state = ereg_replace("[^A-Z a-z0-9]", "", $_POST['state']);
$city = ereg_replace("[^A-Z a-z0-9]", "", $_POST['city']);
$your_age = ereg_replace("[^A-Z a-z0-9]", "", $_POST['your_age']);
$adress1 = ereg_replace("[^A-Z a-z0-9]", "", $_POST['adress1']);
$looking_for = ereg_replace("[^A-Z a-z0-9]", "", $_POST['looking_for']);
$sexual_orientation = ereg_replace("[^A-Z a-z0-9]", "", $_POST['sexual_orientation']);
$living_in = ereg_replace("[^A-Z a-z0-9]", "", $_POST['living_in']);
$accounttype = ereg_replace("[^a-z]", "", $_POST['accounttype']);
$email = stripslashes($_POST['email']);

$password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']);


$hashedPass = md5($password);

$sql = mysql_query("INSERT INTO meetyourpal (username, adress1, country, state, city, your_age, looking_for, sexual_orientation, living_in, accounttype, email, password)
VALUES('$username','$adress1','$country','$state','$city','$your_age','$looking_for','$sexual_orientation','$living_in','$accounttype','$email','$hashedPass', now())") or die (mysql_error());

$id = mysql_insert_id();

mkdir("members/$id", 0755);

$to = "$email";

$from = "[email protected]";
$subject = "Complete your registration";

$message = '<html>
<body bgcolor="#FFFFFF">
Hi ' . $username . ',
<br /><br />
You must complete this step to activate your account with us.
<br /><br />
Please click here to activate now &gt;&gt;
<a href="activation.php?id=' . $id . '&sequence=$db_password">
ACTIVATE NOW</a>
<br /><br />
Your Login Data is as follows:
<br /><br />
E-mail Address: ' . $email . ' <br />
Password: ' . $password . '
<br /><br />
See you at our site!!!!!
Thanks!
</body>
</html>';

$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$to = "$to";

mail($to, $subject, $message, $headers);

print "<br /><br /><br /><h4>OK $firstname, one last step to verify your email identity:</h4><br />
We just sent an Activation link to: $email<br /><br />
<strong><font color=\"#990000\">Please check your email inbox in a moment</font></strong> to click on the Activation <br />
Link inside the message. After email activation you can log in.";
exit();
}
} else {
$errorMsg = "Fields marked with an [*] are required.";
$username = "";
$country = "";
$state = "";
$city = "" ;
$your_age = "";
$adress1 = "";
$looking_for = "";
$sexual_orientation = "";
$living_in = "";
$accounttype = "";
$email = "";
$password = "";
}
?>
Waar moet ik de fout zoeken? Kan iemand mij een hint geven?
Alvast bedankt,peter
Je kolommen kloppen niet in je INSERT query -> check je values

Dit stuk is fout, tel je kolommen maar eens na

"INSERT INTO meetyourpal (username, adress1, country, state, city,  your_age, looking_for, sexual_orientation, living_in, accounttype, email, password) 
        VALUES('$username','$adress1','$country','$state','$city','$your_age','$looking_for','$sexual_orientation','$living_in','$accounttype','$email','$hashedPass', now())"
Script is lek => sql-injection.
santhe wil zeggen gebruik mysql_real_escape_sring() rond je input
dank je jasper, dat ene probleem is opgelost nu krijg ik de melding "Unknown column 'adress1' in 'field list",hij staat in de code, hij staat in het invul formulier en in de database. Wat nu?
Ik weet niet of het helpt maar address is met dubbel d en dubbel s.
Peter, als mysql zegt de kolom 'adress1' niet te kunnen vinden, kan ik twee oorzaken verzinnen: je laat 'm in de verkeerde tabel kijken, of de kolom bestaat echt niet.

Controleer de indeling anders (met DESCRIBE meetyourpal)

Reageren