Jump to content

Hlp With Code not sure wats wrong


LearningKid

Recommended Posts

Hi this code used to work and now im not sure y it isnt workin can anyone hlp me plz

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>luCa Prints Sign Up</title>
<Style>
BODY, P,TD{ font-family: Arial,Verdana,Helvetica, sans-serif; font-size: 10pt }
A{font-family: Arial,Verdana,Helvetica, sans-serif;}
B {	font-family : Arial, Helvetica, sans-serif;	font-size : 12px;	font-weight : bold;}
.error_strings{ font-family:Verdana; font-size:10px; color:#660000;}
</Style>
<script language="JavaScript" src="gen_validatorv31.js" type="text/javascript"></script>
</head>
<body>


<form name="myform" ACTION="regi.php" METHOD=get>
<table cellspacing="2" cellpadding="2" border="0" align="center">
<tr>
    <td align="right">*Username</td>
    <td><input type="text" name="username"></td>
</tr>
<tr>
    <td align="right">*Password</td>
    <td><input type="password" name="password1"></td>
</tr>
<tr>
    <td align="right">*Re-enter Password</td>
    <td><input type="password" name="password2"></td>
</tr>
<tr>
    <td align="right">*First Name</td>
    <td><input type="text" name="FirstName"></td>
</tr>
<tr>
    <td align="right">*Last Name</td>
    <td><input type="text" name="LastName"></td>
</tr>
<tr>
    <td align="right">Company</td>
    <td><input type="text" name="company"></td>
</tr>
<tr>
    <td align="right">Position</td>
    <td><input type="text" name="position"></td>
</tr>
<tr>
    <td align="right">*EMail</td>
    <td><input type="text" name="Email"></td>
</tr>
<tr>
    <td align="right">*Re-enter EMail</td>
    <td><input type="text" name="Email1"></td>
</tr>
<tr>
    <td align="right">*Daytime Number</td>
    <td><input type="text" name="Phone"></td>
</tr>
<tr>
    <td align="right">Other Number</td>
    <td><input type="text" name="Phone2"></td>
</tr>
<tr>
    <td align="right">*Address</td>
    <td><textarea cols="20" rows="5" name="Address"></textarea></td>
</tr>
<tr>
    <td align="right">*City</td>
    <td>
   <SELECT name="City">
	<option value="" selected>[choose yours]
	<option>Parika
	<option>Georgetown
	<option>New Amsterdam
	</SELECT>
</td>
</tr>
<tr>
    <td align="right">*County</td>
    <td>
   <SELECT name="County">
	<option value="" selected>[choose yours]
	<option>Essequibo
	<option>Demerara
	<option>Berbice
	</SELECT>
</td>
</tr>
<tr>
    <td align="right">*Security Question</td>
    <td>
   <SELECT name="sec_ques">
	<option value="" selected>[choose yours]
	<option>What is my name?
	<option>Where do I live?
	<option>My Favourite Pet
	</SELECT>
</td>
</tr>

<tr>
    <td align="right">*Answer</td>
    <td><input type="password" name="sec_ans"></td>
</tr>
<tr>
    <td align="right"><input type="checkbox" name="ckb"></td>
    <td>Please check here if you would like to receive special offers,<br>notification of valuable promotions via company mailings,<br>email contact, telemarketing, catalogues, etc., from us.<br>(Note: You can unsubscribe at any time.)</td>
</tr>
<tr>
    <td align="right"><input type="checkbox" name="ckb2"></td>
    <td>Please check here if you are a business customer</td>
</tr>

<tr>
    <td align="right"></td>
    <td>
<div id='myform_errorloc' class='error_strings'>
                              </div>
</td>
</tr>
<tr>
    <td align="right"></td>
    <td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
<script language="JavaScript" type="text/javascript">
//You should create the validator only after the definition of the HTML form
  var frmvalidator  = new Validator("myform");
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();
  
  frmvalidator.addValidation("username","req","Please enter your Username");
  frmvalidator.addValidation("username","maxlen=20","For Username, Max length is 20");
  
  frmvalidator.addValidation("FirstName","req","Please enter your First Name");
  frmvalidator.addValidation("FirstName","maxlen=30",	"Max length for FirstName is 30");
  frmvalidator.addValidation("FirstName","alpha_s","Name can contain alphabetic chars only");
  
  frmvalidator.addValidation("LastName","req","Please enter your Last Name");
  frmvalidator.addValidation("LastName","maxlen=40","For LastName, Max length is 40");
  
  frmvalidator.addValidation("Email","maxlen=100");
  frmvalidator.addValidation("Email","req");
  frmvalidator.addValidation("Email","email");
  
  frmvalidator.addValidation("Phone","maxlen=11");
  frmvalidator.addValidation("Phone","numeric");
  frmvalidator.addValidation("Phone","req","Please Enter a Daytime Number");
  frmvalidator.addValidation("City","req");  
  frmvalidator.addValidation("Address","maxlen=50");
  frmvalidator.addValidation("County","req","Please select your County");
  frmvalidator.addValidation("sec_ques","req","Please enter your Security Question");
  frmvalidator.addValidation("sec_ans","req","Please enter your Answer");
  
 function DoCustomValidation()
{
  var frm = document.forms["myform"];
  if(frm.FirstName.value == 'Anil')
  {
    sfm_show_error_msg("Anil, you can't submit this form. Go away! ");
    return false;
  }
  else
  {
    return true;
  }
}

  frmvalidator.setAddnlValidationFunction("DoCustomValidation");
</script>


</body>
</html>

 

leads to

 

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="customers"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

if($_GET["username"] && $_GET["password1"] && $_GET["password2"] && $_GET["FirstName"] && $_GET["LastName"] && $_GET["Email"] && $_GET["Email1"]
&& $_GET["Phone"] && $_GET["Phone2"] && $_GET["Address"] && $_GET["County"] && $_GET["City"] && $_GET["sec_ques"] 
&& $_GET["sec_ans"] )
{
  $sql=mysql_query("SELECT * FROM customers WHERE username='$_GET[username]', ");
$result = mysql_fetch_row($sql);
if($result==0){

  
   if($_GET["password1"]==$_GET["password2"])
    {
     if ($_GET["Email"]==$_GET["Email1"]) 
      {
   
    $servername="localhost";
      $username="root";
      $conn=  mysql_connect($servername,$username)or die(mysql_error());
      mysql_select_db("test",$conn);
      $sql="insert into customers (username,password,email,first_name,last_name,county,city,street_address,tel_number,second_number,security_quest,security_answer)
      values('$_GET[username]','$_GET[password1]','$_GET[FirstName]','$_GET[LastName]','$_GET[Email]',
      '$_GET[Phone]','$_GET[Phone2]','$_GET[Address]','$_GET[County]','$_GET[City]','$_GET[sec_ques]', 
      '$_GET[sec_ans]')";
      $result=mysql_query($sql,$conn) or die(mysql_error());		
      print "<h1>you have registered sucessfully</h1>";
   
      print "<a href='login.php'>go to login page</a>";
   }
      else print "Email doesnt match";
   }
    else print "passwords doesnt match";
  }
   else print "username already in use please select another";
}
   else print "try again";

$query = "SELECT * FROM customers order by id DESC LIMIT 0, 1";     //Assuming your ID is set to id  
$result = mysql_query($query) or die(mysql_error());
     while($row = mysql_fetch_array($result)){
            $users_id = $row['id'];   
     }
?>

Link to comment
https://forums.phpfreaks.com/topic/183124-hlp-with-code-not-sure-wats-wrong/
Share on other sites

1. check to make sure username is not in use.

2. make sure a password1, password2, first name, last night, email1, email2, phone1, phone2, address, county, city and questions actually has values in the input fields when submitting

 

but most likely, this line is why it doesnt work:

$sql=mysql_query("SELECT * FROM customers WHERE username='$_GET[username]', ");

 

make it

$sql=mysql_query("SELECT * FROM customers WHERE username='$_GET[username]'");

 

 

also this script is very unsafe, js.

When i said the script is unsafe, "just saying"  :P. I didn't mean javascript

 

You're getting "Try Again" when the page is first loaded because you are checking for $_GET variables even when the form is not submitted.

 

-----------

 

Here's what you need to do  - use $_POST instead of $_GET.

 

Change form method to "post"

 

then change all $_GET to $_POST.

 

give the submit button a name ( <input type="submit" name="submit" value="Submit"> )

 

And then, before this line:

if($_GET["username"] && $_GET["password1"] && $_GET["password2"] && $_GET["FirstName"] && $_GET["LastName"] && $_GET["Email"] && $_GET["Email1"]
&& $_GET["Phone"] && $_GET["Phone2"] && $_GET["Address"] && $_GET["County"] && $_GET["City"] && $_GET["sec_ques"] 
&& $_GET["sec_ans"] )

 

(which you will have changed $_GET to $_POST), add this:

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

 

and at the end of the script, right before the ?>, add a  }

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.