Update using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
johnmergene
Forum Newbie
Posts: 16
Joined: Tue Nov 15, 2011 5:51 am

Update using PHP

Post 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.
Last edited by Benjamin on Tue Nov 22, 2011 7:23 am, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: Update using PHP

Post 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 :)
johnmergene
Forum Newbie
Posts: 16
Joined: Tue Nov 15, 2011 5:51 am

Re: Update using PHP

Post 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.
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: Update using PHP

Post 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
johnmergene
Forum Newbie
Posts: 16
Joined: Tue Nov 15, 2011 5:51 am

Re: Update using PHP

Post by johnmergene »

thanks. iwill try this now
johnmergene
Forum Newbie
Posts: 16
Joined: Tue Nov 15, 2011 5:51 am

Re: Update using PHP

Post by johnmergene »

still not change. do i need to send a form with textfield? or others
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: Update using PHP

Post by maxx99 »

What didnt change? :) you need to be more specific
johnmergene
Forum Newbie
Posts: 16
Joined: Tue Nov 15, 2011 5:51 am

Re: Update using PHP

Post by johnmergene »

still not change the value. it is still no.. lol. it must be yes. lol
Post Reply