Jump to content

Making a signup page, trying to log all attempts


phpchick

Recommended Posts

Hi everybody, I want to build a script that lets someone register with a simple form that logs all activity into a MySQL db.

 

The thing is, I want to log all attempts to signup into the system even if they do not satisfy password strength, or the required fields criteria.

 

In the following code, the string "email" isn't being used. The field named 'name' is what I'm using to collect the email, and the field named 'msg' is what I'm using to collect the password.

 

I've gotten to the point where if they don't provide anything for either email or password, then it directs them to the same page and it asks them to re enter their information. but I can't seem to capture the attempt (so if they enter an email but not a pass, i still want to know what email they entered).

 

I'm getting this error

 

Parse error: syntax error, unexpected T_ELSE in /hermes/bosweb25c/b1454/ipg.domainname/nameofsite/contact_insert2.php on line 41

 

Line 41 corresponds to the line with the first "else{"

 

I'm really not sure what to do, it seems straight forward when I think it through in my head.

 

If pass or email field is empty, enter it into the db, and then send them back to the beginning, if pass or email field not empty, continue in script.

 


<?php

define('DB_NAME', 'dbname');
define('DB_USER', 'phpchick');
define('DB_PASS', 'password');
define('DB_HOST', 'localhost');

// contact to database
$connect = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Error , check your server connection.');
mysql_select_db(DB_NAME);
  
//Get data in local variable
$v_name=$_POST['name'];
$v_email=$_POST['email'];
$v_msg=$_POST['msg'];

// check for null values
if ($v_name==""  or $v_msg=="")
	$query="insert into contact(name,email,msg) values('$v_name','$v_email','$v_msg')";
	mysql_query($query)  or die(mysql_error());
														echo " 
														<head>      <link rel=\"stylesheet\" type=\"text/css\" href=\"http://site.com/signup.css\"></head>
														<h2>Free Registration</h2>
														<form action=\"contact_insert2.php\" method=\"POST\" id=\"insert\">
																  <table>
																			  <tr>
																						  <td >Email</td>
																						  <td  ><input type=\"text\" size=40 name=\"name\"></td>
																			  </tr>

																			  <tr>
																						  <td >Password</td>
																						  <td  ><input type=\"password\" size=40  name=\"msg\" ></td>
																			  </tr>
																			  You must enter an email and password.
																			  <tr>
																						  <td colspan=2 id=\"sub\"><input type=\"submit\" name=\"submit\" value=\"submit\" ></td>
																			  </tr>
																  </Table>
														</form>";
else{
	if (strcspn($_REQUEST['msg'], '0123456789') == strlen($_REQUEST['msg']))
			echo "true";
else{
	$query="insert into contact(name,email,msg) values('$v_name','$v_email','$v_msg')";
	mysql_query($query)  or die(mysql_error());
	echo "Your message has been received";
}
}
?>

 

Link to comment
Share on other sites

Your first error is right here "if ($v_name==""  or $v_msg=="")" look at the code below I fixed your errors and have given you with what you need.

 

<?php
define('DB_NAME', 'dbname');
define('DB_USER', 'phpchick');
define('DB_PASS', 'password');
define('DB_HOST', 'localhost');

// contact to database
$connect = mysql_connect( DB_HOST, DB_USER, DB_PASS ) or die( 'Error , check your server connection.' );
mysql_select_db( DB_NAME );
  
//Get data in local variable
$v_name = $_POST['name'];
$v_email = $_POST['email'];
$v_msg = $_POST['msg'];

 // check for null values
if( $v_name == "" || $v_msg == "" ) {
	$query = "INSERT INTO contact(name,email,msg) VALUES ('$v_name','$v_email','$v_msg')";
	$result = mysql_query( $query );

	if( !$result ) {
		die( mysql_error() );
	}

	echo <<<EOD
		<head>      
			<link rel="stylesheet" type="text/css" href="http://site.com/signup.css">
		</head>
		<h2>Free Registration</h2>
		<form action="contact_insert2.php" method="POST" id="insert">
			<table>
				<tr>
					<td>Email</td>
					<td ><input type="text" size="40" name="name"></td>
				</tr>
			    <tr>
					<td>Password</td>
					<td><input type="password" size="40"  name="msg" ></td>
				</tr>
				<tr>
					<td colspan=2 id="sub">
						You must enter an email and password. <br />
						<input type="submit" name="submit" value="submit">
					</td>
				</tr>
			</Table>
		</form>
EOD;
}
elseif( strcspn( $_REQUEST['msg'], '0123456789' ) == strlen( $_REQUEST['msg'] ) ) {
	echo "true";
}
else {
	$query = "INSERT INTO contact(name,email,msg) VALUES ('$v_name','$v_email','$v_msg')";
	mysql_query( $query );

	if( !$result ) {
		die( mysql_error() );
	}

	echo "Your message has been received";
}
?>

 

I don't want to sound rude by saying this but you need to read some more PHP tutorials you've made a decent amount of amateur mistakes but if your new to PHP its ok we've all wen't through it in the past.

 

I didn't verify your SQL statements so those may or may not be correct but the actual structure and design flow should work for you now.

Link to comment
Share on other sites

thank you minidak03, I am indeed pretty new at PHP.

 

I am trying to do a long nested if basically.

 

I still have to add the functionality that checks if the password is 8 characters minimum, if there is a capital letter, if there is a special character etc.

 

I planned on doing one long if, else, if else, if else, statement.

 

Is that the best way to do this?

 

Is there a maximum number of if else statements that can be nested?

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.