Page 1 of 1
Update using PHP
Posted: Tue Nov 22, 2011 4:44 am
by johnmergene
Code: Select all
<?php
session_start();
$emailadd = $_SESSION['Emailadd'];
$hostname="xxxxxxxxxxxxxxxxxxx";
$username="xxxxxxxxxxxxxxxxxxxxxx";
$password="xxxxxxxxxxx";
$database="xxxxxxxxxxxxxxxxxxxxxxxxxx";
$on = 'yes';
$off = 'no';
$ac = 'yes';
mysql_connect($hostname, $username, $password) OR DIE("Unable to connect");
mysql_select_db("xxxxxxxxxxxxxx") or die("Unable to select database");
$query="update Account SET On='" . $off . "' WHERE Accepted='" . $ac . "'";
$checkresult = mysql_query($query);
$query="update Account SET On='" . $on . "' WHERE Accepted='" . $ac . "'";
$checkresult = mysql_query($query);
if ($checkresult) header('Location:login.html');
else echo 'update query failed';
mysql_close();
?>
Wrong? i would like to have codes that output is .. if a DJ login. the other will be offair(all except the new Loggedin DJ) then he will be onair.
Re: Update using PHP
Posted: Tue Nov 22, 2011 5:01 am
by maxx99
I'm not sure if i got you right.
You want to change status of "onair" DJ to "offair" when new DJ logs in?
Provide more detailed description

Re: Update using PHP
Posted: Tue Nov 22, 2011 6:10 am
by johnmergene
yes. not logsin actualy.. i want a page that have a button. if he is onair. the button named Offair. then if he click offair button. the value in the databse will be 'no' (mean to be offline) then the button in the same page will be renamed to Onair. if he click onair, their is condition. if other DJ is online it is forced to be offair by changing the value in database.
Re: Update using PHP
Posted: Tue Nov 22, 2011 6:57 am
by maxx99
Are you aware that changing values in DB will NOT refresh the page? You need AJAX for that.
If yes
VERY simple solution would be:
Code: Select all
//On every request
mysql_connect($hostname, $username, $password) OR DIE("Unable to connect");
mysql_select_db("xxxxxxxxxxxxxx") or die("Unable to select database");
$query="update Account SET On='" . $off . "'; //set all to "offair"
$result = mysql_query($query);
$query="update Account SET On='" . $on . "' WHERE Accepted='" . $emailaddr . "'"; //set "onair" only to the one with given email addres
$result = mysql_query($query);
//you can do some additional checks on $result and redirect
Re: Update using PHP
Posted: Tue Nov 22, 2011 7:06 am
by johnmergene
thanks. iwill try this now
Re: Update using PHP
Posted: Tue Nov 22, 2011 7:20 am
by johnmergene
still not change. do i need to send a form with textfield? or others
Re: Update using PHP
Posted: Tue Nov 22, 2011 7:30 am
by maxx99
What didnt change?

you need to be more specific
Re: Update using PHP
Posted: Tue Nov 22, 2011 7:33 am
by johnmergene
still not change the value. it is still no.. lol. it must be yes. lol