I have a file with a table with movie titles. When I wish to edit I click on a link which is represented in this following code:

<a href="edit.php?autoid='.$row['autoid'].'">
           edit</a>

This redirects me to an edit file where I can change the name, year and category. After updating it says title updated but with the following error:
Notice: Undefined index: autoid in C:\wamp\www\edit.php on line 37
When I go back to the main page the title is never updated?
Can someone help me please?
I'll attach my file, so that anyone can see what I'm talking about...
Thanks in advance!

Recommended Answers

All 11 Replies

<input type="hidden" value="$autoid">

The error is in this line, you have forgotten to name this field, so it can't find it in the $_POST array. Try changing to this:

<input type="hidden" name="autoid" value="$autoid">
<input type="hidden" value="$autoid">

The error is in this line, you have forgotten to name this field, so it can't find it in the $_POST array. Try changing to this:

<input type="hidden" name="autoid" value="$autoid">

Hi! Thanks for your reply!
I've tried this out and the error dissapeared, but it didn't update the title, when I changed the year of the movie.

Should it update the TITLE if you change the YEAR?

Should it update the TITLE if you change the YEAR?

I can choose to update either the year, title or the category. So if I update the year it only updates the year. I'm sorry for not being clear. Instead of "editing a title" I should have written "edit movie info" as topic.

Try echo'ing your update sql statement before you run the query. This way you can check the sql that is being run for the correct variables. Another good hint for debugging is to copy and paste that sql statement into an mysql command line and seeing what errors or results it gives you there (as opposed to php errors).

Also, you will need to check that each field has been set. Use the isset method on each of your $_POST retrievals, like so:

if( isset( $_POST[ 'title' ]))
  $titel = $_POST[ 'title' ];

Then you will need to qualify your SQL to only update the fields that are not null.

Try echo'ing your update sql statement before you run the query. This way you can check the sql that is being run for the correct variables. Another good hint for debugging is to copy and paste that sql statement into an mysql command line and seeing what errors or results it gives you there (as opposed to php errors).

Good idea!
I've tried both things. In mySQL the query worked fine. However when I tried echoing the update statement everything was echoed (year,title, category) except autoid. It echoed $id, which means that autoid for some reason never is passed..

Also, you will need to check that each field has been set. Use the isset method on each of your $_POST retrievals, like so:

if( isset( $_POST[ 'title' ]))
  $titel = $_POST[ 'title' ];

Then you will need to qualify your SQL to only update the fields that are not null.

I've tried:

if( isset( $_POST[ 'autoid' ]))
  $id = $_POST[ 'autoid' ];

but it acted normal without any errors and without updating.

Good idea!
I've tried both things. In mySQL the query worked fine. However when I tried echoing the update statement everything was echoed (year,title, category) except autoid. It echoed $id, which means that autoid for some reason never is passed..

If autoid is a numeric field, you don't need the ' marks around it in the SQL statement. If you remove them, the $id should be resolved.

I checked your script.

<input type="hidden" value="$autoid">

is wrong. If you want to have a hidden element with php variable's value, you should do,

<input type="hidden" name="autoid" value="<?php echo $autoid; ?>">

Secondly, Everytime there is a database operation, you have mysql_connect and mysql_select_db in your script. You can put it on top of your script, or have it in a separate file and include it on top of this script.
And lastly, You are not sanitizing your input. Use mysql_real_escape_string to protect your application from sql injections.

I checked your script.
is wrong. If you want to have a hidden element with php variable's value, you should do,

<input type="hidden" name="autoid" value="<?php echo $autoid; ?>">

Secondly, Everytime there is a database operation, you have mysql_connect and mysql_select_db in your script. You can put it on top of your script, or have it in a separate file and include it on top of this script.
And lastly, You are not sanitizing your input. Use mysql_real_escape_string to protect your application from sql injections.

Thank you!!
It worked as a charm! I would never have guessed that it required an echo. Now I learned something new. :icon_cheesygrin:
Once again thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.