doctortim Posted December 27, 2007 Share Posted December 27, 2007 Hi Just creating the edit page for my blog articles. Obviously its a form that should fill in the fields with that articles stuff ready for editing. Then when I hit the submit button it will update the fields for the blog article entry int he database etc... I'm getting the following error: Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 4 in C:\wamp\www\sites\****\admin\professional\blog\pro_blog_edit.php on line 13 Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 4 in C:\wamp\www\sites\****\admin\professional\blog\pro_blog_edit.php on line 14 Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 4 in C:\wamp\www\sites\****\admin\professional\blog\pro_blog_edit.php on line 15 Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 4 in C:\wamp\www\sites\****\admin\professional\blog\pro_blog_edit.php on line 16 Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 4 in C:\wamp\www\sites\****\admin\professional\blog\pro_blog_edit.php on line 17 Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 4 in C:\wamp\www\sites\****\admin\professional\blog\pro_blog_edit.php on line 18 Here is my php/sql code: <?php include_once("include/connect_sql.inc.php"); $thisArticle_id = $_POST['article_id']; $sql = "SELECT * FROM blogprofessional WHERE article_id = '".$thisArticle_id."'"; $result = mysql_query($sql); $numberOfRows = mysql_num_rows($result); $article_id = mysql_result($result,0,"article_id"); $issue_no = mysql_result($result,0,"issue_no"); $issue_date = mysql_result($result,0,"issue_date"); $focus = mysql_result($result,0,"focus"); $toc = mysql_result($result,0,"toc"); $article = mysql_result($result,0,"article"); ?> Then I place this in the value=" " of each text box/field of the edit form <?php echo $field_name; ?> Where field_name is one of the given variables from above (just here, not in my code of course) So what am I doing wrong? It's surely the second parameter in the mysql_result function!? (Where I currently have 0) Or is it something else??? {The only other source of problem could be the POST not getting the article id number when the page is linked to. I'm hoping this isn't the problem) {{If no-one can see the problem, can they give me some tests to debug with?}} Quote Link to comment https://forums.phpfreaks.com/topic/83354-solved-trouble-with-displaying-article-fields-edit-form/ Share on other sites More sharing options...
doctortim Posted December 27, 2007 Author Share Posted December 27, 2007 just checked and the url string has id=39 so Im guessing we can discount that other possiblility. Someone please help!! Quote Link to comment https://forums.phpfreaks.com/topic/83354-solved-trouble-with-displaying-article-fields-edit-form/#findComment-424077 Share on other sites More sharing options...
kenrbnsn Posted December 27, 2007 Share Posted December 27, 2007 Change your code so that it checks for errors. Also, use the mysql_fetch_assoc() function instead of mysql_result: <?php include_once("include/connect_sql.inc.php"); $thisArticle_id = $_POST['article_id']; $sql = "SELECT * FROM blogprofessional WHERE article_id = '".$thisArticle_id."'"; $result = mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_error()); $numberOfRows = mysql_num_rows($result); if ($numberOfRows > 0) { $rw = mysql_fetch_assoc($result); $article_id = $rw['article_id']; $issue_no = $rw['issue_no']; $issue_date = $rw['issue_date']; $focus = $rw['focus']; $toc = $rw['toc']; $article = $rw['article']; } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/83354-solved-trouble-with-displaying-article-fields-edit-form/#findComment-424081 Share on other sites More sharing options...
PFMaBiSmAd Posted December 27, 2007 Share Posted December 27, 2007 Edit: Basically says the same as kenrbnsn's post - Here is a run down of the problems - mysql_result() is rarely used. It is about the slowest way of retrieving fields from a row in the result set. It also has the unfortunate side effect of generating the error you are getting when the query worked but there are simply zero rows in the result set. However, in your case this is probably due to a more serious problem, like a query that failed due to no connection to the mysql server, no database selected, or a syntax error in your query. Use mysql_fetch_assoc() function to fetch one whole row from the result set at one time, then use the individual data elements directly in your code. Your code has no error checking and error reporting for the mysql_query() statement, so it is possible that the query failed but your code will never tell you. Your code is accessing the mysql_num_rows() function but is not using the results, so it is also possible that there are simply no matching rows in the database and the result set is empty. Start by changing your code to this - $result = mysql_query($sql) or die("Query failed: " . mysql_error()); Your code should also check if there were any rows returned and take appropriate action - if($numberOfRows > 0) { // code to process the result set } else { // zero rows in the result set echo "Sorry, no matching data in the database<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/83354-solved-trouble-with-displaying-article-fields-edit-form/#findComment-424095 Share on other sites More sharing options...
doctortim Posted December 27, 2007 Author Share Posted December 27, 2007 Hey, Thanks guys. I combined both of your suggestions. That seems to have gotten rid of the errors I was having before. But now I'm getting the error: Sorry, no matching data in the database It's saying the record is empty or something, right? I have been inserting records into the db fine, so I know there is no connection problems or such. (I hope!) The end of the url telling it which article I want to edit is displaying the correct id... http://localhost/sites/****/admin/professional/blog/pro_blog_edit.php?article_id=38 Is the problem perhaps with my sql querry?? $thisArticle_id = $_POST['article_id']; $sql = "SELECT * FROM blogprofessional WHERE article_id = '".$thisArticle_id."'"; Quote Link to comment https://forums.phpfreaks.com/topic/83354-solved-trouble-with-displaying-article-fields-edit-form/#findComment-424149 Share on other sites More sharing options...
kenrbnsn Posted December 27, 2007 Share Posted December 27, 2007 If you're sending the article_id via the URL, you need to use $_GET, not $_POST. Ken Quote Link to comment https://forums.phpfreaks.com/topic/83354-solved-trouble-with-displaying-article-fields-edit-form/#findComment-424154 Share on other sites More sharing options...
doctortim Posted December 27, 2007 Author Share Posted December 27, 2007 so do I change the form's method to get as well? Quote Link to comment https://forums.phpfreaks.com/topic/83354-solved-trouble-with-displaying-article-fields-edit-form/#findComment-424162 Share on other sites More sharing options...
doctortim Posted December 27, 2007 Author Share Posted December 27, 2007 oooppss, sorry realised its a url sending it, not a form with a method. Thanks Ken it works now, learnt something new. Been a bit confused bout get and post so far. Quote Link to comment https://forums.phpfreaks.com/topic/83354-solved-trouble-with-displaying-article-fields-edit-form/#findComment-424163 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.