fixing a signup script

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

Post Reply
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

fixing a signup script

Post by m2babaey »

Hi
This signup script is ok on local but is having problem on the host.
Can you help me? the link is http://takfekr.com/testregister.php
thanks
code but user, pass
the first error is
A database error occurred in processing checking your '.
'submission.\\nIf this error persists, please '.
'contact m2babaeyt@yahoo.com
and if i remove that part of code, "no database selected

Code: Select all

<?php // signup.php

include("head.php");
include("common.php");

function pak($chars){
$chars= mysql_real_escape_string($chars);
$chars= htmlspecialchars($chars);

return $chars;
}

if (!isset($_POST['submit'])):
    // Display the user signup form
    ?>
<!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
</head>
<body>



    <p align=right>
<font color="orangered" size="+1"><tt><p align=right><b></b></tt></font>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
  <br>  <br>  <br><p align=center>
 name
  <br><input name="name" type="text" dir=rtl maxlength="100" size="25" /><br>  
   email
<br><input name="email" type="text"  maxlength="100" size="25" dir=ltr /><br>

state
<br><input name="state" type="text" dir=rtl maxlength="100" size="25" /><br><br>
city
<br><input name="city" type="text" dir=rtl maxlength="100" size="25" /><br><br>

username
<br><input name="username" type="text" maxlength="100" size="25" dir=ltr /><br>

<br>
password
<br><input name="pass" type="password"  maxlength="100" size="25" dir=ltr /><br>


<br>
password again
<br><input name="pass2" type="password" maxlength="100" size="25" dir=ltr /><br>

<br>

  <input type="submit" name="submit" value="  register " />
</form>

</body>
</html>

    <?php
  
else:
 mysql_connect('localhost', 'username', 'pass');
    mysql_select_db('articles');
  $_POST['pass']=md5($_POST['pass']);
  $_POST['pass2']=md5($_POST['pass2']);
    $_POST['name']=pak($_POST['name']);
    $_POST['username']=pak($_POST['username']);
    $_POST['pass']=pak($_POST['pass']);
    $_POST['pass2']=pak($_POST['pass2']);
    $_POST['city']=pak($_POST['city']);
    $_POST['state']=pak($_POST['state']);
    // Process signup submission
   

    if ($_POST['name']=='' or $_POST['username']=='' or $_POST['pass']==''
      or $_POST['pass2']=='') {
        error('please enter name,username & passwords');
    }
    // this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) 
error('passwords don not match');

    // Check for existing user with the new id
    $sql = "SELECT COUNT(*) FROM `user` WHERE `username` = '$_POST[username]'";
    $result = mysql_query($sql);
    if (!$result) {	
        error('A database error occurred in processing checking your '.
              'submission.\\nIf this error persists, please '.
              'contact m2babaeyt@yahoo.com.');
    }
    if (mysql_result($result,0,0)>0) {
        error('username already taken');
    }
    

    mysql_query("INSERT INTO member(name, email, state, city, username, password) VALUES('$_POST[name]', '$_POST[email]', '$_POST[state]','$_POST[city]','$_POST[username]','$_POST[pass]' ) ") 
or die(mysql_error());  
    
    
    
             
              
            
    if (!mysql_query($sql))
        error('A database error occurred in processing your '.
              'submission.\\nIf this error persists, please '.
              'contact m2babaeyt@yahoo.com.\\n' . mysql_error());
              
    // Email the new password to the person.

         
    ?>
    <!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>
      <title> Registration Complete </title>
      <meta http-equiv="Content-Type"
        content="text/html; charset=utf-8" />
    </head>
    <body>
    <p ><strong>Success</strong></p>
    <p>
    </body>
    </html>
    <?php
endif;

?>
dirkr
Forum Newbie
Posts: 20
Joined: Sat Jul 07, 2007 2:55 pm

Post by dirkr »

try doing a die() on your mysql_connect() to see if it actually connect..
mayb the sql server of your webhost isnt hosted local ( localhost ) or you got a wrong password/login

so try mysql_connect('localhost','username','password') or die(mysql_error());

this will print out a errormessage if it fails to connect and login to the sql server
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Post by m2babaey »

Access denied for user 't44kf3ar_javad'@'localhost' to database 'articles
but when I copy the

Code: Select all

mysql_connect('localhost', 't44kf3ar_javad', 'pass')or die(mysql_error());
on http://takfekr.com/data.php, it sends no error
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Post by m2babaey »

but when I add the select db it says access denied!
I have added the user to the database with all previlages. :? :?
Maybe I should contact my host
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I'm actually not sure how meta tags affect php scripts since they are basically headers.. but..

Code: Select all

 <meta http-equiv="Content-Type" 
    content="text/html; charset=utf-8
You're missing a "> or a " /> on that line.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply