textbox Posted May 7, 2007 Share Posted May 7, 2007 Hello, i wish to allow users to update their profile settings. Here if the code i have so far; <? include ('inc/global.php'); $query = mysql_query("SELECT * FROM users WHERE username=".$_SESSION['username']); $result=mysql_query($query); $num=mysql_numrows($result); $about=mysql_result($result,"about"); $interests=mysql_result($result,"interests"); $music=mysql_result($result,"music"); $film=mysql_result($result,"film"); $film=mysql_result($result,"quote"); ?> <form action="updated.php"> <input type="hidden" name="ud_id" value="<? echo $_SESSION['username']; ?>"> About Me: <input type="text" name="ud_about" value="<? echo "$about"?>"><br> Interests: <input type="text" name="ud_interests" value="<? echo "$interests"?>"><br> Music: <input type="text" name="ud_music" value="<? echo "$music"?>"><br> Film: <input type="text" name="ud_film" value="<? echo "$film"?>"><br> Quote: <input type="text" name="ud_quote" value="<? echo "$quote"?>"><br> <input type="Submit" value="Update"> </form> Its just showing me the form fields with no data in Any help would be great! Quote Link to comment https://forums.phpfreaks.com/topic/50416-solved-updating-users-information/ Share on other sites More sharing options...
textbox Posted May 7, 2007 Author Share Posted May 7, 2007 Above i have this session script as well, to save confusion! include "include/session.php"; session_start(); header("Cache-control: private"); if (!$_SESSION['username']) { echo "You're not logged in!"; include("index.php"); exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/50416-solved-updating-users-information/#findComment-247632 Share on other sites More sharing options...
john010117 Posted May 7, 2007 Share Posted May 7, 2007 <? include ('inc/global.php'); $query = mysql_query("SELECT * FROM users WHERE username=".$_SESSION['username']); $result=mysql_query($query); $num=mysql_num_rows($result); $about=mysql_result($result,"about"); $interests=mysql_result($result,"interests"); $music=mysql_result($result,"music"); $film=mysql_result($result,"film"); $film=mysql_result($result,"quote"); ?> <form action="updated.php"> <input type="hidden" name="ud_id" value="<? echo $_SESSION['username']; ?>"> About Me: <input type="text" name="ud_about" value="<? echo "$about"?>"><br> Interests: <input type="text" name="ud_interests" value="<? echo "$interests"?>"><br> Music: <input type="text" name="ud_music" value="<? echo "$music"?>"><br> Film: <input type="text" name="ud_film" value="<? echo "$film"?>"><br> Quote: <input type="text" name="ud_quote" value="<? echo "$quote"?>"><br> <input type="Submit" value="Update"> </form> You forgot the underscore "_" in mysql_num_rows. Quote Link to comment https://forums.phpfreaks.com/topic/50416-solved-updating-users-information/#findComment-247633 Share on other sites More sharing options...
textbox Posted May 7, 2007 Author Share Posted May 7, 2007 Thanks for that John, sadly, it still does not work?!? Any other ideas, or alternative ways to do it? Nick Quote Link to comment https://forums.phpfreaks.com/topic/50416-solved-updating-users-information/#findComment-247641 Share on other sites More sharing options...
textbox Posted May 7, 2007 Author Share Posted May 7, 2007 Can anyone recommend a good tutorial on this?! Head to desk at moment! Quote Link to comment https://forums.phpfreaks.com/topic/50416-solved-updating-users-information/#findComment-247646 Share on other sites More sharing options...
boo_lolly Posted May 7, 2007 Share Posted May 7, 2007 1. don't use short tags (<?/?>) 2. you re-established the variable film, so it's only going to contain the 'quote', and not the 'film' 3. you don't need to add quotes around a $variable 4. you must have been getting an error because you forgot to put a semicolon `;` after your echo statements 5. you should put single quotes around your where clause 6. your query looks like this: $result = mysql_query(mysql_query($query); that is wrong 7. you need an error handler for your query <?php include ('inc/global.php'); $sql = " SELECT * FROM users WHERE username = '{$_SESSION['username']}' "; $result = mysql_query($sql) OR die(mysql_error()); $num=mysql_num_rows($result); $about=mysql_result($result,"about"); $interests=mysql_result($result,"interests"); $music=mysql_result($result,"music"); $film=mysql_result($result,"film"); $quote=mysql_result($result,"quote"); ?> <form action="updated.php"> <input type="hidden" name="ud_id" value="<?php echo $_SESSION['username']; ?>"> About Me: <input type="text" name="ud_about" value="<?php echo $about; ?>"><br> Interests: <input type="text" name="ud_interests" value="<?php echo $interests; ?>"><br> Music: <input type="text" name="ud_music" value="<?php echo $music; ?>"><br> Film: <input type="text" name="ud_film" value="<?php echo $film; ?>"><br> Quote: <input type="text" name="ud_quote" value="<?php echo $quote; ?>"><br> <input type="Submit" value="Update"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/50416-solved-updating-users-information/#findComment-247667 Share on other sites More sharing options...
textbox Posted May 7, 2007 Author Share Posted May 7, 2007 For some reason that echo's out my userid in every field?! Any ideas? Thanks for the tips so far! Quote Link to comment https://forums.phpfreaks.com/topic/50416-solved-updating-users-information/#findComment-247683 Share on other sites More sharing options...
benjaminbeazy Posted May 8, 2007 Share Posted May 8, 2007 you're missing an argument in mysql_result, try $var = mysql_result($result,0,"field name or offset"); Quote Link to comment https://forums.phpfreaks.com/topic/50416-solved-updating-users-information/#findComment-247701 Share on other sites More sharing options...
textbox Posted May 8, 2007 Author Share Posted May 8, 2007 Thanks Ben, thats smashing, because it worked for pulling out the data! BUT, i cant get the record to update; this is the code i am using $query="UPDATE users SET about='$ud_about', interests='$ud_interests', music='$ud_music', film='$ud_film', quote='$ud_quote' WHERE username = '{$_SESSION['username']}'"; mysql_query($query); echo "Record Updated"; mysql_close(); Quote Link to comment https://forums.phpfreaks.com/topic/50416-solved-updating-users-information/#findComment-247717 Share on other sites More sharing options...
benjaminbeazy Posted May 8, 2007 Share Posted May 8, 2007 try this and let me know what you get $username = $_SESSION['username']; $query="UPDATE users SET about='$ud_about', interests='$ud_interests', music='$ud_music', film='$ud_film', quote='$ud_quote' WHERE username = '$username'"; echo "Query: $query<br>"; mysql_query($query) or die(mysql_error()); echo "Record Updated"; mysql_close(); Quote Link to comment https://forums.phpfreaks.com/topic/50416-solved-updating-users-information/#findComment-247720 Share on other sites More sharing options...
textbox Posted May 8, 2007 Author Share Posted May 8, 2007 Ben, i included my session handling <?php include "include/session.php"; session_start(); header("Cache-control: private"); if (!$_SESSION['username']) { echo "You're not logged in!"; include("index.php"); exit(); } ?> And your code worked fine! Thank you very much! Nick Quote Link to comment https://forums.phpfreaks.com/topic/50416-solved-updating-users-information/#findComment-247721 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.