Jump to content

Need help in php


doforumda

Recommended Posts

hi

 

i have a register page. what i want in this page is when user enters his username and password and if that user does exist or he does not provide username or password then i want that php script to change the color border of that username or password div tags. how this can be done?

 

my code is here

register.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="register.php">
  <div>
    <label>username:</label>
      <input type="text" name="username" id="username" />
   </div> 
  <div>
    <label>password:</label>
      <input type="text" name="password" id="password" />
  </div> 
  <div>
      <input type="submit" name="submit" id="submit" value="Register" />
    </div>
</form>
</body>
</html>

 

register.php

<?php
$submit = $_POST['submit'];

$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);

if($submit){
if($username&&$password){
	$connect = mysql_connect("localhost","user","pass");
   		mysql_select_db("db");
   		$emailcheck = mysql_query("SELECT username FROM users WHERE username='$username'");
   		$count = mysql_num_rows($emailcheck);
   				
   		if($count == 0){
		$reg = mysql_query("INSERT INTO users VALUES (' ','$username','$password')");
		echo "You register successfully.";
   		}
}
else
	echo "Please Fill in username and password fields.";
}
?>

 

please help

Link to comment
https://forums.phpfreaks.com/topic/190344-need-help-in-php/
Share on other sites

This should give you the idea of what you need to do, based on your code.

 

Remember that there is just one file now - register.php

 

<?php
$bordercol = '#000';
if(isset($_POST['submit']))
{
$submit = $_POST['submit'];
$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);
if($submit)
{
	if($username&&$password)
	{
		$connect = mysql_connect("localhost","user","pass");
		mysql_select_db("db");
		$emailcheck = mysql_query("SELECT username FROM users WHERE username='$username'");
		$count = mysql_num_rows($emailcheck);
		if($count == 0)
		{
			$reg = mysql_query("INSERT INTO users VALUES (' ','$username','$password')");
			echo "You register successfully.";
		}
	}
	else
	{
		echo "Please Fill in username and password fields.";
		$bordercol = '#660';
	}
}
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="register.php">
<div style="border:1px solid <?php echo $bordercol;?>">
<label>username:</label>
<input type="text" name="username" id="username" />
</div>
<div style="border:1px solid <?php echo $bordercol;?>">
<label>password:</label>
<input type="text" name="password" id="password" />
</div>
<div>
<input type="submit" name="submit" id="submit" value="Register" />
</div>
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/190344-need-help-in-php/#findComment-1004180
Share on other sites

This should give you the idea of what you need to do, based on your code.

 

Remember that there is just one file now - register.php

 

<?php
$bordercol = '#000';
if(isset($_POST['submit']))
{
$submit = $_POST['submit'];
$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);
if($submit)
{
	if($username&&$password)
	{
		$connect = mysql_connect("localhost","user","pass");
		mysql_select_db("db");
		$emailcheck = mysql_query("SELECT username FROM users WHERE username='$username'");
		$count = mysql_num_rows($emailcheck);
		if($count == 0)
		{
			$reg = mysql_query("INSERT INTO users VALUES (' ','$username','$password')");
			echo "You register successfully.";
		}
	}
	else
	{
		echo "Please Fill in username and password fields.";
		$bordercol = '#660';
	}
}
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="register.php">
<div style="border:1px solid <?php echo $bordercol;?>">
<label>username:</label>
<input type="text" name="username" id="username" />
</div>
<div style="border:1px solid <?php echo $bordercol;?>">
<label>password:</label>
<input type="text" name="password" id="password" />
</div>
<div>
<input type="submit" name="submit" id="submit" value="Register" />
</div>
</form>
</body>
</html>

 

well this works but there is a problem with this. when i do not write username it changes the color of both divs what i want is when one is thing is not provided then it should change that praticular boarder color not both.

Link to comment
https://forums.phpfreaks.com/topic/190344-need-help-in-php/#findComment-1004185
Share on other sites

now i change my code but it still has the same problem

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register</title>
</head>
<body>
<?php
$bordercol = '#09C';
if(isset($_POST['submit']))
{
   $submit = $_POST['submit'];
   $username = strip_tags($_POST['username']);
   $password = strip_tags($_POST['password']);
   if($submit)
   {
      if($username)
      {
	  if($password) {
         	$connect = mysql_connect("localhost","user","pass");
         	mysql_select_db("db");
         	$emailcheck = mysql_query("SELECT username FROM users WHERE username='$username'");
         	$count = mysql_num_rows($emailcheck);
         	if($count == 0)
         	{
            	$reg = mysql_query("INSERT INTO users VALUES (' ','$username','$password')");
            	echo "You register successfully.";
         	}
	  }
		else {
			echo "Please Fill in password";
         		$bordercol = '#F00';
		}
      }
      else
      {
         echo "Please Fill in usernam";
         $bordercol = '#F00';
      }
   }
}
?>
<form id="form1" name="form1" method="post" action="register.php">
<div style="border:1px solid <?php echo $bordercol;?>">
   <label>username:</label>
   <input type="text" name="username" id="username" />
</div>
<div style="border:1px solid <?php echo $bordercol;?>">
   <label>password:</label>
   <input type="text" name="password" id="password" />
</div>
<div>
   <input type="submit" name="submit" id="submit" value="Register" />
</div>
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/190344-need-help-in-php/#findComment-1004196
Share on other sites

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.