overlordofevil Posted April 2, 2008 Share Posted April 2, 2008 ok this is probably a simple issue but I can't figure it out. I am working on trying to write a function that takes an id number and then pulls a name from another table. My problem is it errors out on me. I think it is not taking the variable i supply for the function but I don't know so here is my code please take a look and see if I messed up. ok here is the first part of my main interface this pulls up the info to display to the user. <?php session_start(); ?> <html> <body> <?php //this should print out a character sheet include ("misc.inc"); include ("functions.inc"); $uid=$_GET["cid"]; $conn = mysql_connect($msql_server, $msql_user, $msql_password) or die ("Unable to Connect"); mysql_select_db($msql_db, $conn) or die ("Unable to Connect to DB"); $query = "SELECT * FROM characters where cid='$uid'"; $result = mysql_query($query) or die ("Couldn't execute query for character."); $row = mysql_fetch_array($result); extract($row); $cname = "$firstname $lastname"; $raceid = $race;//this is the info to send in the function $racename = getracename($raceid); //calling the function $query1 = "SELECT * FROM demographics where id='$row[id]'"; $result1 = mysql_query($query1) or die ("Couldn't execute query for player name."); $row1 = mysql_fetch_array($result1); extract($row1); $pname= "$firstname $lastname"; echo "<br align='center'><h3>NERO Character Sheet</h3>\n"; echo "<table border='0' cellspacing='15'> <tr><td>Character Name: </td><td>$cname </td><td></td><td>Player's Name: </td><td>$pname </td><td></td><<td>Race: </td><td>$racename</td><td></td><td>Subrace: </td>$subrace<td></td></tr> <tr><td></td><td></td><td></td><td></td><td></td><td></td></tr> <tr><td>Total Build:</td><td>$build</td><td></td><td>Loose Build: </td><td>$freebuild</td><td></td><td>Body Point: </td><td>$body</td><td></td><td>Level: </td><td>$level</td><td></td><td>Deaths: </td><td>$deaths</td></tr> <tr></tr> <tr><td></td></tr> </table>\n"; ?> </body> </html> ok here is my function that I have stored in another file called functions <?php function getracename($raceid) { $result = mysql_query("SELECT * FROM `race_info` WHERE `raceid` = '$raceid'") or die ("Couldn't execute query for race."); $line = mysql_fetch_array($result); if ($line['racename']) { return $line['racename']; } } ?> any help would be appreciated Like I said I think it is something really simple that I am missing but I just can't see it. Link to comment https://forums.phpfreaks.com/topic/99267-solved-function-help/ Share on other sites More sharing options...
trq Posted April 2, 2008 Share Posted April 2, 2008 And the error is? Link to comment https://forums.phpfreaks.com/topic/99267-solved-function-help/#findComment-507913 Share on other sites More sharing options...
overlordofevil Posted April 2, 2008 Author Share Posted April 2, 2008 it brings up my "DIE" message -Couldn't execute query for race. so thats why I am confused as everything looks correct. Link to comment https://forums.phpfreaks.com/topic/99267-solved-function-help/#findComment-507931 Share on other sites More sharing options...
Northern Flame Posted April 2, 2008 Share Posted April 2, 2008 try switching: include ("misc.inc"); include ("functions.inc"); $uid=$_GET["cid"]; $conn = mysql_connect($msql_server, $msql_user, $msql_password) or die ("Unable to Connect"); mysql_select_db($msql_db, $conn) or die ("Unable to Connect to DB"); with: include ("misc.inc"); $uid=$_GET["cid"]; $conn = mysql_connect($msql_server, $msql_user, $msql_password) or die ("Unable to Connect"); mysql_select_db($msql_db, $conn) or die ("Unable to Connect to DB"); include ("functions.inc"); Link to comment https://forums.phpfreaks.com/topic/99267-solved-function-help/#findComment-507935 Share on other sites More sharing options...
overlordofevil Posted April 2, 2008 Author Share Posted April 2, 2008 tried that and it still brings up my die message. I also pulled the function and tried adding the query to the main file and it still gives me the error message so I think its not pulling the variable and I just don't knwo what I am missing. I already tested the table and i am able to do a general query (example listed below) of the info and get a list of everything but for some reason when I try to specify info (using the where option) pulled from one table it just rejects it. $query1 = "SELECT * FROM race_info"; $result1 = mysql_query($query1) or die ("Couldn't execute query for race."); echo "<br align='center'><h3>Base Races</h3>\n"; while ($row1 = mysql_fetch_array($result1)) { extract($row1); echo "<table><tr><td>Race ID: </td><td>$raceid</td><td></td><td>Race Name: </td><td>$racename</td></tr></table>\n"; } I think it is the variable I am using but I just can't figure it out. Link to comment https://forums.phpfreaks.com/topic/99267-solved-function-help/#findComment-507945 Share on other sites More sharing options...
trq Posted April 2, 2008 Share Posted April 2, 2008 Replace your die with something more helpfull. die(mysql_error()) Link to comment https://forums.phpfreaks.com/topic/99267-solved-function-help/#findComment-507982 Share on other sites More sharing options...
Northern Flame Posted April 2, 2008 Share Posted April 2, 2008 wait i found your error $raceid = $race;//this is the info to send in the function $racename = getracename($raceid); //calling the function $race was never established Link to comment https://forums.phpfreaks.com/topic/99267-solved-function-help/#findComment-507986 Share on other sites More sharing options...
overlordofevil Posted April 2, 2008 Author Share Posted April 2, 2008 ok changed the die message and it tells me the table doesn't exist. thanks for the help Now to figure out why it can't find the table. Link to comment https://forums.phpfreaks.com/topic/99267-solved-function-help/#findComment-507990 Share on other sites More sharing options...
overlordofevil Posted April 2, 2008 Author Share Posted April 2, 2008 actually race is the cell from the table. Link to comment https://forums.phpfreaks.com/topic/99267-solved-function-help/#findComment-507992 Share on other sites More sharing options...
overlordofevil Posted April 3, 2008 Author Share Posted April 3, 2008 ok to adjust my last statements. the variable $race is part of the table and i was tryign to pull the data with the extract command. When I changed up the die command the exact error I got it is Table 'nerodb2.race_info' doesn't exist so for some reason when i try to do the function it cant find the table even though I know its there and was able to get the data from a different script that just calls this one table. I have looked over everything i can find on the table doesn't exist error and i am not finding any problems. any suggestions on a setting i should try. Thanks for all the help. Link to comment https://forums.phpfreaks.com/topic/99267-solved-function-help/#findComment-508019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.