I'm totally a newbie in the world of PHP and MySQL. I am reading the book of Kevin Yank and while doing one of his examples, I encountered a weird outcome. I'm sure I followed and typed correctly the code written on his book but I wondered why I'm not getting the same result. I've checked the code back and forth and sure that it is right or maybe I'm missing something.

I'm posting this here because I know a lot from here are very helpful and very kind to starters like me. Any inputs are highly appreciated. Looking forward for comments so that I can proceed with my studies because I think I am stuck because of this weird error.

The problem is that when I click the "Delete" button, it would not delete the author entry. I am sure I typed it right and wondering why I'm not getting the desired result. I am hoping that someone could help me resolve this one.

Drummin
—
2014-03-04T06:49:46Z —
#4

Without getting all into this, aren't you missing the name="id" here?

<input type="hidden" value="<?php echo htmlout($author['id']); ?>"/>

SpacePhoenix
—
2014-03-04T07:37:39Z —
#5

Add these lines after the <?php at the start of the file:

error_reporting(-1);
ini_set('display_errors', 1);

They will cause any errors, warnings and notices to be displayed. For a live site you wouldn;t display any errors, warnings and notices, instead you would log them to an error file

Karl_A
—
2014-03-04T10:03:21Z —
#6

Drummin said:

Without getting all into this, aren't you missing the name="id" here?

<input type="hidden" value="<?php echo htmlout($author['id']); ?>"/>

There you are!Thanks Drummin for the keen eye, this problem is solved now. I'm starting to wonder now what really the name attribute does.But anyways, thanks a lot for the comment. This is what usually happens when you're sleepy coding/studying.

Cheers,Karl

Karl_A
—
2014-03-04T10:05:20Z —
#7

SpacePhoenix said:

Add these lines after the <?php at the start of the file:

`php

error_reporting(-1);ini_set('display_errors', 1);

`

They will cause any errors, warnings and notices to be displayed. For a live site you wouldn;t display any errors, warnings and notices, instead you would log them to an error file

Thanks for the tip bro.

Drummin
—
2014-03-06T23:12:28Z —
#8

I'm starting to wonder now what really the name attribute does

The name identifies the input field and will be the key in the $POST array with its matching value. So <input name="toy" value="ball" /> becomes $POST['toy'] would be ball.

Karl_A
—
2014-03-07T03:29:38Z —
#9

Drummin said:

The name identifies the input field and will be the key in the $POST array with its matching value. So <input name="toy" value="ball" /> becomes $POST['toy'] would be ball.

Thanks for that clear explanation, I really learned from your comments.

Karl_A
—
2014-03-09T12:47:02Z —
#10

Drummin said:

The name identifies the input field and will be the key in the $POST array with its matching value. So <input name="toy" value="ball" /> becomes $POST['toy'] would be ball.

Hi Drummin,I am just wondering what's the difference between an

id

and

name

attribute. I often notice that both attributes have the same value.Thanks!

Drummin
—
2014-03-09T16:52:02Z —
#11

The name used in form inputs are the identifier that is sent on POST or GET that becomes the key as I already mentioned. The same name can be used more than on time as with radio buttons where a group might have the same name but only the selected radio value is sent to POST. An id on the other hand must be unique on a given page and is often used in Javascript where they want to reference an element by the id or style the element with css. The value given to an id is not sent to POST.

Karl_A
—
2014-03-10T03:09:31Z —
#12

Drummin said:

The name used in form inputs are the identifier that is sent on POST or GET that becomes the key as I already mentioned. The same name can be used more than on time as with radio buttons where a group might have the same name but only the selected radio value is sent to POST. An id on the other hand must be unique on a given page and is often used in Javascript where they want to reference an element by the id or style the element with css. The value given to an id is not sent to POST.

Thanks again for that Drummin, I understand it now clearly.I have another question for you if you don't mind, I am curious too with the fetch() and fetchAll(). Can you explain what's the difference between the two?Thanks for your patience and enlightenment.

Drummin
—
2014-03-10T23:25:53Z —
#13

Well I'm sure others could describe this better, but fetchall() is going to return the complete query result as an array that you can later loop through in some other way, e.g. using foreach()The fetch() returns a single row of the fields defined in the query containing both the numeric array key and the column name for each field. Unless grabbing a single row of data, you will need to use WHILE to loop through each row. I tend to use FETCH_ASSOC as I just want column names in a WHILE loop. There may be times you just want FETCH_NUM for just using the numeric key. Just depends on what you're wishing to do.