re : database connection and retrieving values
[email protected] (Raisun John Sunny) Tue, 13 Jul 2010 07:48:08 +0530
| Newsgroups | php.gtk.general |
|---|---|
| Message-ID | <[email protected]> |
--000e0cd51cf0e5d2e0048b3b7a44
Content-Type: text/plain; charset=ISO-8859-1
Hi Ther
I a new to Php-Gtk and its been only 3 days. I was extremely impressed by
the way gtk works.
I started by testing the sample code available in the documentation.
It worked fine.
Now i made some changes to the code so that it would check the username and
password from the database and display a message whether it exists or not.
But when i do that I get the following error messages:
PHP Warning: mysql_connect(): Can't connect to MySQL server on
's**********.db.********.h*********.c*****' (4) in
/home/raisun/phptest/gtktest/test1/gtk1.phpw on line 47
PHP Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link
resource in /home/raisun/phptest/gtktest/test1/gtk1.phpw on line 48
PHP Warning: mysql_query(): Can't connect to local MySQL server through
socket '/var/lib/mysql/mysql.sock' (2) in
/home/raisun/phptest/gtktest/test1/gtk1.phpw on line 52
PHP Warning: mysql_query(): A link to the server could not be established
in /home/raisun/phptest/gtktest/test1/gtk1.phpw on line 52
PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in /home/raisun/phptest/gtktest/test1/gtk1.phpw on line 53
NOTE : I have changed the name of the hostname for security purpose!!!
I am pasting the code for the login function . Please note that everything
was working fine until i typed in the database code.:
function login(GtkWindow $wnd, GtkEntry $txtUsername, GtkEntry
$txtPassword,GtkLabel $lblPassword,GtkLabel $lblUsername, GtkButton
$btnCancel, GtkButton $btnLogin)
{
//fetch the values from the widgets into variables
$strUsername = $txtUsername->get_text();
$strPassword = $txtPassword->get_text();
//Do some error checking
$errors = null;
if (strlen($strUsername) == 0) {
$errors .= "Username is missing.\r\n";
}
if (strlen($strPassword) == 0) {
$errors .= "No password given.\r\n";
}
if ($errors !== null) {
//There was at least one error.
//We show a message box with the errors
$dialog = new GtkMessageDialog($wnd, Gtk::DIALOG_MODAL,
Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, $errors);
$dialog->set_markup(
"The following errors occured:\r\n"
. "<span foreground='red'>" . $errors . "</span>"
);
$dialog->run();
$dialog->destroy();
} else {
//No error. You would need to hide the dialog now
//instead of destroying it (because when you destroy it,
//Gtk::main_quit() gets called) and show the main window
$txtPassword->hide();
$txtUsername->hide();
$lblPassword->hide();
$lblUsername->hide();
$btnCancel->hide();
$btnLogin->hide();
$localhost="s**********.db.********.h*********.c*****";
$username="#######";
$password="########";
$database="########";
$con=mysql_connect($localhost,$username,$password);
mysql_select_db($database,$con);
$myquery="select * from ####### where ################";
$my_q=mysql_query($myquery);
$my_num=mysql_num_rows($my_q);
if($my_num<>0){
echo "Welcome";
}else{
echo "You are not a registered user. ";
}
I have checked my internet connections and it is working fine.
Please check on it and let me know what could be wrong?
Any help would be great and keep up the good work. PHP-GTK ROckZZZZ!!!!
Thanks
regards
raisun
--000e0cd51cf0e5d2e0048b3b7a44--