Anything wrong?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Anything wrong?

Post by Parody »

Code: Select all

<?php
if(preg_match("/(\<|\>)/", $_POST['uname']) | preg_match("/(\<|\>)/")) {
		die('Invalid input, no tags /(/< or />/) are allowed in your username.');
		$test = strstr($email, '@');
if($test != false) 
{}
else{die('The email address you entered does not contain the /@ symbol.');
$rand = rand(10248765,99543547);
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("users") or die('Sorry, we are having database connection problems, please report this to an Administrator');
$regdate = date('m d, Y');
$qry = "INSERT INTO users (username, password, regdate, email) VALUES ('".$_POST['uname']."', '".$rand."', '".$regdate."', '".$_POST['email']."')";
mysql_query($qry)  or die(mysql_error());
mysql_query("INSERT INTO stats('".$_POST['uname']."','$chrctr', '100', '2000', '001', '01', 000, '01', '01', '01', '1', '0', '00000000', '00000000', '00000000', '00000000')");
mysql_close();
print "You successfully registered as('".$_POST['uname']."')";
?>
Any ideas?

I just get a parse error on the bottom line
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Re: Anything wrong?

Post by wwwapu »

Parody wrote:

Code: Select all

print "You successfully registered as('".$_POST['uname']."')";
try

Code: Select all

print 'You successfully registered as(\''.$_POST['uname'].'\')'; //escape
//or
print 'You successfully registered as(´'.$_POST['uname'].'´)';
//or
print 'You successfully registered as("'.$_POST['uname'].'")';
It seems like problems with quotemarks ' is "stronger" than ".
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

I still get the error,

Parse error on line 17
cbrian
Forum Commoner
Posts: 97
Joined: Sun Feb 27, 2005 12:29 pm

Post by cbrian »

i think your missing an ending } for the else {
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

All of the following are perfectly valid:

Code: Select all

print "You successfully registered as('".$_POST['uname']."')";

Code: Select all

print 'You successfully registered as("'.$_POST['uname'].'")';

Code: Select all

print 'You successfully registered as(\''.$_POST['uname'].'\')';

Code: Select all

print "You successfully registered as(\"".$_POST['uname']."\")";

Code: Select all

print "You successfully registered as('{$_POST['uname']}')";
' and " are interchangeable except " parses where ' doesn't.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I generally would never use die() unless it was a fatal error, so I frown on your use of it. However, this is what you want.

Code: Select all

if(preg_match("/(\<|\>)/", $_POST['uname'])) {
		die('Invalid input, no tags /(/< or />/) are allowed in your username.');
	}
	if (preg_match("^[a-z0-9\._-]+@([a-z0-9][a-z0-9-]*[a-z0-9]\.)+([a-z]+\.)?([a-z]+)^",$_POST['email'])) {
		die('Email Adress invalid.');
	}

	$rand = rand(10248765,99543547);
	mysql_connect("localhost", "username", "password") or die(mysql_error());
	mysql_select_db("users") or die('Sorry, we are having database connection problems, please report this to an Administrator');
	$regdate = date('m d, Y');
	$qry = "INSERT INTO users (username, password, regdate, email) VALUES ('".$_POST['uname']."', '".$rand."', '".$regdate."', '".$_POST['email']."')";
	mysql_query($qry)  or die(mysql_error());
	mysql_query("INSERT INTO stats('".$_POST['uname']."','$chrctr', '100', '2000', '001', '01', 000, '01', '01', '01', '1', '0', '00000000', '00000000', '00000000', '00000000')");
	mysql_close();
	print "You successfully registered as('".$_POST['uname']."')";
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

This is the page before, the form. For some reason when I click the submit button it wont proceed onto the next page :(

It just does nothing.

This is the code:

Code: Select all

<html>
<head>
<title>Register an Account</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css"
href="style.css" />
</head>
<body>
<h1 align="center">Please enter your preferable username and enter your email address.</h1>
 <form name="input" form action="registering2.php" method="post">
   <table border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="#FFFFFF">
     <tr>
       <td class="h1"><span class="style3">
         <h1>Username:</h1>
       </span></td>
       <td class="style5"><input type="text" name="uname" maxlength="20"></td>
     </tr>
     <tr>
       <td class="h1"><span class="style3">
         <h1>Email:</h1>
       </span></td>
       <td class="style5"><input type="text" name="email" maxlength="100"></td>
     </tr>
	 <tr>
       <td class="h1"><span class="style3">
         <h1>Character</h1>
       </span></td>
       <td class="style5"><input name="chrctr" type="text" id="chrctr" value="1" maxlength="2"></td>
     </tr>
  <tr bordercolor="#FFFFFF">
   </table> 
</form>
<h1 align="center">Choose a Display Picture and type its number into the space provided above </h1>
<div align="center">
  <table width="600" border="1">
    <tr>
      <td width="100"><img src="/characters/1.jpg" width="100" height="150"></td>
      <td width="100"><img src="/characters/2.jpg" width="100" height="150"></td>
      <td width="100"><img src="/characters/3.jpg" width="100" height="150"></td>
      <td width="100"><img src="/characters/4.jpg" width="100" height="150"></td>
      <td width="100"><img src="/characters/5.jpg" width="100" height="150"></td>
      <td width="108"><div align="center"><img src="/characters/6.jpg" width="100" height="150"></div></td>
    </tr>
    <tr>
      <td><h1 align="center">1</h1></td>
      <td><h1 align="center">2</h1>
      </td>
      <td><h1 align="center">3</h1>
        </td>
           <td><h1 align="center">4</h1>
        </td>
      <td><h1 align="center">5</h1>
        </td>
      <td><h1 align="center">6</h1>
      </td>
    </tr>
  </table>
  <p>&nbsp;</p>
<table width="600" border="1">
  <tr>
    <td width="100"><img src="/characters/7.jpg" width="100" height="150"></td>
    <td width="100"><img src="/characters/8.jpg" width="100" height="150"></td>
    <td width="100"><img src="/characters/9.jpg" width="100" height="150"></td>
    <td width="100"><img src="/characters/10.jpg" width="100" height="150"></td>
    <td width="100"><img src="/characters/11.jpg" width="100" height="150"></td>
    <td width="108"><img src="/characters/12.jpg" width="100" height="150"></td>
    <td width="108"><img src="/characters/13.jpg" width="100" height="150"></td>
  </tr>
  <tr>
    <td><h1 align="center">7 </h1>
     </td>
    <td><h1 align="center">8</h1>
      </td>
    <td><h1 align="center">9</h1>
      </td>
    <td><h1 align="center">10</h1>
      </td>
    <td><h1 align="center">11</h1>
      </td>
    <td><h1 align="center">12</h1>
      </td>
    <td><h1 align="center">13</h1>
      </td>
  </tr>
</table>
<p>&nbsp;</p>
</div>
<div align="center">
<div align="center">
  <input name="submit" type="submit" value="Sign Up">
</div><br>
</html>
Can anyone suggest any reason for this please :?:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Put your submit button inside the form.
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Jcart: I am having a slight problem with my email verification :(

Whenever I put in my own email address it displays email address not valid

Any ideas please :?:
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

then your regular expression is not valid id bet
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

:?: :?: :?: :?: :?: :?: What :?: :?: :?: :?: :?: :?:
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

err sorry you are not using a regular expression to match the email :oops: , don't strstr to do it, use strpos
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

I now have a parse error on line 6, but it is just:

Code: Select all

else{
This is the code at the moment:

Code: Select all

<?php
if(preg_match("/(\<|\>)/", $_POST['uname'])) {
        die('Invalid input, no tags < or > are allowed in your username.');
} 
if (preg_match("^[a-z0-9\._-]+@([a-z0-9][a-z0-9-]*[a-z0-9]\.)+([a-z]+\.)?([a-z]+)^",$_POST['email']))
else{
die{'Email Adress invalid, you entered: '.$_POST['email'].''};
}
$rand = rand(10248765,99543547);    
mysql_connect("localhost", "admin", "ak7456") or die(mysql_error());
mysql_select_db("users") or die('Sorry, we are having database connection problems, please report this to an Administrator');    
$regdate = date('m d, Y');
$chrctr =  $_POST['email'];   
$qry = "INSERT INTO users (username, password, regdate, email) VALUES ('".$_POST['uname']."', '".$rand."', '".$regdate."', '".$_POST['email']."')";    
mysql_query($qry)  or die(mysql_error());    
mysql_query("INSERT INTO stats('".$_POST['uname']."','$chrctr', '100', '2000', '001', '01', 000, '01', '01', '01', '1', '0', '00000000', '00000000', '00000000', '00000000')");    
mysql_close();    
print "You successfully registered as'".$_POST['uname']."'";
   ?>
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

your if statment above doesn't do anything if it is true. so your missing {} before your else statment.
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

I tried that just then, nothing different, can you write out the code you suggest, I may have misunderstood :oops:
Post Reply