• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

zonet first php mysql - check.

Zonet

Web Developer
Joined
Sep 1, 2008
Messages
4,393
Reaction score
52
Location
Tibia VS RL-life, guess whos back?
Hi, I dont know if this is the correct board to post on but, here's my first script with php mysql.

PHP:
<html>
<center>
<?php

$sql['host'] = 'localhost';
$sql['username'] = 'root';
$sql['password'] = 'mypassword';
$sql['database'] = 'mydbname';

$mycon = mysql_connect($sql['host'], $sql['username'], $sql['password']);
	if(!$mycon) {
		die('Unable to connect to MySQL.'. mysql_error());
	}
		else {
			$dbselect = @mysql_select_db ($sql['database']);
			echo 'MySQL Connected. <br />';
		}
	if(!$dbselect) {
		die('Could not select databse. '. mysql_error());
}
	else {
		echo 'Choosing databse ... Done.';
	}
?>
	
</center>
</html>

Please, tell me some exercises I can work on and the site I can read for better tutorial.
 
First off, drop mysql_* functions.
Use $your_variable = new MySQLi();
You can already connect within registering the class:
$your_variable = new MySQLi(host, user, pass, db); else $your_variable->connect(), $your_variable->select_db();

Do some easy stuff at the beggining, you can already try to work with your OTS database (list all players + their levels, then try to get their skills also).

:peace:
 
First off, drop mysql_* functions.
Use $your_variable = new MySQLi();
You can already connect within registering the class:
$your_variable = new MySQLi(host, user, pass, db); else $your_variable->connect(), $your_variable->select_db();

Do some easy stuff at the beggining, you can already try to work with your OTS database (list all players + their levels, then try to get their skills also).

:peace:
Oh nice, thanks :) Reading book called PHP A Beginners guide, just started.
 
Last edited:
I made a RGB ~ look:)
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php
	$r = $_GET['r'];
	$g = $_GET['g'];
	$b = $_GET['b'];
	$rgb = $r . ',' . $g . ',' . $b;
	if(empty($r) || empty($g) || empty($b)) {
		echo 'Write a RGB number!';
	}

?>
<style type="text/css">
	fieldset.rgb {
		background-color: rgb(<?php echo $rgb; ?>);
	}
</style>
	<title> RBG </title>
</head>
<body>

<fieldset class="rgb">
<?php 
	echo "R = $r <br /> G = $g <br /> B = $b";
?>
	<legend> RGB ~ </legend>
		<center>
	<form action="" method="get">
		R: <input type="text" name="r" size="5" /> <br/> <br/>
		G: <input type="text" name="g" size="5" />  <br/> <br/>
		B: <input type="text" name="b" size="5" /> <br/> <br/>
		   <input type="submit" value="Check color!" />
	</form>
	</center>
</fieldset>


</body>
</html>
 
Instead of using if on connection you can use:



Also if u do IF and u put only one line you don't have to put brackets '{ }'

for example

True, although you don't actually have to use the die() keyword, unless you want your own custom error. And, as Nemaneth stated, you better get the hang of MySQLi. And once your coding is more advanced, you might want to consider learning OOP (Oriented Object Programming).
 
Well yes, MySQLi is better, there is also PDO but both of them are really simillar.

OOP is still long way in front of him first let him get basics. :)
 
Well yes, MySQLi is better, there is also PDO but both of them are really simillar.

OOP is still long way in front of him first let him get basics. :)

Yeah that's why I said that if his PHP skills become more advanced, he could consider learning it. I already said that now because he maybe won't be confronted by it when he gets better at PHP.
 
I'd recommend that you do not use !$var, because it will not be supported very good in the newer versions of php.

Either you use empty($var) or isset. Or you can simply just use != '' ect. That will be more secure in the upcoming new versions of PHP.
 
Back
Top