Page 1 of 2

[SOLVED] need help ASAP-- big problem

Posted: Thu Apr 26, 2007 3:00 pm
by thefreebielife
my users are getting this error on sign up:

Could not insert data because Column count doesn't match value count at row 1

now, i was doing work with my database but now in the users section

here's the dump for my users table:

Code: Select all

CREATE TABLE `users` (
  `uId` int(6) NOT NULL auto_increment,
  `username` text NOT NULL,
  `password` text NOT NULL,
  `fname` text NOT NULL,
  `email` text NOT NULL,
  `address` text NOT NULL,
  `city` text NOT NULL,
  `state` text NOT NULL,
  `zip` text NOT NULL,
  `country` text NOT NULL,
  `phone` text NOT NULL,
  `ip` text NOT NULL,
  `gid` int(6) NOT NULL default '0',
  `rid` int(6) NOT NULL default '0',
  `ostatus` tinyint(4) NOT NULL default '0',
  `holdreason` text NOT NULL,
  `astatus` tinyint(4) NOT NULL default '0',
  `date` text NOT NULL,
  `deadline` text NOT NULL,
  `dead` tinyint(4) NOT NULL default '0',
  PRIMARY KEY  (`uId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=486;
please help ASAP

Posted: Thu Apr 26, 2007 3:01 pm
by noahkeller
try changing the

`uId` int(6)

to

`uId` int(11)

Posted: Thu Apr 26, 2007 3:07 pm
by thefreebielife
still getting this error

Could not insert data because Column count doesn't match value count at row 1

Posted: Thu Apr 26, 2007 3:10 pm
by Chris Corbyn
So where's the query? :) We need to see your INSERT query that's causing the error - which as the message says because your listing the columns to insert to but then passing a different number of values.

Posted: Thu Apr 26, 2007 3:10 pm
by noahkeller
can you show me the code you are using to insert the data?

I.E.

Code: Select all

INSERT INTO `table` (`field1`,`field2`,`field3`) VALUES (`field1value`,`field2value`,`field3value`)

-bleh you beat me to it

Posted: Thu Apr 26, 2007 3:12 pm
by Burrito
Please use a better description in the subject of your next post.

Posted: Thu Apr 26, 2007 3:15 pm
by thefreebielife
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


heres the main part of the code minus images:

Code: Select all

<html>
<head>
<? require("config.php"); require("functions.php");?>
		
<? 
if (isset($_GET["form"]) && $_GET['form'] == "submit") { 
$gid = $_POST['gid'];
} else {
$gid = $_GET['gid'];
}
if ($gid != "") {
$data = mysql_query("SELECT * FROM gifts WHERE gId='$gid'")
or die(mysql_error()); 
$r = mysql_fetch_array($data);
$gname=$r["gName"];
$gdescription=$r["gDescription"];
$gimage=$r["gImage"];
$gprice=$r["gPrice"];
$gref=$r["gRef"];
?>
<div id="s_gifts">
<div class="s_gdescription"><font color="#FF0000">Referrals Needed: <? echo "$gref"; ?></font></div>
<div class="s_gimage" align="center"><img src="<? echo "$gimage"; ?>" border="0"></div>
<div class="s_gname"><? echo "$gname"; ?></div>
<div class="s_gdescription"><? echo "$gdescription"; ?><br>
</div>
</div>

		<Br>
 <Br>
 
 <? 
$r = $_GET['r'];
//check ref id
if ($r != "") {
$sql = 'SELECT * FROM `users` WHERE `uId` = "'.$r.'"';
$query = mysql_query ($sql);
if (mysql_num_rows($query) ==0) {
$ref = "error"; 
$r=0;
} 
}
//validate form
//get vars
if (isset($_GET["form"]) && $_GET['form'] == "submit") { 
$Email = $_POST['email']; 
$username2 = $_POST['username'];
$pass = $_POST['pass'];
$fname = $_POST['fname'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$ip = $_POST['ip'];
$r = $_POST['r'];
$date = date("F j, Y");
$gid = $_POST['gid'];
$error = "none";
$terms = $_POST['terms'];
$r = $_POST['r'];
$username = strtolower($username2);
$password = strtolower($password2);
$pass2 = md5($pass);
$deadline = date ("F j, Y", mktime(0,0,0,date('m'), date('d')+$limit, date('y')));
//validate

//validate zip
if (!zip_field($zip)  or $zip == "") {
$error = "zip";
}
//validate state
if (!name_fields($state) or $state == "") {
$error = "state";
}
//validate city
if (!other_fields($city) or $city == "") {
$error = "city";
}
//validate address
if (!other_fields($address) or $address == "") {
$error = "address";
}
//validate gift
if ($gid == "") {
$error = "giftid";
}
//valiudate fname
if (!name_fields($fname) or $fname == "") {
$error = "firstname";
}
//validate password
if (!username_field($pass) or $pass == "") {
$error = "password";
}
//validate username
if (!username_field($username) or $username == "") {
$error = "username";
}

//validate email
if (!check_email($Email)) {
$error = "Email"; 
}
//validate terms
if ($terms == "" or $terms != "accepted") 
{ $error = "terms"; }

//see if username is taken
$sql = 'SELECT * FROM `users` WHERE `username` = "'.$username.'"';
$query = mysql_query ($sql);

if (mysql_num_rows($query) !=0) {
echo '<center><font color="#ff0000"><h4>Username already exists.  Please try again<br /><br /><a href=javascript:history.back()><< Go Back</a></h4>'; exit;
} 
//check to see if email is used
$sql = 'SELECT * FROM `users` WHERE `email` = "'.$Email.'"';
$query = mysql_query ($sql);

if (mysql_num_rows($query) !=0) {
echo '<center><font color="#ff0000"><h4>This Email is already in use.  Please try again<br /><br /><a href=javascript:history.back()><< Go Back</a></h4>'; exit;
} 
//if not insert data
if ($error == "none") { 
	  mail($Email,"Welcome To The Freebie Life!","Welcome to The Freebie Life! <br>

If you have any questions please contact support. <Br>We answer all questions within 1 DAY.<br>

Remember, all gifts are shipped on the 5th and 20th of each month.<Br>
<br>
Enjoy!<br>
Jared<br>
The Freebie Life Admin","From:Admin@thefreebielife.com\nContent-Type: text/html; charset=iso-8859-1");  
$insert = mysql_query("insert into users values ('', '$username', '$pass2', '$fname', '$Email', '$address', '$city', '$state', '$zip', '$ip', '$gid', '$r', '0', '0', '$date', '$deadline', '')")
or die("Could not insert data because ".mysql_error());
echo '<center><font color="#ff0000"><h4>Thank You, Your Account Has Been Created</h4>'; 
if ($error == "none") {
echo '<meta http-equiv="refresh" content="3;url=login.php">';
   exit;
   }
}
}



?>
 
 
 <form action="register.php?form=submit" method="post" name="register2">
<table width="300" border="0" align="center"  class="table" style="border: 1px dashed red; padding: 4px 4px 4px 4px; ">
 <tr>
    <td colspan="2"><div align="center"><? 
if ($ref == "error") { echo "<font color=red><center>Your Referral Link Is Invalid</center></font>"; }
if ($error == "terms") { echo "<font color=red><center>Your Must Accept the User Agreement</center></font>"; }
if ($error == "username") { echo "<font color=red><center>Your Username is Incorrect</center></font>"; }
if ($error == "password") { echo "<font color=red><center>Your Password is Incorrect</center></font>"; }
if ($error == "firstname") { echo "<font color=red><center>Your First Name is Incorrect</center></font>"; }
if ($error == "address") { echo "<font color=red><center>Your Address is Incorrect</center></font>"; }
if ($error == "city") { echo "<font color=red><center>Your City is Incorrect</center></font>"; }
if ($error == "state") { echo "<font color=red><center>Your State is Incorrect</center></font>"; }
if ($error == "zip") { echo "<font color=red><center>Your Zip Code is Incorrect</center></font>"; }
if ($error == "Email") { echo "<font color=red><center>Your Email is Incorrect</center></font>"; }
if ($error == "giftid") { echo "<font color=red><center>You must select a gift from the main page</center></font>"; }

?></div></td>
	</tr>

 <tr>
    <td colspan="2" style="border-bottom:1px dashed red "><div align="left"><strong>Sign Up Now </strong></div></td>
	</tr>
	 <tr>
    <td colspan="2"><div align="center"><strong>Account Information </strong></div></td>
	</tr>
  <tr>
    <td width="141">Username:</td>
    <td width="320"><input name="username" type="text" id="username" size="20" value="<? echo "$username" ?>" /></td>
  </tr>
  <tr>
    <td>Email:</td>
    <td><input name="email" type="text" id="email" size="20" value="<? echo "$Email" ?>" /></td>
  </tr>
    <tr>
    <td>Password:</td>
    <td><input name="pass" type="password" id="pass" value="<? echo "$pass"; ?>"  size="20" /></td>
  </tr>
  <tr>
    <td colspan="2"><div align="center"><strong>Shipping Information </strong></div></td>
  </tr>
  <tr>
    <td height="26">Full Name: </td>
    <td><input name="fname" type="text" id="fname" size="20" value="<? echo "$fname"; ?>"  /></td>
  </tr>
  <tr>
    <td>Address:</td>
    <td><input name="address" type="text" id="address" size="20" value="<? echo "$address"; ?>"  /></td>
  </tr>
  <tr>
    <td>City:</td>
    <td><input name="city" type="text" id="city" size="20" value="<? echo "$city"; ?>"  /></td>
  </tr>
  <tr>
    <td>State:</td>
    <td><select name="state" id="state">

									<option selected value=''>State</option>
									<option value="AL" >Alabama</option>

								  <option value="AK" >Alaska</option>
								  <option value="AZ" >Arizona</option>
								  <option value="AR" >Arkansas</option>
								  <option value="CA" >California</option>
								  <option value="CO" >Colorado</option>
								  <option value="CT" >Connecticut</option>

								  <option value="DE" >Delaware</option>
								  <option value="DC" >District of Columbia</option>
								  <option value="FL" >Florida</option>
								  <option value="GA" >Georgia</option>
								  <option value="HI" >Hawaii</option>
								  <option value="ID" >Idaho</option>

								  <option value="IL" >Illinois</option>
								  <option value="IN" >Indiana</option>
								  <option value="IA" >Iowa</option>
								  <option value="KS" >Kansas</option>
								  <option value="KY" >Kentucky</option>
								  <option value="LA" >Louisiana</option>

								  <option value="ME" >Maine</option>
								  <option value="MD" >Maryland</option>
								  <option value="MA" >Massachusetts</option>
								  <option value="MI" >Michigan</option>
								  <option value="MN" >Minnesota</option>
								  <option value="MS" >Mississippi</option>

								  <option value="MO" >Missouri</option>
								  <option value="MT" >Montana</option>
								  <option value="NE" >Nebraska</option>
								  <option value="NV" >Nevada</option>
								  <option value="NH" >New Hampshire</option>
								  <option value="NJ" >New Jersey</option>

								  <option value="NM" >New Mexico</option>
								  <option value="NY" >New York</option>
								  <option value="NC" >North Carolina</option>
								  <option value="ND" >North Dakota</option>
								  <option value="OH" >Ohio</option>
								  <option value="OK" >Oklahoma</option>

								  <option value="OR" >Oregon</option>
								  <option value="PA" >Pennsylvania</option>
								  <option value="RI" >Rhode Island</option>
								  <option value="SC" >South Carolina</option>
								  <option value="SD" >South Dakota</option>
								  <option value="TN" >Tennessee</option>

								  <option value="TX" >Texas</option>
								  <option value="UT" >Utah</option>
								  <option value="VT" >Vermont</option>
								  <option value="VA" >Virginia</option>
								  <option value="WA" >Washington</option>
								  <option value="WV" >West Virginia</option>

								  <option value="WI" >Wisconsin</option>
								  <option value="WY" >Wyoming</option>
								  </select>
    </select>
    </td>
  </tr>
  <tr>
    <td>Zip:</td>
    <td><input name="zip" type="text" id="zip" size="20" value="<? echo "$zip"; ?>" /></td>
  </tr>
  <tr>
    <td>Country:</td>
    <td>United States</td>
  </tr>
     <tr>
    <td colspan="2">
      <div align="center">
     <input name="terms" type="checkbox" value="accepted">
        <font size="2">I have read and agree to the <a href="terms.php" target="_new">User Agreement</a></font></div></td>
  </tr>
   <tr>
    <td colspan="2">
      <div align="center">
        <input type="submit" name="Submit" value="Submit" />
        </div></td>
  </tr>
  <tr>
    <td colspan="2">Ip Logged As: <? echo getenv('REMOTE_ADDR'); ?> <input name="ip" type="hidden" id="ip" value="<? echo getenv('REMOTE_ADDR'); ?>" /><input name="r" type="hidden" id="r" value="<? echo "$r"; ?>" />
      <input name="gid" type="hidden" id="gid" value="<? echo "$gid"; ?>" /></td>
  </tr>
     <tr>
    <td colspan="2"></td>
  </tr>
</table>
</form>
<? } else { echo "Please Go To The Start Page"; } ?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Apr 26, 2007 3:25 pm
by noahkeller
Try changing:

Code: Select all

$insert = mysql_query("insert into users values ('', '$username', '$pass2', '$fname', '$Email', '$address', '$city', '$state', '$zip', '$ip', '$gid', '$r', '0', '0', '$date', '$deadline', '')")
to

Code: Select all

$insert = mysql_query("insert into users values (NULL, '$username', '$pass2', '$fname', '$Email', '$address', '$city', '$state', '$zip', '$ip', '$gid', '$r', '0', '0', '$date', '$deadline', '')")

Posted: Thu Apr 26, 2007 3:28 pm
by aaronhall
PHP tags, guys... it's right next to the "Code" button and is, surprisingly, labeled "PHP"

Posted: Thu Apr 26, 2007 3:30 pm
by noahkeller
In all fairness I used code tag because I considered it more SQL than PHP....

my bad if I'm ignorant

Posted: Thu Apr 26, 2007 3:31 pm
by thefreebielife
hm same problem, i guess its a database issue on MYSQL? but i dont understand this problem at all

Posted: Thu Apr 26, 2007 3:31 pm
by aaronhall
It's still PHP code (a string declaration). Either way, there are syntax tags for SQL in the "Syntax..." drop-down menu

Posted: Thu Apr 26, 2007 3:34 pm
by aaronhall
thefreebielife wrote:hm same problem, i guess its a database issue on MYSQL? but i dont understand this problem at all
There are 17 values in the insert query, and 20 columns in the table. You missed a couple of columns

Posted: Thu Apr 26, 2007 3:40 pm
by noahkeller

Code: Select all

mysql_query("insert into users values ('', '$username', '$pass2', '$fname', '$Email', '$address', '$city', '$state', '$zip', '$ip', '$gid', '$r', '0', '0', '$date', '$deadline', '')")
to

Code: Select all

mysql_query("INSERT INTO `users` (`username`,`password`,`fname`,`email`,`address`,`city`,`state`,`zip`,`country`,`phone`,`ip`,`gid`,`rid`,`ostatus`,`holdreason`,`astatus`,`date,`deadline,`dead`) VALUES 
('$USERNAME','$PASSWORD','$FNAME','$EMAIL','$ADDRESS','$CITY','$STATE','$ZIP','$COUNTRY','$PHONE','$IP','$GID','$RID','$OSTATUS','$HOLDREASON','$ASTATUS','$DATE','$DEADLINE','$DEAD')")
replacing the variables with whatever they may be of course

Posted: Thu Apr 26, 2007 3:45 pm
by thefreebielife

Code: Select all

`uId` int(11) NOT NULL auto_increment,
  `username` text NOT NULL,
  `password` text NOT NULL,
  `fname` text NOT NULL,
  `email` text NOT NULL,
  `address` text NOT NULL,
  `city` text NOT NULL,
  `state` text NOT NULL,
  `zip` text NOT NULL,
  `country` text NOT NULL,
  `ip` text NOT NULL,
  `gid` int(6) NOT NULL default '0',
  `rid` int(6) NOT NULL default '0',
  `ostatus` tinyint(4) NOT NULL default '0',
  `holdreason` text NOT NULL,
  `astatus` tinyint(4) NOT NULL default '0',
  `date` text NOT NULL,
  `deadline` text NOT NULL,
  `dead` tinyint(4) NOT NULL default '0',
i dont think that the tinyint(4)'s matter though? or the hold reason. just the info that they sign up with.

like i said, this was working fine this morning and has had 500 people sign up with it but i dont know what happened