lastvision Posted March 7, 2011 Share Posted March 7, 2011 Hi guys. I got some problem with my code i got this error message : Notice: Undefined index: idmembers in C:\Users\su08danielc\Documents\Website\yts\edit_user.php on line 3 And don't know how to solve it This is my code edit_user.php <?php include_once "../yts/inc/connect.php"; $id = $_GET['idmembers']; $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $sql = "UPDATE Members SET username = '$username', password = '$password', email = '$email' WHERE Members . idmembers = '$id' LIMIT 1"; mysql_query($sql) or die ("Error: ".mysql_error()); echo "User Updated. <a href='test.php'> Return to Edit Info</a>"; ?> test.php <?php include_once "../yts/inc/connect.php"; $sql = "SELECT * FROM Members WHERE idmembers = 1"; $results = mysql_query($sql); while ($row = mysql_fetch_array($results)){ $id = $row['idmembers']; $username = $row['username']; $password = $row['password']; $email = $row['email']; //we will echo these into the proper fields } mysql_free_result($results); ?> <html> <head> <title>Edit User Info</title> </head> <body> <form action="edit_user.php" method="post"> userid:<br/> <input type="text" value="<?php echo $id;?>" name="idmembers" disabled/> <br/> Username:<br/> <input type="text" value="<?php echo $username;?>" name="username"/> <br/> Password:<br/> <input type="text" value="<?php echo $password;?>" name="password"/> <br/> Email:<br/> <input type="text" value="<?php echo $email;?>" name="email"/> </br> <input type="submit" value="submit changes"/> </form> </body> </html> Hope you can help me out, Thanks in advance Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/ Share on other sites More sharing options...
doddsey_65 Posted March 7, 2011 Share Posted March 7, 2011 your form method is POST so it should be $_POST['idMembers'] Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/#findComment-1183995 Share on other sites More sharing options...
lastvision Posted March 7, 2011 Author Share Posted March 7, 2011 I tried that but still got the error: Notice: Undefined index: idmembers in C:\Users\su08danielc\Documents\Website\yts\edit_user.php on line 4 Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/#findComment-1183996 Share on other sites More sharing options...
doddsey_65 Posted March 7, 2011 Share Posted March 7, 2011 try using the disabled tag properly. Eg: instead of this: <input type="text" value="<?php echo $id;?>" name="idmembers" disabled/> use this: <input type="text" value="<?php echo $id;?>" name="idmembers" disabled="disabled" /> Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/#findComment-1183997 Share on other sites More sharing options...
silkfire Posted March 7, 2011 Share Posted March 7, 2011 Check to see if $_POST is set; idmembers does not exist until your web site has been submitted/posted. Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/#findComment-1183999 Share on other sites More sharing options...
lastvision Posted March 7, 2011 Author Share Posted March 7, 2011 try using the disabled tag properly. Eg: instead of this: <input type="text" value="<?php echo $id;?>" name="idmembers" disabled/> use this: <input type="text" value="<?php echo $id;?>" name="idmembers" disabled="disabled" /> Have tried that, but with no success Check to see if $_POST is set; idmembers does not exist until your web site has been submitted/posted. Have tried that too, but still doesn't know what the problem is :/ Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/#findComment-1184002 Share on other sites More sharing options...
doddsey_65 Posted March 7, 2011 Share Posted March 7, 2011 can you show how you modified edit_user.php as the error jumped from line 3 to 4 Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/#findComment-1184006 Share on other sites More sharing options...
lastvision Posted March 7, 2011 Author Share Posted March 7, 2011 can you show how you modified edit_user.php as the error jumped from line 3 to 4 <?php include_once "../yts/inc/connect.php"; print_r($_POST); $id = $_POST['idmembers']; $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $sql = "UPDATE Members SET username = '$username', password = '$password', email = '$email' WHERE Members . idmembers = '$id' LIMIT 1"; mysql_query($sql) or die ("Error: ".mysql_error()); echo "User Updated. <a href='test.php'> Return to Edit Info</a>"; ?> Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/#findComment-1184008 Share on other sites More sharing options...
doddsey_65 Posted March 7, 2011 Share Posted March 7, 2011 print_r($_POST); what does that show? Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/#findComment-1184009 Share on other sites More sharing options...
lastvision Posted March 7, 2011 Author Share Posted March 7, 2011 print_r($_POST); what does that show? It just display the information about the variable $_POST. Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/#findComment-1184011 Share on other sites More sharing options...
lastvision Posted March 7, 2011 Author Share Posted March 7, 2011 I have solved it now, made a mistake with the isset code So the code that is working is edit_user.php <?php include_once "../yts/inc/connect.php"; print_r($_POST); if(isset($_POST['idmembers'])){ $id = $_POST['idmembers']; $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $sql = "UPDATE Members SET username = '$username', password = '$password', email = '$email' WHERE Members . idmembers = '$id' LIMIT 1"; mysql_query($sql) or die ("Error: ".mysql_error());} echo "User Updated. <a href='test.php'> Return to Edit Info</a>"; ?> Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/#findComment-1184016 Share on other sites More sharing options...
lastvision Posted March 7, 2011 Author Share Posted March 7, 2011 now i got another problem, it won't update the database, and i don't know how to fix it Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/#findComment-1184018 Share on other sites More sharing options...
Pikachu2000 Posted March 7, 2011 Share Posted March 7, 2011 You haven't fixed the original problem at all. The actual problem here is that the value of a field that has the "disabled" attribute does not get sent in the $_POST array. By enclosing the entire query in the if( isset($_POST['idmembers']) ) {} conditional, all you've done is prevent the query from being reached and executed. Change the form field to use the readonly attribute instead of disabled. Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/#findComment-1184078 Share on other sites More sharing options...
kenrbnsn Posted March 7, 2011 Share Posted March 7, 2011 When you use the "disabled" attribute in a form, that value is not returned to the processing script. If you don't want the user to change the value, you can use either the "readonly" or "hidden" attribute. Ken Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/#findComment-1184081 Share on other sites More sharing options...
lastvision Posted March 7, 2011 Author Share Posted March 7, 2011 Thanks it works fine now Link to comment https://forums.phpfreaks.com/topic/229876-php-error-undefined-index-idmembers/#findComment-1184153 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.