Jump to content

assuming an obvious mistake?


law

Recommended Posts

I am inexperienced with databases and coding in general. I am getting this error "Incorrect integer value: '' for column 'GraduatingClass' at row 1"  I know the problem is with my database, but i don't understand them well enough to know how it should be done. Also how can I validate my form so that users do not insert incorrect data? Apparently what I have is not working?

 

FORM

<div id="">
<?php session_start(); 
if(isset($_SESSION['ses_user'])){
$ses = $_SESSION['ses_user'];
echo $ses;
}
?>
<script type="text/javascript"
      src="javascript.js">
</script>
<script language="Javascript" type="text/javascript">
//This is the javascript function that validates fields on the form. 

function CheckTheForm()
{
if (document.Register.Name.value=="")
{
alert("Name is Required!")
document.Register.Name.focus();return false
}

if (document.Register.Email.value=="")
{
alert("Email is Required!")
document.Register.Email.focus();return false
}

if (document.Register.userid.value=="")
{
alert("Don't forget to enter user name!")
document.Register.userid.focus();return false
}
if (document.Register.password.value=="")
{
alert("Don't forget to enter your password!")
document.Register.password.focus();return false
}
if (document.Register.FirstName.value=="")
{
alert("Don't forget to enter your First Name!")
document.Register.First Name.focus();return false
}
if (document.Register.MiddleName.value=="")
{
alert("Don't forget to enter your Middle Name!")
document.Register.MiddleName.focus();return false
}
if (document.Register.LastName.value=="")
{
alert("Don't forget to enter your Last Name!")
document.Register.LastName.focus();return false
}
if (document.Register.GraduatingClass.value=="")
{
alert("Don't forget to enter your Graduating Class!")
document.Register.GraduatingClass.focus();return false
}
if (document.Register.City.value=="")
{
alert("Don't forget to enter your City!")
document.Register.City.focus();return false
}
if (document.Register.State.value=="")
{
alert("Don't forget to enter your State!")
document.Register.State.focus();return false
}
if (document.Register.Address.value=="")
{
alert("Don't forget to enter your Address!")
document.Register.Address.focus();return false
}
if (document.Register.ZipCode.value=="")
{
alert("Don't forget to enter your ZipCode!")
document.Register.ZipCode.focus();return false
}
if (document.Register.PhoneNumber.value=="")
{
alert("Don't forget to enter your PhoneNumber!")
document.Register.PhoneNumber.focus();return false
}
if (document.Register.Nickname.value=="")
{
alert("Don't forget to enter your Nickname!")
document.Register.Nickname.focus();return false
}
//This does validation of a valid email address... it cannot validate that the address works, but that it is 
//formatted like an email address should be (something@something.something)

if (document.Register.Email.value != "")
{if (document.Register.Email.value.indexOf("@") == -1 ||
document.Register.Email.value.length < 7)
{alert("Sorry your email address is not valid");
  document.Register.Email.focus();return false}
}
}

</script>

        <?php
        if(!array_key_exists('formMessage', $_SESSION))
        $_SESSION['formMessage'] = "";
        if(!array_key_exists('form_element0', $_SESSION))
        $_SESSION['form_element0'] = "";
        if(!array_key_exists('form_element1', $_SESSION))
        $_SESSION['form_element1'] = "";
        if(!array_key_exists('form_element2', $_SESSION))
        $_SESSION['form_element2'] = "";
        if(!array_key_exists('form_element3', $_SESSION))
        $_SESSION['form_element3'] = "";
        ?>

        <div class="message-text">
          <?php
          if ($_GET['userexist'] == 1){
			echo '<font color=red>This username already exists. Check the spelling or try another name. </font><p>';
		}
//          if (!$_POST['formMessage']) { 
          	echo 'Fill in the form below to open an account. We are also going to save your contact information to keep you up to date on the chapter. Please check back often with the Alumni Connection the site will be undergoing massive overhauls within the near future! To provide our alumni with alot of useful features, (including fantasy football) Thank you!';
