PHP classes for a newbie like me... Help plss T_T
I'm having a problem in handling classes using php. Ok, this is my first time handling classes in php, so I made a basic php code.
Database name: try
Table name: example
Here's my 3 files:
insertUser.php
Code:
<?php
if(isset($_GET['submit']))
{
include "dbconnect.php";
include "execute.class.php";
$execute = new try();
$username = $_GET['user'];
$password = $_GET['password'];
$sqlstring = "insert into example values('$username','$password')";
$execute->execute_query($sqlstring);
}
?>
<html>
<head>
<title> php class </title>
</head>
<body>
<form method="get" action="">
<label for= "userid"> Username</label>
<input type= "text" name="user" id="userid" />
<label for= "passid"> Password</label>
<input type= "password" name= "password" id="passid"/>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
dbconnect.php
Code:
<?php
$con = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("try",$con) or die(mysql_error());
?>
execute.class.php
Code:
<?php
class try
{
function execute_query($query)
{
mysql_query($query);
}
}
?>
My problem was, when I executed this, I've got a blank page... I have tried putting include "dbconnect.php" in the execute.class.php but it's of no use. I tried putting the include "execute.class.php" and the creation of object outside the if statement, still, failed... what went wrong? And if you could kindly explain the rules, constraints, the do's, and dont's in using classes in php, it would be more appreciated...