Click to See Complete Forum and Search --> : Inserting Form Values Into Database...HELP


dangillow
11-11-2006, 04:18 AM
Hi There,

I seem to be having issues with my form and inserting those values into my database. I have my form in one file and PHP form processing in another file.

When the user clicks submit, my PHP form processing file is called and it process's the form. After all fields have been validated. When user clicks the submit button its greyed out to prevent multiple clicks and entrys my PHP form processing file is called but nothing happens, just a blank screen. I know the form is working fine as it was before I added the javascript validation.

I have recently added some javascript validation to check my form and grey out the submit button once clicked.

http://www.webdeveloper.com/forum/showthread.php?p=665859#post665859

I posted on this site yesterday for some help on my javascript validation. That all seems to be fine now. Is there something wrong with my my form or my PHP processing script?

I have posted both bits of code below. Thank you for reading. This is driving me nuts right now :confused:

FORM CODE

<script language="JavaScript" type="text/javascript">
<!--

function checkform ( form )

{

if (document.getElementById("forename").value.length <2) {
alert( "Please Enter Your Forename" );
document.getElementById("forename").focus();
return false ;
}

if (document.getElementById("surname").value.length <2) {
alert( "Please Enter Your Surname" );
document.getElementById("surname").focus();
return false ;
}

if (document.getElementById("telephone_extension").value.length <3) {
alert( "Please Enter Your Telephone Extension" );
document.getElementById("telephone_extension").focus();
return false ;
}


if (document.getElementById("email").value.length <5) {
alert( "Please Enter Your E-Mail" );
document.getElementById("email").focus();
return false ;
}


if (document.getElementById("location").value.length <2) {
alert( "Please Provide Your Room Location" );
document.getElementById("location").focus();
return false ;
}

document.getElementById("submitButton").disabled = true;

form.submit();

return true ;

}

//-->
</script>


</head>
<body>

<div align="center"><h2>Create User</h2></div>



<form action="create_user_processing.php" method="post">


<fieldset>

<legend>Contact Details</legend>



<p>
<label for="forename">Forename:<em class="required"> (Required)</em></label>
<input style="background-color:#ffc;" name="forename" id=forename" type="text" maxlength="30"/>
</p>

<p>
<label for="surname">Surname:<em class="required"> (Required)</em></label>
<input style="background-color:#ffc;" name="surname" id=surname" type="text" maxlength="30"/>
</p>

<p>
<label for="telephone_extension">Telephone Extension:</label>
<input style="background-color:#ffc;" name="telephone_extension" id=telephone_extension" type="text" maxlength="15"/>
</p>

<p>
<label for="email">E-Mail:<em class="required"> (Required)</em></label>
<input style="background-color:#ffc;" name="email" id=email" type="text" maxlength="30"/>
</p>

<p>
<label for="location">Location:<em class="required"> (Required)</em></label>
<input style="background-color:#ffc;" name="location" id=location" type="text" maxlength="20"/>
</p>


<input type="reset" name="reset" value="Reset" />
<input type="button" name="submitButton" id="submitButton" onclick="checkform(this.form)" value="Submit"/>

</fieldset>

</form>


PHP FORM PROCESSING

// Assign the query

$query = "INSERT INTO user (id, user_id, forename, surname, telephone_extension, email, location)

VALUES ('{$_POST['id']}', '{$_POST['user_id']}', '{$_POST['forename']}', '{$_POST['surname']}', '{$_POST['telephone_extension']}' , '{$_POST['email']}', '{$_POST['location']}')";

// Execute the query

if (@mysql_query ($query))
{
print '<h3>User Successfully Created</h3>';
}

else
{
print "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>";
}


Thank you

Danny

grumpyoldtechs
11-11-2006, 04:44 AM
where is the script supposed to be getting the userid and id from?

i would have through the id would be an auto_increment INT in the database which you can completely remove from the script

dangillow
11-11-2006, 05:51 AM
where is the script supposed to be getting the userid and id from?

i would have through the id would be an auto_increment INT in the database which you can completely remove from the script

id is auto_increment. User ID concats id and a stored variable to create user_id which is follow after the insert. I dont think thats my problem? Or could it be?

Danny

grumpyoldtechs
11-11-2006, 06:59 AM
the id is a problem if thats your code you need to remove it from your script as its trying to assign nothing to ID. also your trying to assign nothing to user_id.

also you can have '{$_POST['id']}' as this '$_POST[id]'

finally i strongly suggest you don't directly put the POST global into an SQL script as it stands someone can drop your table with no more than a few words.

$fore_name = mysql_real_escape_string($_POST['forename']);