Member Avatar for OldDeveloper01

Hey if anyone could help me out, that would be superb.

It is probably something simple but i am always getting undefined index messages.

This is the latest example.

Notice: Undefined index: savebtn in C:\xampp\htdocs\practice\editprofile.php on line 20

And this is the php.

if ($username){
		
		require ("scripts/connect.php");
		
		
		
		if ($_POST['savebtn']){
			$forename = fixtext($_POST['forename']);
			$surname = fixtext($_POST['surname']);
			
			$housenona = fixtext($_POST['housenona']);
			$addressline1 = fixtext($_POST['addressline1']);
			$addressline2 = fixtext($_POST['addressline2']);
			$city = fixtext($_POST['city']);
			$postcode = fixtext($_POST['postcode']);
			
			$email = fixtext($_POST['email']);
			$password = fixtext($_POST['password']);
						
			if ($forename && $surname && $email && $password){
				if (strstr($email, "@") && strstr($email, ".") && (strlen($email) >= 6)){
					$password = md5(md5($password));
					$query = mysql_query("SELECT * FROM members WHERE id='$userid' AND password='$password'");
					$numrows = mysql_num_rows($query);
					if ($numrows == 1){
						// set firstname
						mysql_query("UPDATE members SET forename='$forename' WHERE id='$userid'");
						// set lastname
						mysql_query("UPDATE members SET surname='$surname' WHERE id='$userid'");
						// set house no/name
						mysql_query("UPDATE members SET housenona='$housenona' WHERE id='$userid'");
						// set address line 1
						mysql_query("UPDATE members SET addressline1='$addressline1' WHERE id='$userid'");
						// set address line 2
						mysql_query("UPDATE members SET addressline2='$addressline2' WHERE id='$userid'");
						// set city
						mysql_query("UPDATE members SET city='$city' WHERE id='$userid'");
						// set post code
						mysql_query("UPDATE members SET postcode='$postcode' WHERE id='$userid'");
						// set email
						mysql_query("UPDATE members SET email='$email' WHERE id='$userid'");
												
						}
						
						echo "Your information has been saved.";
					}
					else
						echo "Your password was incorrect.";
				}
				else
					echo "You did not provide a valid email.";
			}
			else
				echo "You did not provied the required info.";
		}
		
		$query = mysql_query("SELECT * FROM members WHERE id='$userid'");
		$numrows = mysql_num_rows($query);
		if ($numrows == 1){
			$row = mysql_fetch_assoc($query);
			$id = $row['id'];
			$forename = $row['forename'];
			$surname = $row['surname'];
			$housenona = $row ['housenona'];
			$addressline1 = $row ['addressline1']; 
			$addressline2 = $row ['addressline2']; 
			$city = $row ['city']; 
			$postcode = $row ['postcode'];
			$email = $row['email'];
			$date = $row['date'];
		}
		else
			echo "An error occured while connecting to the database.";
		
		$infoform = "<form action='editprofile.php' method='post' enctype='multipart/form-data'>
		<table cellspacing='5px'>
		<tr>
			<td></td>
			<td><font color='red'>*</font> are required</td>
		</tr>
		<tr>
			<td>First Name:</td>
			<td><input type='text' name='forename' class='textbox' size='35' value='$forename'><font color='red'>*</font></td>
		</tr>
		<tr>
			<td>Last Name:</td>
			<td><input type='text' name='surname' class='textbox' size='35' value='$surname'><font color='red'>*</font></td>
		</tr>
		<tr>
			<td>House no./name </td>
			<td><input type='text' name='housenona' class='textbox' size='35' value='$housenona'><font color='red'>*</font></td>
		</tr>
		<tr>
			<td>Address line 1</td>
			<td><input type='text' name='addressline1' class='textbox' size='35' value='$addressline1'><font color='red'>*</font></td>
		</tr>
		<tr>
			<td>Address line 2</td>
			<td><input type='text' name='addressline2' class='textbox' size='35' value='$addressline2'><font color='red'>*</font></td>
		</tr>
		<tr>
			<td>City</td>
			<td><input type='text' name='city' class='textbox' size='35' value='$city'><font color='red'>*</font></td>
		</tr>
		<tr>
			<td>Post Code</td>
			<td><input type='text' name='postcode' class='textbox' size='35' value='$postcode'><font color='red'>*</font></td>
		</tr>
		<tr>
			<td>Email:</td>
			<td><input type='text' name='email' class='textbox' size='35' value='$email'><font color='red'>*</font></td>
		</tr>
				<tr>
			<td>Current Password:</td>
			<td><input type='password' name='password' class='textbox' size='35'></td>
		</tr>
		<tr>
			<td></td>
			<td><input type='submit' name='savebtn' value='Save Changes' class='button'></td>
		</tr>
		</table>
		</form>";
		
		echo "$infoform";

im having difficulty spotting the mistake. Could somebody help me solve this please.

Thanks

Recommended Answers

All 12 Replies

You get that error because you call

$_POST['savebtn']

without having $_POST
it doesn't exist until after the form is submited

