April 5, 2008
WikiNetworkedobjects Moodbox Development Gettingittogether Php
#wiki
Those are the php files that I query two variables to the database.
die.php
<?php
include('common_db.php');
$btn = $_GET['var1'];
$loc = $_GET['var2'];
$result = mysql_do("INSERT INTO tes2 (button_id, location_id) VALUES ('$btn','$loc');");
// $result = mysql_do("INSERT INTO tes2 (test) VALUES ('$btn');");
echo $result;
?>
//common_db.inc
<?php
//common_db.inc
$dbhost = 'xxx.113.xxx.xxx';
$dbusername = 'ilteris';
$dbuserpassword = 'xxxxxx';
$default_dbname = 'moodbox';
$MYSQL_ERRNO = '';
$MYSQL_ERROR = '';
function db_connect() {
global $dbhost, $dbusername, $dbuserpassword, $default_dbname;
global $MYSQL_ERRNO, $MYSQL_ERROR;
$link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword);
if(!$link_id) {
$MYSQL_ERRNO = 0;
$MYSQL_ERROR = "Connection failed to the host $dbhost.";
return 0;
}
else if(empty($dbname) && !mysql_select_db($default_dbname)) {
// MYSQL_ERRNO = mysql_errno();
// MYSQL_ERROR = mysql_error();
return 0;
}
else return $link_id;
}
function sql_error() {
global $MYSQL_ERRNO, $MYSQL_ERROR;
if(empty($MYSQL_ERROR)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
}
return "$MYSQL_ERRNO: $MYSQL_ERROR";
}
function mysql_do($sql) {
$link_id = db_connect();
$result = mysql_query($sql, $link_id);
return $result;
}
?>
Continue Reading
Back to Archive