Undefined Index
Posted by: zayadjaffar (182.181.204.---)
Date: November 17, 2013 04:37PM

( ! ) Notice: Undefined index: action in C:\wamp\www\PHP\php-practice\University\admin\login.php on line 7
Call Stack
# Time Memory Function Location
1 0.0020 144848 {main}( ) ..\login.php:0


My code is perfect and working hundred percent correct.
i dont know what is the problem, i think problem is in php.ini but i dont know how to fix it.

Options: ReplyQuote
Re: Undefined Index
Posted by: Otomatic (Moderator)
Date: November 17, 2013 05:34PM

Hi,

- Your code is not perfect.
- A code that runs without fault somewhere can not be considered flawless.
- You want to use an array with an index 'action', but this index has never been defined, that is to say, nowhere you have given it any value.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: Undefined Index
Posted by: zayadjaffar (182.181.204.---)
Date: November 17, 2013 06:36PM

See my code, whats wrong in it???


<?php
include("../conn/conn.php"winking smiley;
session_start();
?>
<?php
// login.
if($_GET['action']=="login"winking smiley{
$username=$_POST['username'];
$password=$_POST['password'];
$sel=mysql_query("select * from users"winking smiley;
while($ss=mysql_fetch_array($sel)){
$userdb=$ss['username'];
$passdb=$ss['password'];
if($username==$userdb && $password==$passdb){
$_SESSION['admin']=$username;
header("location:main.php"winking smiley;
}
else
{
$msg="Invalid Username or Password";
}
}
}
if($_GET['action']=="logout"winking smiley{
unset($_SESSION['admin']);
}
?>

Options: ReplyQuote
Re: Undefined Index
Posted by: Otomatic (Moderator)
Date: November 17, 2013 06:56PM

Hi,

> if($_GET['action']=="login"
The problem is If $_GET['action'] does not exist!

<?php
// login.
if(isset($_GET['action']) && $_GET['action']=="login" ) {
$username=$_POST['username'];
$password=$_POST['password'];
....
or to cover all other cases:
<?php
// login.
if(!isset($_GET['action'])) $_GET['action'] = "";
if($_GET['action']=="login" ) {
$username=$_POST['username'];
$password=$_POST['password'];
...
or
<?php
// login.
$action = (isset($_GET['action']) ? $_GET['action'] : "" );
if($action == "login" ) {
$username=$_POST['username'];
$password=$_POST['password'];
...

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: Undefined Index
Posted by: zayadjaffar (182.185.45.---)
Date: November 17, 2013 08:06PM

Thanks Otomatic (Moderator) ... Problem Solved smiling smiley smiling smiley smiling smiley smiling smiley

Options: ReplyQuote
Re: Undefined Index
Posted by: volak (42.115.34.---)
Date: April 19, 2014 05:07PM

Pls help me

Undefined index: action

<?php if($current_page != ''){ ?>
<div id="staff">
<ul>
<?php

if($_GET['action']=='addnew' || $_GET['action']=='edit'){
echo "<li onclick='validate_form(\"".$current_page."\"winking smiley;'><img src=\"images/save.png\" alt=\"\" />Save/li>";
echo "<li onclick='window.location.href=\"?\";'><img src=\"images/cancel.png\" alt=\"\" />Cancel</li>";
}
else{
echo "<li onclick='window.location.href=\"?action=addnew\";'><img src=\"images/add_new.png\" alt=\"\" />Add</li>";
if($current_page != 'category' && $_GET['action']!='restore'):
echo "<li onclick='delete_edit_restore(\"delete\",\"".$current_page."\"winking smiley;'><img src=\"images/delete.png\" alt=\"\" />Delete</li>";
endif;
echo "<li onclick='delete_edit_restore(\"".(($_GET['action']!='detail')?'edit':'detail')."\",\"".$current_page."\"winking smiley;'><img src=\"images/edit.png\" alt=\"\" />កែប្រែ</li>";
if($current_page != 'category'):
if($_GET['action']=='restore'){
echo "<li onclick='delete_edit_restore(\"restore\",\"".$current_page."\"winking smiley;'><img src=\"images/restore.png\" alt=\"\" />Restore</li>";
}else{
echo "<li onclick='window.location.href=\"?action=restore\";'><img src=\"images/add_new.png\" alt=\"\" />Restore</li>";
}
endif;
if($_GET['action']=='detail' || $_GET['action']=='restore'):
echo "<li onclick='window.location.href=\"?\";'><img src=\"images/cancel.png\" alt=\"\" />Cancel</li>";
endif;
}
?>
</ul>
</div>
<?php }?>

Options: ReplyQuote
Re: Undefined Index
Posted by: RiggsFolly (---.ppp.as43234.net)
Date: April 19, 2014 05:36PM

The value $_GET['action'] obviously does not exist in the $_GET array.

Add this debug code.




<?php 

echo '<pre>' . print_r($_GET,true) . '</pre>';

if($current_page != ''){ 
?>
<div id="staff">
<ul>
<?php

if($_GET['action']=='addnew' || $_GET['action']=='edit'){

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-



Edited 1 time(s). Last edit at 04/19/2014 05:36PM by RiggsFolly.

Options: ReplyQuote
Notice: Undefined variable: _post in C:\wamp\www\new\view.php
Posted by: kavitha03 (106.208.102.---)
Date: June 25, 2015 08:35PM

Notice: Undefined variable: _post in C:\wamp\www\new\view.php

iam getting this warning in update and view ...my table is nt retrived also what is problem i cant find help me out ...



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[www.w3.org];
<html xmlns="[www.w3.org];
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table align="center" border="1">
<tr><td><a href="addemp.php">ADD EMPLOYEE</a></td><td><a href="wel.php">VIEW EMPLOYEE</a></td></tr>
</table>
<br />

<?php
// Connects to your Database
$id=$_GET['id'];
include ("db.php"winking smiley;
$results = @mysql_query("SELECT * from list where id='$id'"winking smileyor die(mysql_error());
Print "<table bgcolor='blue' border cellpadding=3 width='760' align='center'>";
Print"<tr><td colspan='9' align='center' id='success'>";
if(isset($_GET['success']))echo $_GET['success'];
Print" </td>";
Print"</tr>";
Print"<tr><td colspan='9' align='center' id='failed'>";
if(isset($_GET['failed']))echo $_GET['failed'];
Print"</td>";
Print"</tr>";
Print"<tr bgcolor='#999999'><td><b>ID</b></td>";
Print"<td><b>FirstName</b></td>";
Print"<td><b>LastName</b></td>";
Print"<td><b>Department</b></td>";
Print"<td><b>email</b></td>";

$i=1;
while($row = mysql_fetch_array( $results))
{

Print "<tr>";
Print "<td>".$i. "</td> ";
Print " <td>".$row['firstname'] . "</td> ";
Print " <td>".$row['lastname'] . " </td>";
Print " <td>".$row['department'] . " </td>";
Print " <td>".$row['email']. " </td>";
"</tr>";
echo '<td align="center"><a href="viewdetail1.php?id='.$id.'">view</a></td>
<td align="center"><a href="editdetail.php?id='.$id.'">Edit</a> </td> </tr>';

$i++;
}
Print "</table>";
?>
</body>
</html>

Options: ReplyQuote
Notice: Undefined variable: _post in C:\wamp\www\new\view.php
Posted by: kavitha03 (106.208.102.---)
Date: June 25, 2015 08:36PM

Notice: Undefined variable: _post in C:\wamp\www\new\view.php

iam getting this warning in update and view ...my table is nt retrived also what is problem i cant find help me out ...



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[www.w3.org];
<html xmlns="[www.w3.org];
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table align="center" border="1">
<tr><td><a href="addemp.php">ADD EMPLOYEE</a></td><td><a href="wel.php">VIEW EMPLOYEE</a></td></tr>
</table>
<br />

<?php
// Connects to your Database
$id=$_GET['id'];
include ("db.php"winking smiley;
$results = @mysql_query("SELECT * from list where id='$id'"winking smileyor die(mysql_error());
Print "<table bgcolor='blue' border cellpadding=3 width='760' align='center'>";
Print"<tr><td colspan='9' align='center' id='success'>";
if(isset($_GET['success']))echo $_GET['success'];
Print" </td>";
Print"</tr>";
Print"<tr><td colspan='9' align='center' id='failed'>";
if(isset($_GET['failed']))echo $_GET['failed'];
Print"</td>";
Print"</tr>";
Print"<tr bgcolor='#999999'><td><b>ID</b></td>";
Print"<td><b>FirstName</b></td>";
Print"<td><b>LastName</b></td>";
Print"<td><b>Department</b></td>";
Print"<td><b>email</b></td>";

$i=1;
while($row = mysql_fetch_array( $results))
{

Print "<tr>";
Print "<td>".$i. "</td> ";
Print " <td>".$row['firstname'] . "</td> ";
Print " <td>".$row['lastname'] . " </td>";
Print " <td>".$row['department'] . " </td>";
Print " <td>".$row['email']. " </td>";
"</tr>";
echo '<td align="center"><a href="viewdetail1.php?id='.$id.'">view</a></td>
<td align="center"><a href="editdetail.php?id='.$id.'">Edit</a> </td> </tr>';

$i++;
}
Print "</table>";
?>
</body>
</html>

Options: ReplyQuote
Re: Notice: Undefined variable: _post in C:\wamp\www\new\view.php
Posted by: RiggsFolly (---.as43234.net)
Date: June 25, 2015 08:56PM

If you are going to supply an error message then please supply all of it.
This error comes with a line number and a file name.


Is this the file containing the error, I dont think so.


Also this site is for people having problems getting WAMPServer running, and not for people who dont know how to code PHP.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote


Sorry, only registered users may post in this forum.