It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

Inputting into DB issues

Moderator: Malcolm

Inputting into DB issues

Postby dflynn on Tue Dec 16, 2008 5:02 pm

Hey guys,
I don't know why this isn't working for me. It is essentially a copy of another script I have working but scaled down.

I have form asking for email and name.
It runs it through the sign-up script.
I know the page is properly connected to the db because if I try to use the only email entry that exists in the db, it knows that it is being used.
The issue is somewhere withing the actual insert area of the code.

Code: Select all
<?
if(isset($todo) and $todo=="post"){

$status = "OK";
$msg="";

// if userid is less than 3 char then status is not ok
            
if(!isset($email) or strlen($email)<3){
$msg=$msg."You must enter an existing email address<BR>";
$status= "NOTOK";}

if(mysql_num_rows(mysql_query("SELECT email FROM newsletter WHERE email = '$email'"))){
$msg=$msg."Email already exists in our database. Thank-you for having signed up.<BR>";
$status= "NOTOK";}               


if(!isset($name) or strlen($name) <2){
$msg=$msg."Name should be at least 2 characters in length<BR>";
$status= "NOTOK";}

if ($agree<>"yes") {
$msg=$msg."You must agree to <a href=tandc.php>terms and conditions</a><BR>";
$status= "NOTOK";}   


if($status<>"OK"){
echo "<font face='Verdana' size='2' color=red>$msg</font><br><input type='button' value='Retry' onClick='history.go(-1)'>";
}else{ // if all validations are passed.
$query=mysql_query("insert into newsletter(email,name) values('$email','$name')");
echo "<font face='Verdana' size='2' color=green>Thank-you for signing-up, we will e-mail you for the launch of nnjoi.com. </font> <br /><br /><br /> <a href=index.php>Home</a>";
}
}
?>



and here is the form that inputs it:
Code: Select all
<span class="sub">Sign-up to keep up to date on nnjoi.com's launch date. </span><br />

<form name="form1" method="post" action="signupnews.php" onsubmit='return validate(this)'><input type=hidden name=todo value=post>
<table border=0 cellpadding="2px" cellspacing="2px" align="left" width="400px">

<tr><td>Email:</td><td><input name="email" type="text" size="17" maxlength="50" /></td></tr>

<tr><td>Name:</td><td><input name="name" type="text" size="17" maxlength="20" /></td></tr>

<tr><td>I agree to <a href="tandc.php target="_blank"">terms and conditions</a></td><td><input type=checkbox name=agree value='yes'></td></tr>

<tr><td></td><td><input type="submit" value="Submit" /></td></tr>

</table>
</form>
User avatar
dflynn
500+ Club
 
Posts: 860
Joined: Wed Oct 03, 2007 9:06 pm
Location: Guelph, Canada

Re: Inputting into DB issues

Postby webmaster on Tue Dec 16, 2008 6:48 pm

Try change the database field "name" to "username" or something, that might be the problem.
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden

Re: Inputting into DB issues

Postby dflynn on Tue Dec 16, 2008 9:35 pm

nope that didn't work. I changed all instances of 'name' to 'username', including the table in the db. any other ideas?
User avatar
dflynn
500+ Club
 
Posts: 860
Joined: Wed Oct 03, 2007 9:06 pm
Location: Guelph, Canada

Re: Inputting into DB issues

Postby Johnathan on Tue Dec 16, 2008 9:47 pm

Try making the "insert into" here $query=mysql_query("insert into newsletter(email,name) to INSERT INTO

EDIT

Put a space after the comma before name.
Johnathan
1000+ Club
 
Posts: 1207
Joined: Thu May 31, 2007 3:28 pm
Location: Belfast, Northen Ireland

Re: Inputting into DB issues

Postby dflynn on Tue Dec 16, 2008 9:53 pm

No luck,

Here is the code for the working signup script:

Code: Select all
<?
if(isset($todo) and $todo=="post"){

$status = "OK";
$msg="";

// if userid is less than 3 char then status is not ok
if(!isset($userid) or strlen($userid) <3){
$msg=$msg."User id should be =3 or more than 3 char length<BR>";
$status= "NOTOK";}               

if(mysql_num_rows(mysql_query("SELECT username FROM member WHERE username = '$userid'"))){
$msg=$msg."User already exists. Please try another Username<BR>";
$status= "NOTOK";}               


if ( strlen($password) < 3 ){
$msg=$msg."Password must be more than 3 char length<BR>";
$status= "NOTOK";}               

if ( $password <> $password2 ){
$msg=$msg."Passwords do not match, please try again.<BR>";
$status= "NOTOK";}               


if ($agree<>"yes") {
$msg=$msg."You must agree to terms and conditions<BR>";
$status= "NOTOK";}   

if($status<>"OK"){
echo "<font face='Verdana' size='2' color=red>$msg</font><br><input type='button' value='Retry' onClick='history.go(-1)'>";
}else{ // if all validations are passed.
$salt = md5($password);
$mdpass = md5($salt.$password);
$query=mysql_query("insert into member(username,password,email,name) values('$userid','$mdpass','$email','$name')");
echo "<font face='Verdana' size='2' color=green>Welcome, You have successfully signed up<br><br><a href=login.php>Click here to login</a><br></font>";
}
}
?>



And the table with the form:
Code: Select all

<span class="sub">Sign-up</span><br />

<form name="form1" method="post" action="signup2.php" onsubmit='return validate(this)'><input type=hidden name=todo value=post>
<table border=0 cellpadding="2px" cellspacing="2px" align="left" width="400px">
<tr><td>Username:</td><td><input name="userid" type="text" size="17" maxlength="20" /></td></tr>

<tr><td>Password:</td><td><input name="password" type="text" size="17" maxlength="20" /></td></tr>

<tr><td>Re-enter Password:</td><td><input name="password2" type="text" size="17" maxlength="20" /></td></tr>

<tr><td>Email:</td><td><input name="email" type="text" size="17" maxlength="50" /></td></tr>

<tr><td>Name:</td><td><input name="name" type="text" size="17" maxlength="20" /></td></tr>

<tr><td>I agree to terms and conditions</td><td><input type=checkbox name=agree value='yes'></td></tr>

<tr><td></td><td><input type="submit" value="Submit" /></td></tr>

</table>
</form>
User avatar
dflynn
500+ Club
 
Posts: 860
Joined: Wed Oct 03, 2007 9:06 pm
Location: Guelph, Canada

Re: Inputting into DB issues

Postby dflynn on Tue Dec 16, 2008 11:04 pm

Ok! So I decided to scrap the table in the db, and rebuild the form. Now it seems to be working with no real changes. Who knows why, but it is. If some of you wouldn't mind doing me a favour and sign up at:
nnjoi.com. If you really don't want to be emailed just sign up with a name of "dontemail" or something like that and I'll take it off the db, just want to make sure it's working.

Thanks :D
User avatar
dflynn
500+ Club
 
Posts: 860
Joined: Wed Oct 03, 2007 9:06 pm
Location: Guelph, Canada


Who is online

Users browsing this forum: No registered users and 1 guest