Text Based Mafia Game || Database with Connection Part 1. Setting up a database with simple Connection
#16
Posted 16 April 2011 - 09:16 AM
#17
Posted 22 May 2011 - 11:54 AM
nyjatt, on 16 April 2011 - 05:16 PM, said:
hi nyjatt,
The best answer i can give you is to learn php and starting making little php scripts, use the tutorials on this site to help you out. When you have finished all the basics this will make much sense. let me know how it all goes.
#18
Posted 15 June 2011 - 11:58 AM
creativecoding, on 24 October 2010 - 10:48 PM, said:
Themitchel0, on 18 October 2010 - 04:46 PM, said:
Why did this get -rep?
Anyhow, I believe if you wanted to, you could set up a Virtual Machine (oracle has a good one) with some server software, you can add mysql to it and host your websites database. Although, your VM and computer would have to remain turned on...
Or even simpeler, WAMP
#19
Posted 26 November 2011 - 05:32 AM
my user database is all filled out. im using XAMPP
Created a folder called spacewars in the htdocs folder
This is the folder I placed connect.php and test.php in
On the connect.php script i wasnt sure what to put for connection and db? so I put mysq1_connect and mysql_database
My Database name is spacewars
server name is localhost
Username is shadowing
I type in http://localhost/spacewars/test
and I get a object not found error
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
I really appreciate the help
Attached image(s)
#20
Posted 26 November 2011 - 09:35 PM
<?php
mysql_connect("localhost", "shadowing", "eguitars8") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
I named that script test.php and typed in localhost/test.php and it worked saying connect to mysql
but when I do yours and type localhost/connect/php I get a Object not found error "the request url was not found on this server.
This is what i have for your connection script. I understand there is no echo in this script but shouldnt it give me a white page at least saying nothing on it?
<?php
$mysql_server = "localhost"; // localhost is common on most hosts.
$mysql_user = "shadowing"; // this is the name of your username of the server.
$mysql_password = "eguitars8"; // the password connected to the username. MAKE IT COMPLEX.
$mysql_database = "spacewars"; // the database name of where to connect to and where the information will be help.
$connection = mysq1_connect("$mysql_server","$mysql_user","$mysql_password") or die ("Unable to establish a DB connection");
$db = mysql_database("$mysql_database") or die ("Unable to establish a DB connection");
?>
#21
Posted 27 November 2011 - 01:35 AM
I was putting the connect and test php file in a folder with in the dir. I use xammp so i was putting it in the dir xampp/htdocs/spacewars which is the name of my project
Also the other reason it wasnt working was because mysql_connect had a 1 in it instead of a L
and i just noticed there is no differance from a 1 and a L on this site lol looks the same almost l1 crazy
#22
Posted 27 November 2011 - 03:04 AM
I cant get the test page to do anything I get a HTTP 500 Internal Server Error and says Internet instead of intranet on the bottom of my broswer using IE8.
So for kicks I created a php file with only this line of code
<?php include_once("connect.php"); ?>
and saved it as aa.php
so i run http://localhost/aa.php in my browser and i get the same error.
Shouldnt I get a blank page that is all white? like as if I ran connect.php
so its like this code doesnt even work <?php include_once("connect.php"); ?>
I"m using XAMPP the test file and the connect file is in xampp/htdocs
#23
Posted 27 November 2011 - 04:13 AM
On the connect script I had $db = $mysql_database("$mysql_database") instead of having $db = mysql_select_db("$mysql_database")
I had errors shut off on my apache server so I didnt see the error. Which would of solved alot of my other problems seeing errors.
After I fixed that issue I was still getting a db error. Either using <?php instead of <? fixed that or adding a space between <html > and <?php include_once("connect.php"); ?> fixed it.
Either way i double checked and using <? or not putting a space between those two lines still makes everything work. For some reason it didnt at first but now it does. lol not sure why. now i can continue the rest of the tutor. Ya!
#24
Posted 18 February 2012 - 04:40 PM
Denis1, on 09 September 2010 - 10:12 AM, said:
<? echo "Denis"; ?>you should use
<?php echo "Denis"; ?>. Local-hosts like xampp confuse <? tage for xml and it all a big mess.
Thank you!! i spent 2 days trying to find the problem myself.
#26
Posted 25 September 2012 - 03:11 AM
Im currently using xampp Apache and MySQL laters version, no longer wampserver. Dont know what Im going to do about that so far.
This is what I get using the crimson editor browser.