you have to check first.
chanche your if statement to

if( isset($_POST['savebtn']) && $_POST['savebtn']){
Member Avatar for OldDeveloper01

Thanks pzuurveen, that works fine now!

I have this other, a bit more complicated.. i think so anyway.

I am using a style php to pass variable for the sessions when i log in.

I get these two notifications.

Notice: Undefined index: username in C:\xampp\htdocs\practice\styles\top.php on line 3

Notice: Undefined index: userid in C:\xampp\htdocs\practice\styles\top.php on line 4

it is still possible to login and once i do theses message are no longer there.

This is the code..

<?php
session_start();
$username = $_SESSION['username'];
$userid = $_SESSION['userid'];

?>
<html> 
<head> 
<title><?php echo "$title";?></title>
<link href='styles/main.css' rel='stylesheet' type='text/css'></link>
<link rel="shortcut icon" type="image/ico" src="<?php echo $site;?>/images/favicon.ico"></link>
<script language="javascript" src="scripts/javascript.js"></script>


<?php require("scripts/functions.php"); ?>
<style type='text/css'>
<!--
body{
	background-color: #E2DECF;
}
-->
</style>
</head> 
<body>

<div id='wrapper'>
<div id='header'>
	<div id='status'><?php require('scripts/status.php'); ?></div>
	<a href='index.php'><img src='images/logo.png'></img></a>
	

</div>

	<div id='nav'>
		<a href='index.php'>Home</a>
		<a href='register.php'>Cards</a>
	</div>
	
<div id='content'>

Again, if you have any ideas as to why this is happening that would be great.

Thanks

Hi! GUyz could any one help me about this code i dont know what is wrong cuz the second html code is working but this php code it gives me error: Undefined index: username in C:\wamp\www\web.php on line 2... GET AND POSTcode does not working for me! plz any help

<html>
<title>form test </title>
<head>
<?php
$username =$_POST;
print ($username);
?>

</head>
<body>
<Form name = "form" METHOD= "POST" ACTION=" myform.php">
<input type="text" value="username" NAME="user name">
<input type="Submit"name= "submit" value = "login">
</form>
</body>
</html>

<input type="text" value="username" NAME="user name">

Remove value and it will be ok

@brants

It's the same problem
$_SESSION and $_SESSION don't exist jet

if (is_set($_SESSION['username']){
       $username = $_SESSION['username'];
       }

do the same with userid


on second thought:
do you realy need session for your styling?

Hi! GUyz could any one help me about this code i dont know what is wrong cuz the second html code is working but this php code it gives me error: Undefined index: username in C:\wamp\www\web.php on line 2... GET AND POSTcode does not working for me! plz any help

<html>
<title>form test </title>
<head>
<?php
$username =$_POST;
print ($username);
?>

</head>
<body>
<Form name = "form" METHOD= "POST" ACTION=" myform.php">
<input type="text" value="username" NAME="user name">
<input type="Submit"name= "submit" value = "login">
</form>
</body>
</html>

still the same problem! the second html code is working but the first one which contained PHP code it gives some error i wrote above..

Member Avatar for OldDeveloper01

pzuurveen that has not seemed to have worked.

just get the message saying unexpected ; ...

I have used session in styling because the tutorials i was following did it that way!

sorry i forget the second )

if (is_set($_SESSION['username'])) {
       $username = $_SESSION['username'];
       }

that's better

Hi! GUyz could any one help me about this code i dont know what is wrong cuz the second html code is working but this php code it gives me error: Undefined index: username in C:\wamp\www\web.php on line 2... GET AND POSTcode does not working for me! plz any help

<html>
<title>form test </title>
<head>
<?php
$username =$_POST;
print ($username);
?>

</head>
<body>
<Form name = "form" METHOD= "POST" ACTION=" myform.php">
<input type="text" value="username" NAME="user name">
<input type="Submit"name= "submit" value = "login">
</form>
</body>
</html>

Remove the space between user and name in your input (i.e)
Replace this code

<input type="text" value="username" NAME="user name">

with

<input type="text" value="username" NAME="username">

please help me i cant update records

<?php
if( isset($_POST['Submit2']) && $_POST['Submit2']){

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
if (isset($_SESSION['firstname'])) {
       $firstname = $_SESSION['firstname'];
       }
if (isset($_SESSION['email'])) {
       $email = $_SESSION['email'];
       }

$sql = "UPDATE register SET firstname = $firstname WHERE email = $email" ;

mysql_select_db('dbsalon');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
}
else
{}
?>
<?php
 $username = $_POST ['username'];
 $password = $_POST ['password'];

if ($username&&$password)

{
  $connect = mysql_connect("localhost","root"," ") or die ("Error!");

  mysql_select_db("dblogin") or die ("Eroor!");
}
else

   die("invalid username or password");




?>
  • plz check this code :*

Notice: Undefined index: username in C:\xampp\htdocs\login1.php on line 5

Notice: Undefined index: password in C:\xampp\htdocs\login1.php on line 6
invalid username or password

This post is over a year old. And you have't even read it, because your anser is already in here.

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.