bugzy Posted April 22, 2012 Share Posted April 22, 2012 I can't get the value of $edit_proj_name and $edit_content fromn the below code. <?php if(isset($id)) { $edit_proj_id = $_GET['id']; $edit_query = "Select proj_name, content from rec_proj where proj_id = {$edit_proj_id}"; $edit_result = mysql_query($edit_query, $connection); $edit_proj_name = mysql_result($edit_result,$i,"proj_name"); $edit_content = mysql_result($edit_result,$i,"content"); } ?> I wonder what the problem is.. Quote Link to comment https://forums.phpfreaks.com/topic/261434-undefined-variable-problem/ Share on other sites More sharing options...
NLT Posted April 22, 2012 Share Posted April 22, 2012 if(isset($id)) Have you defined that variable or is it meant to be a GET method? if(isset($_GET['id'])) Quote Link to comment https://forums.phpfreaks.com/topic/261434-undefined-variable-problem/#findComment-1339657 Share on other sites More sharing options...
bugzy Posted April 22, 2012 Author Share Posted April 22, 2012 if(isset($id)) Have you defined that variable or is it meant to be a GET method? if(isset($_GET['id'])) hey thank you for the response. It's a get, the value is coming from <a href=\"edit_project.php?id=". mysql_result($result,$i,"proj_id") ."\">[edit]</a> Quote Link to comment https://forums.phpfreaks.com/topic/261434-undefined-variable-problem/#findComment-1339658 Share on other sites More sharing options...
NLT Posted April 22, 2012 Share Posted April 22, 2012 Did you try the code I gave you? Quote Link to comment https://forums.phpfreaks.com/topic/261434-undefined-variable-problem/#findComment-1339660 Share on other sites More sharing options...
bugzy Posted April 22, 2012 Author Share Posted April 22, 2012 pic=358216.msg1693066#msg1693066 date=1335128154] Did you try the code I gave you? I just tried it... Now I'm having this error Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\hee\edit_project.php on line 52 Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\hee\edit_project.php on line 53 5 Quote Link to comment https://forums.phpfreaks.com/topic/261434-undefined-variable-problem/#findComment-1339665 Share on other sites More sharing options...
gizmola Posted April 22, 2012 Share Posted April 22, 2012 bugzy, There are any number of mysteries in your code that could account for your problem. -As pointed out, your code may never be reached because we don't see where $id gets a value. In your snippet it looks like it's undefined. -You do a mysql_query, but you do not check that $edit_result is valid. -You call mysql_result, with a row parameter of $i, which we don't see being assigned anywhere. It should be an integer, starting with '0' for the first row in the result set. Any one of these could be the problem. Quote Link to comment https://forums.phpfreaks.com/topic/261434-undefined-variable-problem/#findComment-1339667 Share on other sites More sharing options...
bugzy Posted April 22, 2012 Author Share Posted April 22, 2012 bugzy, There are any number of mysteries in your code that could account for your problem. -As pointed out, your code may never be reached because we don't see where $id gets a value. In your snippet it looks like it's undefined. -You do a mysql_query, but you do not check that $edit_result is valid. -You call mysql_result, with a row parameter of $i, which we don't see being assigned anywhere. It should be an integer, starting with '0' for the first row in the result set. Any one of these could be the problem. Hello! Thank you very much for the suggestion. -I have posted where variable "id" is coming from the above post. -As I'm using mysql_result and only getting 1 row, isn't the default value of $i will going to be "0" which mean the 1st row? Will I'm going to have a problem even if in mysql query I'm only asking for 1 row? instead of using mysql_result what's the best way that you can suggest to fetch a data from a database? an example using my code above will going to be really helpful... I'm just new so I'm still learning the right way to do it. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/261434-undefined-variable-problem/#findComment-1339670 Share on other sites More sharing options...
bugzy Posted April 22, 2012 Author Share Posted April 22, 2012 got it. I misspelled the table in mysql query. Thanks to those who help me here. Quote Link to comment https://forums.phpfreaks.com/topic/261434-undefined-variable-problem/#findComment-1339676 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.