When Im opening the test file in localhost/myfiles/test.php
I get an error
Parse error: syntax error, unexpected '}' in C:\xampp\htdocs\myfiles\test\test.php on line 98
When I remove the } nothing specials happens but it seems to gives some problem when I add money to non existing player so I guess it all looks like this because I have no real list.
Im going to try add a player with the phpmyadmin but not sure if it will work.
Just wanted to show my progress so far and might get some tip even if the thread is old.
Wish me luck
#27
Posted 25 September 2012 - 06:44 AM
fuzzx, on 25 September 2012 - 03:11 AM, said:
Im currently using xampp Apache and MySQL laters version, no longer wampserver. Dont know what Im going to do about that so far.
This is what I get using the crimson editor browser.

When Im opening the test file in localhost/myfiles/test.php
I get an error
Parse error: syntax error, unexpected '}' in C:\xampp\htdocs\myfiles\test\test.php on line 98
When I remove the } nothing specials happens but it seems to gives some problem when I add money to non existing player so I guess it all looks like this because I have no real list.
Im going to try add a player with the phpmyadmin but not sure if it will work.
Just wanted to show my progress so far and might get some tip even if the thread is old.
Wish me luck
Hello would you mind posting the code you have on your test.php please. I'm no expert but it's seems like one of 3 things to me.
1. Missing bracket.
2. Extra bracket somewhere.
3. Bracket in the wrong location.
We should be able to help you more once we see the code.
#28
Posted 30 March 2013 - 04:31 PM
<?php include_once("connect.php"); ?>
<? require 'functions.php'; ?>
<?
if (isset($_POST['Register'])) {
if(strlen($_POST['Username'])<3 || strlen($_POST['Username'])>32)
{ // This check the characters of the username and it makes sure if it is longer that 3 letters.
echo 'Your name must be between 3 and 32 characters!';
}else{
if(empty($_POST['Password'])){ // This checks the password field to see if it is empty
echo 'You need to select a password!';
}else{
if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['Username']))
{// this checks the user for any symbols space etc .You can remove this is you choose
echo 'Your name contains invalid characters!';
}else{
if(!checkEmail($_POST['Email']))
{ // this is one of the functions we added on the function page. for this to work make sure the function is required on this page
echo 'Your email is not valid!';
}else{
if(empty($_POST['Agree'])){ // Check if the Checkbox is checked to agree with the terms of services
echo "You need to accept the Terms & conditions in order to sign up.!";
}else{
// this check and makes sure that their are no duplication with the email
$sql = "SELECT id FROM users WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($sql) or die(mysql_error());
$m_count = mysql_num_rows($query);
if($m_count >= "1"){
echo 'This email has already been used.!';
}else{
// this makes sure that all the uses that sign up have their own names
$sql = "SELECT id FROM users WHERE name='".mysql_real_escape_string($_POST['Username'])."'";
$query = mysql_query($sql) or die(mysql_error());
$m_count = mysql_num_rows($query);
if($m_count >= "1"){
echo 'This name has already been used.!';
}else{
$password = md5($_POST['Password']); // this is a md5 hash. its encrypt your password so it isnt easily hackable
// The id is blank because it is an auto_increment which mean it will auto add a value to every user and the are all different. this is mainly so we dont have dupilcate.
$sql = "INSERT INTO users SET id = '', name = '".$_POST['Username']."' , password= '$password', mail= '".$_POST["Email"]."'";
$res = mysql_query($sql);
$to = $_POST['Email'];
$from = "no-reply@Game.co.uk";
$subject = "Registration - Your Registration Details";
$message = "<html>
<body background=\"#4B4B4B\">
<h1>Game Registration Details</h1>
Dear ".$_POST['Username'].", <br>
<center>
Your Username: ".$_POST['Username']."<p>
Your Password: ".$_POST['Password']."<p>
<p>
<font size=3> You recived this mail because someone used this mail to sign up to a game</font>
</body>
</html>";
$headers = "From: Game Registration Details <no-reply@Game.co.uk>\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
echo "".$_POST['Username'].", Welcome to the game.";
}}}
}
}
}
}
}
?>
<form method="post" >
<center>
<h1><strong>Registeer hier:</strong></h1>
<p>Gebruikersnaam:
<input type="text" name="Username" id="Username">
</p>
<p>Wachtwoord:
<input type="password" name="Password" id="Password">
</p>
<p>Emailadres:
<input type="text" name="Email" id="Email">
</p>
<p> Toon aan dat je geen BOT bent:
<input type="checkbox" name="Agree" id="Agree">
<br>
<input type="submit" name="Register" id="Register" value="Registeer">
</p>
</center>
</form>
<?
if (isset($_POST['Register'])) {
$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
// Generate a random password
}
?>
<?
if (isset($_POST['Send'])) {
$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
// Generate a random password
$nsql = "SELECT * FROM users WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($nsql) or die(mysql_error());
$row = mysql_fetch_object($query);
$name = htmlspecialchars($row->name);
$pass = htmlspecialchars($row->password);
$mail = htmlspecialchars($row->mail);
if((empty($_POST['Email']))){ // if the email field is empty there will be an error
echo 'You one field empty.';
}else{
if(empty($name)){ if // there is no name with the entered email
echo 'Invalid information.';
}else{
if($_POST['Email'] != $mail){
echo 'Invalid information.'; // if their is no match in the email
}else{
if(!checkEmail($_POST['Email'])){ // the checkEmail function we have in our function that saves us time and sapce
echo 'Your email is not valid!';
}else{
$result = mysql_query("UPDATE users SET password='$password' WHERE name='" .mysql_real_escape_string($name). "'")
or die(mysql_error());
$to = $_POST['Email'];
$from = "no-reply@Game.co.uk";
$subject = "Registration - Your Registration Details";
$message = "<html>
<body background=\"#4B4B4B\">
<h1>Game Registration Details</h1>
Dear $name, <br>
<center>
Your Username: $name <p>
Your Password: $password <p>
</body>
</html>";
$headers = "From: Game Lost Details <no-reply@Game.co.uk>\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
echo 'We sent you an email with your Details!';
}
}
}// check if name is unused.
}// check if accepted to the tos.
}// name check.
// if post register.
?>
Keep getting: Parse error: syntax error, unexpected T_ECHO, expecting '(' in /home/a2156125/public_html/Register.php on line 145
please help!
#29
Posted 20 April 2013 - 04:04 AM
fature, on 31 March 2013 - 12:31 AM, said:
<?php include_once("connect.php"); ?>
<? require 'functions.php'; ?>
<?
if (isset($_POST['Register'])) {
if(strlen($_POST['Username'])<3 || strlen($_POST['Username'])>32)
{ // This check the characters of the username and it makes sure if it is longer that 3 letters.
echo 'Your name must be between 3 and 32 characters!';
}else{
if(empty($_POST['Password'])){ // This checks the password field to see if it is empty
echo 'You need to select a password!';
}else{
if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['Username']))
{// this checks the user for any symbols space etc .You can remove this is you choose
echo 'Your name contains invalid characters!';
}else{
if(!checkEmail($_POST['Email']))
{ // this is one of the functions we added on the function page. for this to work make sure the function is required on this page
echo 'Your email is not valid!';
}else{
if(empty($_POST['Agree'])){ // Check if the Checkbox is checked to agree with the terms of services
echo "You need to accept the Terms & conditions in order to sign up.!";
}else{
// this check and makes sure that their are no duplication with the email
$sql = "SELECT id FROM users WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($sql) or die(mysql_error());
$m_count = mysql_num_rows($query);
if($m_count >= "1"){
echo 'This email has already been used.!';
}else{
// this makes sure that all the uses that sign up have their own names
$sql = "SELECT id FROM users WHERE name='".mysql_real_escape_string($_POST['Username'])."'";
$query = mysql_query($sql) or die(mysql_error());
$m_count = mysql_num_rows($query);
if($m_count >= "1"){
echo 'This name has already been used.!';
}else{
$password = md5($_POST['Password']); // this is a md5 hash. its encrypt your password so it isnt easily hackable
// The id is blank because it is an auto_increment which mean it will auto add a value to every user and the are all different. this is mainly so we dont have dupilcate.
$sql = "INSERT INTO users SET id = '', name = '".$_POST['Username']."' , password= '$password', mail= '".$_POST["Email"]."'";
$res = mysql_query($sql);
$to = $_POST['Email'];
$from = "no-reply@Game.co.uk";
$subject = "Registration - Your Registration Details";
$message = "<html>
<body background=\"#4B4B4B\">
<h1>Game Registration Details</h1>
Dear ".$_POST['Username'].", <br>
<center>
Your Username: ".$_POST['Username']."<p>
Your Password: ".$_POST['Password']."<p>
<p>
<font size=3> You recived this mail because someone used this mail to sign up to a game</font>
</body>
</html>";
$headers = "From: Game Registration Details <no-reply@Game.co.uk>\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
echo "".$_POST['Username'].", Welcome to the game.";
}}}
}
}
}
}
}
?>
<form method="post" >
<center>
<h1><strong>Registeer hier:</strong></h1>
<p>Gebruikersnaam:
<input type="text" name="Username" id="Username">
</p>
<p>Wachtwoord:
<input type="password" name="Password" id="Password">
</p>
<p>Emailadres:
<input type="text" name="Email" id="Email">
</p>
<p> Toon aan dat je geen BOT bent:
<input type="checkbox" name="Agree" id="Agree">
<br>
<input type="submit" name="Register" id="Register" value="Registeer">
</p>
</center>
</form>
<?
if (isset($_POST['Register'])) {
$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
// Generate a random password
}
?>
<?
if (isset($_POST['Send'])) {
$password = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
// Generate a random password
$nsql = "SELECT * FROM users WHERE mail='".mysql_real_escape_string($_POST['Email'])."'";
$query = mysql_query($nsql) or die(mysql_error());
$row = mysql_fetch_object($query);
$name = htmlspecialchars($row->name);
$pass = htmlspecialchars($row->password);
$mail = htmlspecialchars($row->mail);
if((empty($_POST['Email']))){ // if the email field is empty there will be an error
echo 'You one field empty.';
}else{
if(empty($name)){ // if there is no name with the entered email
echo 'Invalid information.';
}else{
if($_POST['Email'] != $mail){
echo 'Invalid information.'; // if their is no match in the email
}else{
if(!checkEmail($_POST['Email'])){ // the checkEmail function we have in our function that saves us time and sapce
echo 'Your email is not valid!';
}else{
$result = mysql_query("UPDATE users SET password='$password' WHERE name='" .mysql_real_escape_string($name). "'")
or die(mysql_error());
$to = $_POST['Email'];
$from = "no-reply@Game.co.uk";
$subject = "Registration - Your Registration Details";
$message = "<html>
<body background=\"#4B4B4B\">
<h1>Game Registration Details</h1>
Dear $name, <br>
<center>
Your Username: $name <p>
Your Password: $password <p>
</body>
</html>";
$headers = "From: Game Lost Details <no-reply@Game.co.uk>\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
echo 'We sent you an email with your Details!';
}
}
}// check if name is unused.
}// check if accepted to the tos.
}// name check.
// if post register.
?>
Keep getting: Parse error: syntax error, unexpected T_ECHO, expecting '(' in /home/a2156125/public_html/Register.php on line 145
please help!
At line 144 you have an if that i presume should be commented.
if(empty($name)){ [b]if[/b] // there is no name with the entered email
echo 'Invalid information.';
This post has been edited by Denis1: 20 April 2013 - 04:05 AM
|
|






MultiQuote






|