Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


problem with my php

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
deleted user 111213
Grandmaster Cheater
Reputation: 0

Joined: 09 Nov 2007
Posts: 714

PostPosted: Fri Oct 31, 2008 4:05 am    Post subject: problem with my php Reply with quote

i have two files so someone can register to my website

this is register.php
Code:
<?php
include_once("functions.php");

connect();

if(!$_POST['submit']){
   echo "<table border='0' cellspacing='0' cellpadding='0'>";
   echo "<form method='post' action='register.php'>";
   echo "<tr><td colspan='2' align='center'>Registration Form</td></tr>";
   echo "<tr><td>Username:</td><td><input type='text' name='username'></td></tr>";
   echo "<tr><td>Password:</td><td><input type='password' name='password'></td></tr>";
   echo"<tr><td>Confirm:</td><td><input type='password' name='passconf'></td></tr>";
   echo "<tr><td>E-mail:</td><td><input type='text' name='email'></td></tr>";
   echo "<tr><td>Name:</td><td><input type='text' name='name'></td></tr>";
   echo "<tr><td colspan='2' align='center'><input type='submit' name='submit' value='Register'></td></tr>";
   echo "</form><table>";
}else {
   $username = protect($_POST['username']);
   $password = protect($_POST['password']);
   $confirm = protect($_POST['passconf']);
   $email = protect($_POST['email']);
   $name = protect($_POST['name']);
   
   $errors = array();
   
      if(!$username){
         $errors[] = "username is not defined";
      }
      if(!$password){
         $errors[] = "password is not defined";
      }
      if($password){
         if(!$confirm){
            $erroes[] = "confirmation password is not defined";
         }
      }
      if(!$email){
         $errors[] = "email is not defined";
      }
      if(!$name){
         $errors[] = "name is not defined";
      }
      if($username){
         if(!ctype_alnum($username)){
            $errors[] = "username can only contain numbers and letters";
         }
         
         $range = range(1,32);
         if(!in_array(strlen($username),$range)){
            $errors = "username must be within 1 and 32 characters";
            }
      }
      if($password && $confirm){
         if($password != $confirm){
            $errors[] = "passwords do not match";
         }
      }
      if($email){
         $checkmail = "/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2, }$/i";
         if(!preg_match($checkmail, $email)){
            $errors[] = "e-mail is not valid, must be [email protected]";
         }
      }
      
      if($name){
         $range2 = range(3,64);
         if(!in_array(strlen($name),$range2)){
            $errors = "name must be within 3 and 64 characters";
         }
      }
      
      if($username){
         $sql = "SELECT * FROM `users` WHERE `username`='$username'";
         $res = mysql_query($sql) or die(mysql_error());
         
         if(mysql_num_rows($res) > 0){
            $errors[] = "the username you gave is already in use";
         }
      }
      
      if($email){
         $sql2 = "SELECT * FROM `users` WHERE `email`='$email'";
         $res2 = mysql_query($sql2) or die(mysql_error());
         
         if(mysql_num_rows($res2) > 0){
            $errors[] = "the email you gave is already in use";
         }
      }
      
      if(count($errors) > 0){
         foreach($errors AS $error){
            echo $error . "<br>";
         }
         }else {
            $sql3 = "INSERT INTO `users`
            (`username`,`password`,`email`,`name`);
            ('$username','".md5($password)."','$email','$name');";
            $res3 = mysql_query($sql3) or die(mysql_error());
            echo"you have successfully registered with the username <b>$username</b> and the password <b>$password</b>";
         }
      }
?>


and this is functions.php
Code:
<?php

function protect($string){
   $string = mysql_real_escape_string($string);
   $string = strip_tags($string);
   $string = addslashes($string);
   
   return $string;
}

function connect(){
   $con =  mysql_connect(localhost ,root , 'hello') or die(mysql_error());
   $db = mysql_select_db(users, $con);
}

?>


could someone fix the code for me please? thx to whoever helps.
but it keeps coming up with mysql_connect(); errors
Back to top
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Fri Oct 31, 2008 4:44 am    Post subject: Reply with quote

