SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can any body check my php program and remove the errors pls

    <?
    session_start();
    ?>
    <?

    $conn = mysql_connect('84.91.36.55','test1','321321');
    mysql_select_db('test1');


    if(isset($_POST['submit']))
    {


    if(isset($_POST['username']) && $_POST['username'] == '')
    {
    $err_user='<em>enter user name<em>';
    }

    if(isset($_POST['password']) && $_POST['password'] == '' )
    {
    $err_paswd = '<em>Enter password<em>';
    }

    if(isset($_POST['fullname']) && $_POST['fullname']=='')
    {
    $err_fulln='<em>Enter Fullname<em>';
    }
    if ($_POST['password'] != $_POST['password1'] )
    {
    $err_passw2='Password entered in both field are Not Same';
    }

    if(isset($_POST['captcha_code']) && isset($_SESSION['captcha_code']))
    {
    if(md5($_POST['captcha_code']) != $_SESSION['captcha_code'])
    {
    $err_captc='<em>Enter The Correct code<em>';
    }
    }
    if(isset($_POST['captcha_code']) && $_POST['captcha_code']=='')
    {
    $err_captc1='<em>No security code was entered.<em>';
    }
    if(!isset($_SESSION['captcha_code']))
    {
    $err_captc2='No CAPTCHA was viewed';
    }

    $qry = 'SELECT `id` FROM `userl` WHERE `username` = "'. mysql_escape_string( $_POST['username'] ).'"';
    $res = mysql_query($qry);
    $num = mysql_num_rows($res);

    if ( $num )
    {
    $err_user1='<em>This username already exists<em>';

    }

    else
    {

    $int_user = '';
    $sql = 'insert into userl (fullname,username,password,password1,address,email) values("'.$_POST['fullname'].'","'.$_POST['username'].'","'.md5($_POST['password']).'","'.$_POST['password1'].'","'.$_POST['address'].'","'.$_POST['email'].'")';

    //if ( $_POST['password'] == $_POST['password1'] )
    //{}
    // else{

    //$err_passw2='Password entered in both field are Not Same';
    //}
    $int_user = mysql_query($sql);



    $headers = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "From: 'Alboom.com'\r\n";
    $to = $_POST['email'];

    $subject = "Conformation mail from Alboom website registration";
    $body = "
    <html>
    <head>
    <title>REGISTRATION DETAILS FOR CONFORMATION </title>
    </head>
    <body>
    <p>THANK YOU for registering in our site akhbaralboom!!!!!!</p>
    <center><p><b>REGISTRATION DETAILS</b></p></center>
    <p>Username:".$_POST['username']."</p>
    <p>Address:".$_POST['address']."</p>
    <p>Email:".$_POST['email']."</p>
    </body>
    </html>";
    ini_set("sendmail_from","denny@jazirasoft.com");
    ini_set("SMTP","webmail.jazirasoft.com");
    if(mail($to,$subject,$body,$headers))
    {
    echo '<center><b>Conformation mail has been send to ur Email !!! THANKYOU FOR THE REGISTRATION</b></center>';
    echo '<br>';
    echo '<center><b>****************Have a nice day*****************</b></center>';
    echo '<center><img src = "thank.jpg"/></center>';
    }
    else
    {
    echo 'email not sent';
    }


    if($int_user>0)
    {

    echo '<script>';
    echo 'window.location = "index.php"';
    echo '</script>';

    }

    }
    }


    ?>






    <!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=iso-8859-1" />
    <title>Registration Page</title>
    <script type="text/javascript">

    var RE_EMAIL = /^(\w+[\-\.])*\w+@(\w+\.)+[A-Za-z]+$/;


    function validate(form){
    var email = form.Email.value;
    var errors = [];

    if (!RE_EMAIL.test(email)) {
    errors[errors.length] = "You must enter a valid email address.";
    }
    if (errors.length > 0) {
    reportErrors(errors);
    return false;
    }

    return true;
    }


    function reportErrors(errors){
    var msg = "There were some problems...\n";
    for (var i = 0; i<errors.length; i++) {
    var numError = i + 1;
    msg += "\n" + numError + ". " + errors[i];
    }
    alert(msg);
    }
    </script>
    </head>

    <body>
    <form name='regform' action="" method="post" onsubmit="return validate(this);">
    <table width="55%" height="632" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td width="22%"></td>
    <td colspan="2"><b>
    <h3><u>Enter Details Below</u></h3></b></td>
    </tr>
    <tr>
    <td><b>Full Name/b></td><td width="35%"><input type="text" name="fullname" value="<?=$_POST['fullname']?>" maxlength="100" /></td><td width="18%"><? echo $err_fulln;?></td>
    </tr>
    <tr>
    <td><b>Username/b></td><td><input type="text" name="username" value="<?=$_POST['username']?>" maxlength="100" /></td><td><? echo $err_user;?></td><td width="25%"><? echo $err_user1;?></td>
    </tr>
    <tr>
    <td><b>Password/b></td><td><input type="password" name="password" value="<?=$_POST['password']?>" maxlength="10" /></td><td><? echo $err_paswd;?></td>
    </tr>
    <tr>
    <td><b>Re-Enter Password/b></td><td><input type="password" name="password1" value="" maxlength="10" /></td><td><? echo $err_passw2;?></td>
    </tr>
    <tr>
    <td><b>Address/b></td><td ><textarea name="address" value="<?=$_POST['address']?>" cols="25" rows="4" ></textarea></td></td><td>&nbsp;</td>
    </tr>
    <tr>
    <td><b>Email/b></td><td><input type="text" name="email" /><input type="hidden" name="action" value="send" /></td><td>&nbsp;</td>
    </tr>
    <tr>
    <td></td><td><img src="sa29.php" /><? echo $err_captc2 ;?>
    &nbsp;&nbsp;&nbsp;<input type="submit" name="change" value="change" /></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td><b>Enter Security Code/b></td><td><input type="text" name="captcha_code" /></td><td><? echo $err_captc;?><? echo $err_captc1;?></td>
    </tr>
    <tr>
    <td></td><td><input type="submit" name="submit" value="submit" />&nbsp;&nbsp;<input type="reset" name="reset" value="Reset" /></td>
    <td>&nbsp;</td>
    </tr>

    </table>
    </form>
    </body>
    </html>


    hello pls help me in this program i am not getting an error while both password r not same ,but the thing is that the error will show when the username entry will be having an error pls remove my difficulty. and if u can pls assign a nice css style sheet for my page

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Please use the appropriate code tags around your code when posting. It makes it much easier to read it.

    First thing I notice, is you do all kind of checks on the form input, and then you always insert a new line in your database, and send an email. You really should only insert and send when everything is ok.

    Secondly, always pass user input through mysql_real_escape_string() to prevent SQL injection:
    Code PHP:
    $sql = "
      INSERT INTO userl (fullname, username, password, password1, address, email) 
      VALUES('" . mysql_real_escape_string($_POST['fullname']) . "',
             '" . mysql_real_escape_string($_POST['username']) . "',
             '" . md5($_POST['password']) . "',
             '" . mysql_real_escape_string($_POST['password1']) . "',
             '" . mysql_real_escape_string($_POST['address']) . "',
             '" . mysql_real_escape_string($_POST['email']) . "')";
    May I ask why you save password1 as well in your database?

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but no use its not combaring the password field and giving the error hello any 1 pls help me

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Do a
    PHP Code:
    print_r($_POST); 
    at the top of the script and post the result here.

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello friend i got the outp put like

    Array ( [fullname] => her [username] => her [password] => he [password1] => we [address] => hello [email] => d@ya.co [action] => send [captcha_code] => 065gk [submit] => submit )

    but its not giving error for the password comparison

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Put an echo inside the if where you check the two passwords, to see if the script passes there:
    PHP Code:
    if ($_POST['password'] != $_POST['password1'] ) {
      
    $err_passw2 'Password entered in both field are Not Same';
      echo 
    "does it pass here?";  // debug echo, to be deleted after debugging

    Do the other error messages display ok? Like when you don't insert a user name?

  7. #7
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i found sme thing while i remove the

    if($int_user>0)
    {

    echo '<script>';
    echo 'window.location = "index.php"';
    echo '</script>';

    }

    this statement and giving print_r($_post) its echoing the error i dont know why? but i need the above statement also and the password comparison also pls check it

  8. #8
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by kuttus011 View Post
    but i need the above statement
    Why? What does it do?

  9. #9
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i dont know please verify my progam i am getting mad i am not getting where the error is why its not echoing the error pls check the if ststemnts made by me is right or not

  10. #10
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by kuttus011 View Post
    i dont know
    You don't know what it does or why you need it, but you need it?

    Come on. It's javascript. I don't know what it does. It might do a redirect to index.php, thus losing all variables you set. I don't know. You should. Otherwise it might be a good idea to look it up, or ask in the JS forum.


    Do the other error messages display ok? Like when you don't insert a user name?
    And you might want to answer the questions I ask trying to help you, instead of begging again and again for ppl to correct your script. You could also hire a programmer, you know

    Ah, btw, did you try the echo statement, like I told you?

  11. #11
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i know tht its redirecting the page but only for the password comparison it is not showing evry else its echoing so what will be the problem

  12. #12
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no body cant solve my problem

  13. #13
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Why? What does it do?
    I assume it should redirect the user if the registration was succesful. Meaning that when mysql resource from the insert returned true (user was inserted to db) else it would return false. In this case you can check it just like this:
    PHP Code:
    if ($int_user)
    {
       
    // user was inserted.

    Also I don't understand why you mix up js and php so much. You could do the redirect with php too:
    PHP Code:
    if ($int_user)
    {
       
    header('Location: reg_succesful.php'); // ..whatever page you want.

    Some notes I made also that you save password and password1 to db when registration was succesful. If they are the same (as they are when reg success) you only need to save on of them. And I prefer using <?php ?> instead short tags, those might not work if you change host.

    Conclusion your code and explanation is quite a mess. And probably nobody is interested in coding you css layout just for fun unless you hire someone to do it.

    As guido2004 already guided you, use print_r or var_dump to debug what is actually inside $_POST variables and see it by yourself if they match or don't match. And then try figuring out whats wrong.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •