chocopi Posted August 2, 2007 Share Posted August 2, 2007 For some reason, which I can't seem to work out, my script is dying. My code is: <?php if(empty($user_familiar_name)) { $query = mysql_query("SELECT `name` FROM `kol_familiars` WHERE `id`='$user_familiar'") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); $_SESSION['user_familiar_name'] = $row['name']; $user_familiar_name = ucwords($_SESSION['user_familiar_name']); } ?> The script wil die on $row yet it does not give an error even though I have mysql_error(). So this means it isn't a mysql error, so i'm stumped I've tried using array and row instead of assoc but it still doesn't work. So I was wondering if anyone could shed some light on the matter. If you need any more info, drop me a line. Many thanks, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/63099-mysql_fetch-problems/ Share on other sites More sharing options...
micah1701 Posted August 2, 2007 Share Posted August 2, 2007 code looks good... are you sure the that section is being called? perhaps the var your checking to see if its empty() isn't really empty? instead of fetch_array or _assoc since you're just getting one resutit did you try: $_SESSION['user_familiar_name'] = mysql_result($query,0,0); Quote Link to comment https://forums.phpfreaks.com/topic/63099-mysql_fetch-problems/#findComment-314340 Share on other sites More sharing options...
premiso Posted August 2, 2007 Share Posted August 2, 2007 You do realize that in the sql statement you only call $user_familiar, not $user_familiar_name right? Quote Link to comment https://forums.phpfreaks.com/topic/63099-mysql_fetch-problems/#findComment-314341 Share on other sites More sharing options...
simcoweb Posted August 2, 2007 Share Posted August 2, 2007 Also, I don't see where this variable is set: WHERE `id`='$user_familiar'" in your query. To compare the 'id' it needs to have a value. Is that somewhere else in your code? Quote Link to comment https://forums.phpfreaks.com/topic/63099-mysql_fetch-problems/#findComment-314346 Share on other sites More sharing options...
ViN86 Posted August 2, 2007 Share Posted August 2, 2007 you sure its a problem with the mysql portion? you have error displaying turned on in php? Quote Link to comment https://forums.phpfreaks.com/topic/63099-mysql_fetch-problems/#findComment-314385 Share on other sites More sharing options...
chocopi Posted August 3, 2007 Author Share Posted August 3, 2007 Thanks, it thought error reporting was turned on but apparently not so im using: error_reporting(E_ALL); It said something to do with line 35 which is: $user_familiar_name = $_SESSION['user_familiar_name']; But for some reason the error message is not showing up now, even though the problem persists seeing as I havent changed anything. $user_familiar is set further up and that works fine. $user_familiar is a number which corresponds to the id's in the table hence why I am trying to take the name where the id from the user matches the table. The empty() part is working fine as I added echos onto every line to check where it stops, and it stops at $row. At first I thought it was a problem with using mysql_fetch_assoc but quite sure it isn't seeing as it is not throwing up anything from mysql_error(). So thanks for all of your help, but so far I think that premiso is the closest as the error message said something about user_familiar_name not being set/called/used or something along those lines. Many thanks, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/63099-mysql_fetch-problems/#findComment-314852 Share on other sites More sharing options...
chocopi Posted August 3, 2007 Author Share Posted August 3, 2007 Here we go I got the error message back: Notice: Undefined index: user_familiar_name in /data/members/free/tripod/uk/c/h/o/chocopi/htdocs/kol/sessions.php on line 35 Line 35: $user_familiar_name = $_SESSION['user_familiar_name']; So how do I go about fixing this, as I don't quite understand what it means Many thanks, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/63099-mysql_fetch-problems/#findComment-314872 Share on other sites More sharing options...
micah1701 Posted August 3, 2007 Share Posted August 3, 2007 sounds like your session variable is not being set. have you tried the whole thing without the if(empty()) clause around the section that defines the session variable? Quote Link to comment https://forums.phpfreaks.com/topic/63099-mysql_fetch-problems/#findComment-314878 Share on other sites More sharing options...
chocopi Posted August 3, 2007 Author Share Posted August 3, 2007 cheers, but that just gets rid of the error message, which is quite random seeing as it still stops/dies in the same place The only error I get now is that i am using another session_start(); Thanks Quote Link to comment https://forums.phpfreaks.com/topic/63099-mysql_fetch-problems/#findComment-314884 Share on other sites More sharing options...
ViN86 Posted August 3, 2007 Share Posted August 3, 2007 cheers, but that just gets rid of the error message, which is quite random seeing as it still stops/dies in the same place The only error I get now is that i am using another session_start(); Thanks you should only use one session_start(); call. should be at the very top of the page. Quote Link to comment https://forums.phpfreaks.com/topic/63099-mysql_fetch-problems/#findComment-315008 Share on other sites More sharing options...
chocopi Posted August 6, 2007 Author Share Posted August 6, 2007 it is, i have it on one page and then on anohter page which is required <?php session_start(); require('sessions.php'); ?> // sessions.php <?php session_start(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/63099-mysql_fetch-problems/#findComment-316613 Share on other sites More sharing options...
chocopi Posted August 9, 2007 Author Share Posted August 9, 2007 The problem is still persisting even after removing sessions_start(); at the top of sessions.php The strange thing with this is that it still die()'s on line 35: $row = mysql_fetch_assoc($query) or die(mysql_error()); Yet nothing is being echoed. Now, I know its not a mysql error seeing as nothing is echoed. Then i turned on the error reporting and for a brief time and got this message to appear: Notice: Undefined index: user_familiar_name in /directory/folder/sessions.php on line 35 However, this message isn't showing up anymore yet i have changed squat, but im quite sure its still the same problem. So does anyone know what the above error means, and know how to rectify the problem. By the by the code giving me the problem is: <?php if(empty($user_familiar_name)) { $query = mysql_query("SELECT `name` FROM `kol_familiars` WHERE `id`='$user_familiar'") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); $_SESSION['user_familiar_name'] = $row['name']; $user_familiar_name = ucwords($_SESSION['user_familiar_name']); } ?> Many thanks ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/63099-mysql_fetch-problems/#findComment-319260 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.