Are you running a local server with the website and mysql database on the same machine? or is the site being hosted remotely?
Back to top
View user's profile Send private message
deleted user 111213
Grandmaster Cheater
Reputation: 0

Joined: 09 Nov 2007
Posts: 714

PostPosted: Fri Oct 31, 2008 5:46 am    Post subject: Reply with quote

local server meaning like phpMyAdmin. and remotely meaning hosting website. remotely then.
Back to top
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Fri Oct 31, 2008 6:23 am    Post subject: Reply with quote

Local as in the computer is in your house and you have direct access to it.

For a remotely hosted service, I'm pretty sure you wouldn't connect to their mysql server with 'localhost', root, etc. Presuming they offer database support, you may need to login to their site and create your own personal mysql account. Contact support if you need to and ask them about database access.
Back to top
View user's profile Send private message
deleted user 111213
Grandmaster Cheater
Reputation: 0

Joined: 09 Nov 2007
Posts: 714

PostPosted: Fri Oct 31, 2008 6:38 am    Post subject: Reply with quote

ok, thankyou.
Edit: i tried with easyPHP. didnt work. (i cant install phpMyAdmin). lulz. it really doesn't work ill give u the things it said.
Code:
Notice: Use of undefined constant localhost - assumed 'localhost' in C:\Program Files\EasyPHP 2.0b1\www\registration\functions.php on line 12

Notice: Use of undefined constant root - assumed 'root' in C:\Program Files\EasyPHP 2.0b1\www\registration\functions.php on line 12

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\Program Files\EasyPHP 2.0b1\www\registration\functions.php on line 12
Access denied for user 'root'@'localhost' (using password: YES)
Back to top
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Fri Oct 31, 2008 7:44 am    Post subject: Reply with quote

I've never used EasyPHP but this may be of some help..

http://www.easyphp.org/faq.php wrote:
6. What are the: name of the server, the user name, the database name and the password for accessing mySQL capabilities?
"localhost", "root", ""

14. How can I change the password for a mySQL user?
Open phpMyAdmin, and click on "Users & Permissions".
Click on the "modify" link of the user you want to change the password, and follow the instructions.
WARNING: if you set a new password for the "root" user, you will not be able to access phpMyAdmin anymore, or you will need to re-configure phpMyAdmin: edit the "EasyPhp\phpMyAdmin\config.inc.php" file and set your new password with this line $cfgServers[1]['password'].
For Example:
$cfgServers[1]['password'] = 'mynewpassword'

30. [v1.6] My scripts worked perfectly with 1.5 but now I get this error : Warning: Forbidden access for user: 'user@localhost' (password: YES) when I want to connect to MySql.
Only the root user (without password) has the rights to connect to the database. Either modify your scripts to use it, or add the user you need (phpMyAdmin/users and privileges: See phpMyAdmin's documentation for more information).


Code:
$con = mysql_connect('localhost', 'root', '') or die(mysql_error());
Back to top
View user's profile Send private message
pkedpker
Master Cheater
Reputation: 1

Joined: 11 Oct 2006
Posts: 412

PostPosted: Sat Nov 01, 2008 9:14 pm    Post subject: Reply with quote

in functions.php

function connect(){
$con = mysql_connect(localhost ,root , 'hello') or die(mysql_error());
$db = mysql_select_db(users, $con);
}

that line thats bold is not correct to your sql settings

what is 'hello' that should be your SQL password..
now what is root? php helped you out.. it suppose to have '' 's or "" 's
thats your SQL username..

now localhost is your IP or IP with port. but leave that localhost if your SQL is your computer but also you forgot the '' 's or "" 's around it.

final result should look like

$con = mysql_connect("localhost" ,"root" , "hello") or die(mysql_error());

I'd use the '' 's only if it's one character and "" 's when it's alot of letters I know both work but thats just php helping you out.. it auto fixes your errors but makes ur page load faster

_________________
Hacks I made for kongregate.
Kongregate Universal Badge Hack: http://forum.cheatengine.org/viewtopic.php?p=4129411
Kongreate Auto Rating/Voter hack: http://forum.cheatengine.org/viewtopic.php?t=263576
Took a test lol
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites