Jump to content

Recommended Posts

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

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

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 :/

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>";
?>

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>";
?>

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.

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.