Jump to content

[SOLVED] trouble with displaying article fields edit form


doctortim

Recommended Posts

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?}}

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 />"; 
}

Link to comment
Share on other sites

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."'";

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.