Help with PHP
#1

Hi there, I dont really know if people would help as this isnt a PHP forum, but I think I should give it a go.

What I need help on:

Currently I am editing a register script which uses PHP, I basically got a source which I have been editing to work properly, and It is going well execpt, I want the 'Username' bar to work when this 'Firstname_Lastname' format is input into the textbox or else it returns a error saying:
"Please use this format: Firstname_Lastname" on the top of the page.

The next request is, I would like the register script to save password as a SHA1 hash instead of a text hash, How can I do that?


Thank you in advance, Riddy
Reply
#2

Hi, for the username you could use PHP eregi... Like this..

if(eregi("^[a-z]*_[a-z]", $username)){ // The username is in first_last format } else { // Error }

and for sha1 it is just sha1($password);
Reply
#3

What do I do with this:

$Username = $_POST['Username']; // Setting the user value

and

<? echo "Username: <input type='text' name='Username' /><br>"; ?>
Reply
#4

Quote:
Originally Posted by Riddy
Посмотреть сообщение
What do I do with this:

$Username = $_POST['Username']; // Setting the user value

and

<? echo "Username: <input type='text' name='Username' /><br>"; ?>
You will need always to take the data from the form, or the login / register system don't work.
Reply
#5

If I left the other to boxes empty, I need it to return as "Please put stuff in all the fields" and What about string limit?
Reply
#6

use isset() to determine if a variable contains a value. I don't think there's any particular string limit in PHP, at least not when POST'ing data. Also eregi is deprecated, use preg_match instead.
Reply
#7

Quote:
Originally Posted by Vince
Посмотреть сообщение
use isset() to determine if a variable contains a value. I don't think there's any particular string limit in PHP, at least not when POST'ing data. Also eregi is deprecated, use preg_match instead.
One problem, I really dont know how to use these things, so can you give me a example of the code your telling me to use please
Reply
#8

If you use the empty(never used it) function or '', it can help you out .
like
PHP код:
if(isset($_POST['user'] == "")) echo 'Please fill up the username field!';
else {
// continue the code

Or setup more than 1 $_POST on a if, like:
PHP код:
if(isset($_POST['user'] == '')||($_POST['password'] == '')||($_POST['e-mail'] == '')) echo 'Please fill up all fields.';
else {
// continue the code

Reply
#9

<?php
if ($username == null){
// The variable is blank..

} else {
// It is not blank..

}

?>

For string limit, if you mean allow only a certain limit, I'd just recommend putting maxlength="30" on the input (form) and limiting the length in the database.
Reply
#10

PHP код:
if(isset("Submit")) {
    
$Username $_POST['Username']; // Setting the user value
    
$Pass $_POST['Password']; // Setting the user value
    
if($Username == "/" || $Username == "\" || $Username == "_") {
      echo "
invalid"; exit;
    }
    mysql_query("
INSERT INTO table (namepassVALUES ($Username$Pass));
}
// Form with html
<form method "POST" action "index.php">
Username: <input type='text' name='Username' /><br>
Password: <input type='text' name='Password' /><br>
<
input type "submit" name "Submit" /> <br />
</
form
Its something like that, i'm not sure if this is right, check on www.******.com.br or w3schools about HTML and PHP scripting and your questions will be answered.


http://forum.sa-mp.com/showthread.ph...ighlight=MySQL

Check PHP part.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)