jokerbla Posted October 28, 2009 Share Posted October 28, 2009 I have a table with 3 fields, one of which is primary, auto-increment, like an id. How do I select the id? ... $sql="SELECT * FROM users WHERE username='$un' and password='$pw'"; $result=mysql_query($sql); $count=mysql_num_rows($result); $_SESSION["id"]=$id; ... that didn't work Quote Link to comment https://forums.phpfreaks.com/topic/179352-how-do-i-select-a-field/ Share on other sites More sharing options...
cags Posted October 28, 2009 Share Posted October 28, 2009 $sql="SELECT * FROM users WHERE username='$un' and password='$pw'"; $result=mysql_query($sql); $row = mysql_fetch_assoc($result); $_SESSION['id'] = $row['id']; You may consider changing your SELECT statement. If you only require the id, change the * for id. If you only need a couple your still better implicitly selecting those columns rather than using the *. Quote Link to comment https://forums.phpfreaks.com/topic/179352-how-do-i-select-a-field/#findComment-946308 Share on other sites More sharing options...
jokerbla Posted October 28, 2009 Author Share Posted October 28, 2009 I understand now, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/179352-how-do-i-select-a-field/#findComment-946319 Share on other sites More sharing options...
jokerbla Posted October 28, 2009 Author Share Posted October 28, 2009 I seem to be having another problem with the UPDATE $sgvote = mysql_query("SELECT voted FROM vote") or die(mysql_error()); $row1 = mysql_fetch_array($sgvote); $voted = $row1['voted']; $sql="SELECT id FROM users"; $result=mysql_query($sql); $row = mysql_fetch_assoc($result); $newvoted = $row['id']; //echo $row['id']; $total = $voted." ".$newvoted; echo " voted: ".$voted; echo " newvoted: ".$newvoted; echo " total: ".$total; $update = mysql_query("UPDATE vote SET voted=$total"); I want to make a list with the ids (that have voted), each id separated by space $voted is 1, $newvoted is 1 $total is "1 1" cause the id that voted was 1 and initially the field was set by me to 1 So each time someone votes it's supposed to get it's id. Problem is it always stays at "1 1", when it's supposed to add " 1" each time someone votes. What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/179352-how-do-i-select-a-field/#findComment-946340 Share on other sites More sharing options...
fenway Posted October 31, 2009 Share Posted October 31, 2009 Yikes... you need a WHERE clause for every update statement. Quote Link to comment https://forums.phpfreaks.com/topic/179352-how-do-i-select-a-field/#findComment-948406 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.