slapdashgrim Posted August 30, 2008 Share Posted August 30, 2008 im pretty sure these 2 questions have simple fixes. Question 1: how come this query wont update? <?php mysql_query("UPDATE users SET online=0 WHERE id='".$_SESSION['id']."'"); ?> where this one does <?php mysql_query("UPDATE users SET online=1 WHERE id='".$values['id']."'"); ?> Question 2: how come i can't use a variable as a database? <?php if ($dbc = mysql_connect ("$dbhost", "$dbuser", "$dbpass")) { mysql_select_db ("$dbname"); } ?> Link to comment https://forums.phpfreaks.com/topic/121960-solved-2-easy-questions/ Share on other sites More sharing options...
ratcateme Posted August 30, 2008 Share Posted August 30, 2008 there is absolutely no problem with any of the code you posted how are you assigning the vars? Scott. Link to comment https://forums.phpfreaks.com/topic/121960-solved-2-easy-questions/#findComment-629536 Share on other sites More sharing options...
genericnumber1 Posted August 30, 2008 Share Posted August 30, 2008 Question 1: how come this query wont update? <?php mysql_query("UPDATE users SET online=0 WHERE id='".$_SESSION['id']."'"); ?> where this one does <?php mysql_query("UPDATE users SET online=1 WHERE id='".$values['id']."'"); ?> Well they both have different id variables, did you mean to use $values['id'] for the first query? If not, try echoing the raw query before you pass it to mysql_query() to make sure it's what you expect it to be. Alteratively you can do mysql_query(' ... ') or die(mysql_error()); to see if there's an error in your query. Question 2: how come i can't use a variable as a database? <?php if ($dbc = mysql_connect ("$dbhost", "$dbuser", "$dbpass")) { mysql_select_db ("$dbname"); } ?> You should be able to, but you don't need the double quotes around the variable... not that that would cause the problem. We would need more info to figure out why this does not work. Link to comment https://forums.phpfreaks.com/topic/121960-solved-2-easy-questions/#findComment-629537 Share on other sites More sharing options...
slapdashgrim Posted August 30, 2008 Author Share Posted August 30, 2008 okay the first query is used when a user logs in <?php if ($_POST['submit']=='Login'){ $username = trim($_POST['username']); $password = mysql_escape_string(md5(trim($_POST['password']))); $results = mysql_query("SELECT id, username, password, admin FROM users WHERE username='$username'"); if(mysql_num_rows($results) == 1){ $values = mysql_fetch_array($results); if ($password == $values['password']){ $_SESSION['userName'] = $values['username']; $_SESSION['admin'] = $values['admin']; $_SESSION['auth'] = TRUE; $_SESSION['id'] = $values['id']; mysql_query("UPDATE users SET online=1 WHERE id='".$values['id']."'"); header('Location: ../index.php'); }else{ header('Location: ../index.php?act=login&alert=1&message='.urlencode('check your Password again, we were unable to log you in.')); } } else{ header('Location: ../index.php?act=login&alert=1&message='.urlencode('check your login information again, we were unable to log you in.')); } } ?> the second is for a log out <?php mysql_query("UPDATE users SET online=0 WHERE id='".$_SESSION['id']."'") or die(mysql_error()); unset($_SESSION); session_destroy(); header('location: ../index.php'); ?> i tried to use or die(mysql_error()); in the second code to see why it wont update and it does not print an error it just continues and the second question it is a function <?php $dbuser = 'root'; $dbpass = ''; $dbhost = 'localhost'; $dbname = 'slapdashcms'; function dbmysqlcms(){ if ($dbc = mysql_connect ("$dbhost", "$dbuser", "$dbpass")) { mysql_select_db ("slapdashcms"); } } ?> but when i use the dbname var it alters the way mysql works. it creates errors in my scripts Link to comment https://forums.phpfreaks.com/topic/121960-solved-2-easy-questions/#findComment-629543 Share on other sites More sharing options...
genericnumber1 Posted August 30, 2008 Share Posted August 30, 2008 Try adding or die(mysql_error()); at the end of your mysql_query()s, your mysql_connect()s and your mysql_select_db()s. After changing mysql_select_db() back to mysql_select_db($dbname) first of course. Also, echo the query that isn't acting correctly and make sure it is what you want it to be... echo "UPDATE users SET online=0 WHERE id='$_SESSION['id']'"; or whatever edit: cut out the quote, taking up too much room Link to comment https://forums.phpfreaks.com/topic/121960-solved-2-easy-questions/#findComment-629547 Share on other sites More sharing options...
ratcateme Posted August 30, 2008 Share Posted August 30, 2008 have you called session_start() Scott. Link to comment https://forums.phpfreaks.com/topic/121960-solved-2-easy-questions/#findComment-629548 Share on other sites More sharing options...
slapdashgrim Posted August 30, 2008 Author Share Posted August 30, 2008 ya the session should be working fine Link to comment https://forums.phpfreaks.com/topic/121960-solved-2-easy-questions/#findComment-629549 Share on other sites More sharing options...
slapdashgrim Posted August 30, 2008 Author Share Posted August 30, 2008 OMG IM SO SRY! that was the biggest mistake of my life. i was using an old link. i screwed up it was not using the script that i have been telling you about. thats why it would not update. it still logged out tho becuase it was the old version of the script Link to comment https://forums.phpfreaks.com/topic/121960-solved-2-easy-questions/#findComment-629551 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.