doforumda Posted January 30, 2010 Share Posted January 30, 2010 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 More sharing options...
jl5501 Posted January 30, 2010 Share Posted January 30, 2010 Your best solution is to have the html and the php in the same file, and then you can use the error loop in your code to set variables to control the colour of the the div tags Link to comment https://forums.phpfreaks.com/topic/190344-need-help-in-php/#findComment-1004174 Share on other sites More sharing options...
doforumda Posted January 30, 2010 Author Share Posted January 30, 2010 Your best solution is to have the html and the php in the same file, and then you can use the error loop in your code to set variables to control the colour of the the div tags how can use error loop for this purpose? you can modify my code Link to comment https://forums.phpfreaks.com/topic/190344-need-help-in-php/#findComment-1004179 Share on other sites More sharing options...
jl5501 Posted January 30, 2010 Share Posted January 30, 2010 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 More sharing options...
doforumda Posted January 30, 2010 Author Share Posted January 30, 2010 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 More sharing options...
doforumda Posted January 30, 2010 Author Share Posted January 30, 2010 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 More sharing options...
jl5501 Posted January 30, 2010 Share Posted January 30, 2010 in that case you need a different variable for each div and set those variables according to which div you want to change the colour of Link to comment https://forums.phpfreaks.com/topic/190344-need-help-in-php/#findComment-1004200 Share on other sites More sharing options...
jl5501 Posted January 30, 2010 Share Posted January 30, 2010 One other thing to point out. Although you can easily change the colour on the div that is wrong, normally, for security reasons, you would not indicate which of username or password was wrong. Link to comment https://forums.phpfreaks.com/topic/190344-need-help-in-php/#findComment-1004201 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.