//          } else {
//           echo $_POST['formMessage'];
//           }
           ?>
        </div>
        <br />

        <form name="Register" action="./thank.php"
              method="post"
              enctype="multipart/form-data" onsubmit="return CheckTheForm()">
          <label>Your Name:</label>
          <br />
          <input class="form-input-field"
                type="text"
                name="FirstName"
                size="30" /><br>

          <label>Middle Name:</label>
          <br />
          <input class="form-input-field"
                type="text"
                name="MiddleName"
                size="30" /><br>
  
          <label>Last Name:</label>    
          <br />
          <input class="form-input-field"
                type="text"
                name="LastName"
                size="30" />
          <br>
	  <br>
	  <label>Graduating Class (numbers only! example:'1999'):</label>    
          <br />
          <input class="form-input-field"
                type="text"
                name="GraduatingClass"
                size="4" /><br>
	  <label>Nick Name (if you had one):</label>    
          <br />
          <input class="form-input-field"
                type="text"
                name="Nickname"
                size="30" />
          <br>
	  <br>
          <label>City:</label>    
          <br />
          <input class="form-input-field"
                type="text"
                name="City"
                size="30" /><br>

          <label>State:</label>    
          <br />
          <input class="form-input-field"
                type="text"
                name="State"
                size="30" /><br>

          <label>Address:</label>    
          <br />
          <input class="form-input-field"
                type="text"
                name="Address"
                size="30" /><br>

          <label>Zipcode:</label>    
          <br />
          <input class="form-input-field"
                type="text"
                name="ZipCode"
                size="5" />
          
          <br />          
          <br />
          <label>Phone Number (numbers only no dashes):</label>    
          <br />
          <input class="form-input-field"
                type="text"
                name="PhoneNumber"
                size="10" />
          <br />
          <label>Email:</label>
          <br />
          <input class="form-input-field"
                type="text"
                name="Email"
                size="40" />
          <br />
          <br />
          <label>User Name:</label>
          <br />
          <input class="form-input-field"
                type="text"
                name="userid"
                size="40" />
          <br />
          <br />
          <label>Password:</label>
          <br />
          <input class="form-input-field"
                type="password"
                name="password"
                size="40" />
          <br />
          <br />
          <input class="form-input-button"
                type="reset"
                name="resetButton"
                value="Reset" /> 
          <input class="form-input-button"
                type="submit"
                name="submitButton"
                value="Submit" />
        </form><?php session_destroy(); ?>
</div>

 

thank.php (form processor)

<?php 
session_start();
//if(isset($_SESSION['ses_user'])){
//	$tmp=$_SESSION['ses_user'];	
$var0 = stripslashes($_POST['userid']);
$var1 = $_POST['FirstName'];
$var2 = $_POST['MiddleName'];
$var3 = $_POST['LastName'];
$var4 = $_POST['GraduatingClass'];
$var5 = $_POST['Nickname'];
$var6 = $_POST['City'];
$var7 = $_POST['State'];
$var8 = $_POST['Address'];
$var9 = $_POST['ZipCode'];
$var10 = $_POST['PhoneNumber'];
$var11 = $_POST['Email'];
$var12 = $_POST['Password'];

