i’m try to write simple user registeration page and use simple DBCONNECTOR Class same as below and when i try to send user to database i get mysql_query() error.this is my php code and class please help me to fix problem
and this is my dbconnector class:
<?php
require_once 'UConfig.inf.php';
class udbcl extends USettings{
var $link;
var $myquery;
function UDbconnect(){
$DBinfo=USettings::GSettings();
$DBhost=$DBinfo['UDbhost'];
$DBname=$DBinfo['UDbname'];
$DBusername=$DBinfo['UDbusername'];
$DBpassword=$DBinfo['UDbpassword'];
$this->link=mysql_connect($DBhost,$DBusername,$DBpassword);
mysql_select_db($DBname);
}
function UQuery($myquery){
$this->link=$myquery;
return mysql_query($myquery, $this->link);
}
function UFetch($result){
return mysql_fetch_array($result);
}
function UDbclose(){
mysql_close($this->link);
}
}
?>
and this is my register.php page :
<?php
require_once ('UConfig/UDbconnector.php');
$myinfoadd = new udbcl();
if (isset($_POST['username'])) {
$myq = "INSERT INTO userinfo(username,password,email,telphon) VALUES('$_POST[username]','$_POST[password]','$_POST[email]','$_POST[telnumber]')";
$myinfoadd->UQuery($myq);
$myinfoadd->UDbclose();
echo "You registration is Success!";
sleep(3);
header('Location:index.php');
} else {
print <<<hldoc
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>U S R R</title></head><body><form method="POST" action="register.php" ><b>User Name:</b> <input type="text" name="username" /><br/><b>User Password:</b><input type="password" name="password" /><br/><b>User Email:</b><input type="email" name="email" /><br/><b>User Tel:</b><input type="telnumber" name="telnumber" /><br/><input type ="submit" name="submit" value="Register"/></form></body></html>
hldoc;
}
?>
When I try to register user I get an error same as below:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\uzu\UConfig\UDbconnector.php on line 18
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\uzu\UConfig\UDbconnector.php on line 25
You registration is Success!
Warning: Cannot modify header information – headers already sent by (output started at C:\xampp\htdocs\uzu\UConfig\UDbconnector.php:18) in C:\xampp\htdocs\uzu\register.php on line 10
The above function is equivalent to:
Don’t re-assign
$this->linkand you should be fine.UPDATE
I also noticed you never initialize the link. You should do this in the class constructor, or pass it as a parameter into the constructor.