mysql - mysqli error when updating query php mysqli targeting specific id -
I $ GET_ [id]; I'm trying to target a specific ID from the URL using
. This works to get the ID but when I click submit button to update it, then I get 2 errors notice: undefined index: id
and Fatal error: member function fetch_assoc () Call
in the non-object that refers to the first 2 lines of code
Query ("Select * from player WHERE id = $ _GET [id]"); $ Person = $ result- & gt; Fetch_assoc (); ? & Gt; If (isset ($ _ POST ['submit'])) {$ db- & gt; Query ("UPDATE player-bio SET 'Player-ID' = '$ _ POST [Player-ID]', 'Date-Created' = NOW () WHERE id = $ _POST [ID]"); Header ('location: test_input.php'); } & Lt; Form action = "& lt ;? php echo $ _SERVER ['PHP_SELF'] ;? & gt;" Method = "post" & gt; Player ID: & lt; Input type = "text" name = "PlayerID" value = "& lt ;? php echo $ person ['PlayerID'] ;? & gt;" / & Gt; & Lt; Input type = "hidden" name = "id" value = "& lt ;? Php echo $ _GET ['id'] ;;>" / & Gt; & Lt; Input type = "submit" name = "submit" /> & Lt; / Form & gt;
Be sure to understand the changes you made.
- You ran a php code outside the php tag
- Actually you are trying to reach $ _POST without inserting 'id' as a string
- Do you save $ _GET ['id'] twice not just in the variable?
- You are selecting from ID, limit the query to 1, it will be faster.
- In the form you are using $ _POST '[PlayerID'] can be the reason for this warning without actually making sure that it actually exists.
(I can not put the answer here at the beginning & lt ;? php, why not know, anyway. Do not forget to start with php openig)
$ id = isset ($ _ GET ["id"])? $ _GET ["id"]: 0; $ Result = $ db- & gt; Query ("Select * FROM` PlayerBoos' Where ID =". $ Id); $ Person = $ result- & gt; Fetch_assoc (); If (empty ($ person ['player IDID']) $ person ['player IDID'] = ""; ($ _ POST ['submit']) & amp; Continue ($ _ POST ['Player-ID']) & Issued ($ _ POST ['id']) {$ db- & gt; ; Query ("player-bio set 'player-id' = '". $ _POST [' player-id '].' ',' Date-created '= now () Where id = ". $ _POST [' id '] "LIMIT 1"); Header ('location: test_input.php');}? & Gt; & gt; form action = "& lt ;? Php echo $ _SERVER ['PHP_SELF'] ;? & Gt; "method =" post "& gt; player id: & lt; input type =" text "name =" PlayerID "value =" & lt ;? Php echo $ person ['PlayerID'] ;? & Gt; "/" & gt; Input type = "hidden" name = "id" value = "& lt ;? Php echo $ id ;; & Gt; "/ & gt; Input Type =" submit "name =" submit "/>
Comments
Post a Comment