I have a problem with php-gtk. Namely, I wrote a nice little php-cli application that will send certain information to a MySQL-DB and then display it on a webpage. Now I tried porting it to php-gtk, and it works great. Almost, except for the fact that whenever I run get_text() on a GtkEntry object, I get the initial value and not the value I entered. How do I fix this?
#!/usr/bin/php
<?
mysql_connect("server", "user", "password");
mysql_select_db("database");
$array = mysql_fetch_assoc(mysql_query("SELECT * FROM mood"));
if (!class_exists('gtk')) {
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
dl('php_gtk.dll');
else
dl('php_gtk.so');
}
/*
* Called when delete-event happens. Returns false to indicate that the event
* should proceed.
*/
function delete_event()
{
return false;
}
/*
* Create a new top-level window and connect the signals to the appropriate
* functions. Note that all constructors must be assigned by reference.
*/
$window = &new GtkWindow();
$window->connect_object('destroy', 'shutdown');
$window->connect('delete-event', 'delete_event');
$window->set_border_width(10);
$window->set_title('phpMood');
function shutdown()
{
print('Closing MySQL... ');
print mysql_close() ? "OK\n" : "ERROR\n" ;
print("Shutting down... OK\n");
gtk::main_quit();
}
$vbox = &new GtkVBox();
$window->add($vbox);
$vbox->show();
$hbox = &new GtkHBox(false, 5);
$hbox->set_border_width(5);
$vbox->pack_start($hbox, false);
$hbox->show();
$hbox2 = &new GtkHBox(false, 5);
$hbox2->set_border_width(5);
$rant = &new GtkText(NULL, $ad);
$rant->insert_text($array['rant'], 0);
$rant->set_editable(true);
$current = &new GtkEntry;
$current->insert_text($array['current'], 0);
$current->set_editable(true);
$mood = &new GtkEntry;
$mood->insert_text($array['mood'], 0);
$mood->set_editable(true);
//$mood->connect('changed','echochange');
$button = &new GtkButton('Close');
$button->connect_object('clicked', 'shutdown');
$submit = &new GtkButton('Update');
$submit->connect_object('clicked', 'submit',addslashes($mood->get_text()),addslashes($current->get_text()),addslashes($rant->get_chars(0,-1)));
$hbox->pack_start($mood);
$hbox->pack_start($current);
$vbox->pack_start($rant);
$vbox->pack_start($hbox2);
$hbox2->pack_start($submit);
$hbox2->pack_start($button);
function echochange($text)
{
echo "$text\n";
}
function submit($moodText, $currentText, $rantText)
{
echo "$moodText\n$currentText\n$rantText\n";
echo('Updating... ');
$sql = "UPDATE mood SET mood='$moodText', current='$currentText', rant='$rantText'";
print mysql_query($sql) ? "OK\n" : "ERROR\n".mysql_error();
}
$window->show_all();
gtk::main();
?>