DudleyRay Posted February 16, 2012 Share Posted February 16, 2012 Hey all, I am just learning how to do SQL etc. I have a php script that used to work, but now it doesn't. Can someone tell me if this is the correct code? $sql_Eq = "SELECT Code1 AS Code FROM CodeTable WHERE Code2 = '$computercode'"; Names changed of course. Link to comment Share on other sites More sharing options...
Don E Posted February 16, 2012 Share Posted February 16, 2012 Looks right to me, but if you want to be more precise, you can post the actual code? Link to comment Share on other sites More sharing options...
DudleyRay Posted February 16, 2012 Author Share Posted February 16, 2012 function check_existing($eq,$exists,$ac,$link) { $sql_Eq = "SELECT Code1 AS Code FROM CodeTable WHERE Code2 = '$computercode'"; $typeRow = doQuery($link, $sql_Eq); if ($exists) { // (eg if there is any existing route) echo "Comparing : is $typeRow->CODE inside $eq ?<br>"; if (strpos(" ".$eq,$typeRow->CODE) > 0) { // the ac is there already. do nothing. $need = false; } else { // the ac isn't there. the list must be updated $need = true; } } else { // no route found : must add the route $need = true; } if ($need) { // prepare new ac to be added //echo "Need to add this : $typeRow->CODE<br>"; return $typeRow->CODE.","; } else { return false; } sqlsrv_free_result($types); } Link to comment Share on other sites More sharing options...
justsomeguy Posted February 16, 2012 Share Posted February 16, 2012 What happens when you run that? What do you mean when you say it isn't working? Is there an error message? Link to comment Share on other sites More sharing options...
DudleyRay Posted February 16, 2012 Author Share Posted February 16, 2012 It should fail out if I enter a value that isn't in the table. It should display values that are in the table and it isn't doing that. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 16, 2012 Share Posted February 16, 2012 Add this to the top of whatever page you're running that function on: ini_set('display_errors', 1);error_reporting(E_ALL); Does the doQuery function check for database errors? On the last line you're using a variable called $types that I don't see defined, and the function sqlsrv_free_result isn't a built-in function if you're trying to use one there. Link to comment Share on other sites More sharing options...
DudleyRay Posted February 16, 2012 Author Share Posted February 16, 2012 Notice: Trying to get property of non-object in URL on line 42 This is line 42 return $typeRow->CODE.","; There is stuff I am leaving out I know is working because the information I want added is getting added. Just a one column of a table isn't have data entered. Even though the information is getting added to different columns within the table. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 17, 2012 Share Posted February 17, 2012 That error means that $typeRow is not an object, so doQuery is not returning what you think it is. You can use var_dump if you want to figure out what it's returning. It's fine if you want to leave out code, but I can only answer questions based on what I see. If something that you think is working or is not important is actually important then I can't take that into account if you leave it out. I can tell you that $typeRow is not an object, but I don't know why because I don't know what the doQuery function does for example. Link to comment Share on other sites More sharing options...
DudleyRay Posted February 19, 2012 Author Share Posted February 19, 2012 Thanks for the help, I am going to contact the person who wrote this code. It used to work, and most of the file is. Just one field fails to get entered. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.