include("./dbconfig.php");
$sql = mysql_query("SELECT * FROM members WHERE nickname = '$var0'") or die(mysql_error());
$num = mysql_num_rows($sql);
//echo "$var3";
//		include_once('./includes/head.inc');
//		include_once('./includes/logo.inc');
//		include_once('./includes/registrationmenu.inc'); 	
	if ($num ==0){
	$result = mysql_query("INSERT INTO members(FirstName, MiddleName, LastName, GraduatingClass, Nickname, City, State, Address, Zip, PhoneNumber, Email, UserName, Password)
										VALUES('$var1', '$var2', '$var3', '$var4', '$var5', '$var6', '$var7', '$var8', '$var9', '$var10', '$var11', '$var0' ,'$var12')") or die(mysql_error());
// echo "$result";
	print "** Thank you <B><font color=#adfcff>";
	print "$var1 $var2 $var3";
	print "</B></font> for registering with us. **";
	print "PLEASE CHECK BACK OFTEN FOR UPDATES";
} else {

	header("Location:./index.php?userexist=1");
}
//	include_once('./includes/indexbody.inc');
//	include_once('./includes/footer.inc');      
//} else {
//	header('Location:index.php?notloggedin=1');
//}
?>

 

TABLE (once again i'm not good at making tables)

/*Column Information For - sigepalumni.members*/
------------------------------------------------

Field            Type         Collation          Null    Key     Default  Extra           Privileges                       Comment
---------------  -----------  -----------------  ------  ------  -------  --------------  -------------------------------  -------
id               int(4)       (NULL)             NO      PRI     (NULL)   auto_increment  select,insert,update,references         
FirstName        varchar(30)  latin1_swedish_ci  YES             (NULL)                   select,insert,update,references         
MiddleName       varchar(30)  latin1_swedish_ci  YES             (NULL)                   select,insert,update,references         
LastName         varchar(30)  latin1_swedish_ci  YES             (NULL)                   select,insert,update,references         
GraduatingClass  year(4)      (NULL)             YES             (NULL)                   select,insert,update,references         
City             varchar(30)  latin1_swedish_ci  YES             (NULL)                   select,insert,update,references         
State            varchar(30)  latin1_swedish_ci  YES             (NULL)                   select,insert,update,references         
Address          varchar(30)  latin1_swedish_ci  YES             (NULL)                   select,insert,update,references         
Zip              int(5)       (NULL)             YES             (NULL)                   select,insert,update,references         
PhoneNumber      int(10)      (NULL)             YES             (NULL)                   select,insert,update,references         
Nickname         varchar(15)  latin1_swedish_ci  YES             (NULL)                   select,insert,update,references         
UserName         varchar(15)  latin1_swedish_ci  YES             (NULL)                   select,insert,update,references         
Password         varchar(15)  latin1_swedish_ci  YES             (NULL)                   select,insert,update,references         
Email            varchar(30)  latin1_swedish_ci  YES             (NULL)                   select,insert,update,references         
DateRegistered   date         (NULL)             YES             (NULL)                   select,insert,update,references         

/*Index Information For - sigepalumni.members*/
-----------------------------------------------

Table    Non_unique  Key_name  Seq_in_index  Column_name  Collation  Cardinality  Sub_part  Packed  Null    Index_type  Comment
-------  ----------  --------  ------------  -----------  ---------  -----------  --------  ------  ------  ----------  -------
members           0  PRIMARY              1  id           A                    0    (NULL)  (NULL)          BTREE              

/*DDL Information For - sigepalumni.members*/
---------------------------------------------

Table    Create Table                               
-------  -------------------------------------------
members  CREATE TABLE `members` (                   
           `id` int(4) NOT NULL auto_increment,     
           `FirstName` varchar(30) default NULL,    
           `MiddleName` varchar(30) default NULL,   
           `LastName` varchar(30) default NULL,     
           `GraduatingClass` year(4) default NULL,  
           `City` varchar(30) default NULL,         
           `State` varchar(30) default NULL,        
           `Address` varchar(30) default NULL,      
           `Zip` int(5) default NULL,               
           `PhoneNumber` int(10) default NULL,      
           `Nickname` varchar(15) default NULL,     
           `UserName` varchar(15) default NULL,     
           `Password` varchar(15) default NULL,     
           `Email` varchar(30) default NULL,        
           `DateRegistered` date default NULL,      
           PRIMARY KEY  (`id`)                      
         ) ENGINE=InnoDB DEFAULT CHARSET=latin1     

Link to comment
Share on other sites

<label>Graduating Class (numbers only! example:'1999'):</label>    
          <br />
          <input class="form-input-field"
                type="text"
                name="GraduatingClass"
                size="4" /><br>

 

So how can i produce a java script form checker to make sure they only enter numbers? or is there some "type" of form input field that only allows numbers? here is my current script it only checks to make sure that the user has entered something in every input field.

 

if (document.Register.GraduatingClass.value=="")
{
alert("Don't forget to enter your Graduating Class!")
document.Register.GraduatingClass.focus();return false
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.