Notice: Undefined index while deleting the item - php

I am trying to delete an entry, But constantly getting these errors:
Notice: Undefined index: wineTypeID in
/storage/ssd5/765/3453765/public_html/wine_action.php on line 33
Notice: Undefined index: wineName in
/storage/ssd5/765/3453765/public_html/wine_action.php on line 34
Notice: Undefined index: wineSize in
/storage/ssd5/765/3453765/public_html/wine_action.php on line 35
Notice: Undefined index: winePrice in
/storage/ssd5/765/3453765/public_html/wine_action.php on line 36
my code looks like this
<?php
// include the connection stream include 'connectYes.php';
// here are the two hiddent fields
// they tell the script is this is an add, update or delete
// and for an update and delete, they pass the id
$action = $_REQUEST["action"];
$id = $_REQUEST["id"];
$wineTypeID = $_REQUEST["wineTypeID"];
$wineName = $_REQUEST["wineName"];
$wineSize = $_REQUEST["wineSize"];
$winePrice = $_REQUEST["winePrice"];
if ($action == 'a') {
$query = "insert into WINE values (
null,
'$wineTypeID',
'$wineName',
'$wineSize',
'$winePrice'
)";
mysqli_query($conn,$query)
or die (mysqli_error());
print "<h3>The Item $wineName is added to the List</h3>";
" </h3>";
}
if ($action == 'u') {
$query = "update WINE
set wineTypeID = '$wineTypeID',
wineName = '$wineName',
wineSize = '$wineSize',
winePrice = '$winePrice'
where wineID = '$id'";
mysqli_query($conn, $query)
or die(mysqli_error());
print "<h3>Update Successful</h3>";
} // end u
if ($action == 'd') {
$query = "delete from WINE
where wineID = '$id'";
mysqli_query($conn, $query)
or die("query failed:" . mysqli_error());
print "<h3>Delete Successful</h3>";
}
?>}
Links to my page :- my page
Link to my files :- Php Files
mysql structure Image :-Mysql structure

Please check you request parameters whether "wineTypeID" paremeter is passing or not.

Related

query works, nothing happens

Ok, I have changed the code to two different querys and cut the GET_$ID semicolon and place it like the isset POST variables.
Now I get two new errors:
Notice: Undefined index: edit in C:\wamp64\www\projekt\edit.php on line 20
"$ID = $_GET['edit']; "
Notice: Undefined variable: title in C:\wamp64\www\projekt\edit.php on line 23
"SET title='$title'" "ID = $ID"
So something is lost from the ID or POST.
I have dumped all the values so they exist, is there something wrong with the syntax?
if (isset($_POST['submit']))
{
// input array
if (isset($_POST['title'])
&& isset($_POST['director'])
&& isset($_POST['year'])
&& isset($_POST['genre'])
&& isset($_GET['edit']))
// filter txt input
$title = filter_input(INPUT_POST,'title',FILTER_SANITIZE_SPECIAL_CHARS);
$director = filter_input(INPUT_POST,'director',FILTER_SANITIZE_SPECIAL_CHARS);
$year = filter_input(INPUT_POST,'year',FILTER_SANITIZE_SPECIAL_CHARS);
$category = $_POST['genre'];
$ID = $_GET['edit'];
// Edit query
$sql = "UPDATE movies
SET title='$title' director='$director' year='$year'
WHERE ID='$ID'";
$insert = mysqli_insert_id($conn);
$insert = "UPDATE category
SET category='$category'
WHERE ID='$ID'";
if ($conn->query($sql) && $conn->query($insert) === TRUE) {
echo "<div class='receipt'>Record ".$ID." updated successfully<br>
<a href='index.php'>Gå tillbaka</a> </div>";
} else {
echo "Fel vid anslutning : " . $conn->error;
}
} $conn->close();

how to capture undefined error in php when selecting from different tables which do not have all the required data using and operator

Hello Developers.
Am working on an application where i have to select data from different tables and views.
However some views may not have the corresponding data i have queried yet the other tables have the required data.
This gives me undefined error response for the views where the data for a selected variables is not found in the view.
How best can i write my code. see below.
error returned
Notice: Undefined variable: fname in C:\wamp\www\Kesa\web\add_shares.php on line 175
Notice: Undefined variable: mname in C:\wamp\www\Kesa\web\add_shares.php on line 175
Notice: Undefined variable: lname in C:\wamp\www\Kesa\web\add_shares.php on line 175
Notice: Undefined variable: passbook_no in C:\wamp\www\Kesa\web\add_shares.php on line 176
Notice: Undefined variable: share_amount in C:\wamp\www\Kesa\web\add_shares.php on line 177
if(isset($_POST['button2'])){
$id = mysql_real_escape_string($_POST['slt_member_id']);
//selecting employee details
$query = "SELECT member_tbl.fname AS fname,
member_tbl.mname AS mname,
member_tbl.lname AS lname,
member_tbl.member_id AS member_id,
member_tbl.Pasbook_no AS passbook_no,
share_view.share_amount AS share_amount
FROM member_tbl, share_view
WHERE member_tbl.member_id = '$id'
AND member_tbl.member_id = share_view.member_id";
$result = mysql_query($query, $connection);
while($res=mysql_fetch_array($result)){
$share_amount = $res['share_amount'];
if(isset($share_amount) || !empty($share_amount)){
$member_id = $res['member_id'];
$fname = $res['fname'];
$mname = $res['mname'];
$lname = $res['lname'];
$passbook_no = $res['passbook_no'];
$share_amount = $res['share_amount'];
}elseif(!isset($share_amount) || empty($share_amount)){
$member_id = $res['member_id'];
$fname = $res['fname'];
$mname = $res['mname'];
$lname = $res['lname'];
$passbook_no = $res['passbook_no'];
$account_type = 'User has no shares';
$share_amount = 'User has no shares';
}else{
$member_id = '';
$fname = 'No user selected';
$mname = '';
$lname = '';
$passbook_no = 'No user selected';
$account_type = 'No user selected';
$share_amount = 'No user selected';
}
}//closing selection from members tbl
}else {
$member_id = '';
$fname = 'No user selected';
$mname = '';
$lname = '';
$passbook_no = 'No user selected';
$account_type = 'No user selected';
$share_amount = 'No user selected';
}
Fetch your result as an associative array with fetch_assoc(). Then you can access the result via the column name. Currently you are fetching the result as an indexed array by fetch_array(). So you will have to access the values as $result[1].

Notice: Undefined index: SESS_NAME in student_vote.php on line 9

<?php
include "connection.php";
if(!isset($_SESSION))
{
session_start();
}
$cand1 = $_POST['cand1'];
$cand2 = $_POST['vice1'];
$sess = $_SESSION['SESS_NAME'];
if(!$cand1){
$error="<center><h4><font color='#FF0000'>Please fill empty fields</h4></center></font>";
include"student.php";
exit();
}
$cand1 = addslashes($cand1);
$cand1 = mysqli_real_escape_string($con,$cand1);
$sql = 'SELECT * FROM student WHERE username="'.$_SESSION['SESS_NAME'].'" AND status="VOTED"';
$result = mysqli_query($con,$sql);
if (mysqli_num_rows($result)==1){
$msg="<center><h4><font color='#FF0000'>You have already been voted, No need to vote again</h4></center></font>";
include 'student.php';
exit();
}
else{
$sql = 'UPDATE candidate SET votecount = votecount + 1 WHERE cand_id = "'.$_POST['cand1'].'" OR cand_id = "'.$_POST['vice1'].'"';
$sql2 = 'UPDATE student SET status="VOTED" WHERE username="'.$_SESSION['SESS_NAME'].'"';
$result = mysqli_query($con,$sql);
$result2 = mysqli_query($con,$sql2);
if(!$result && !$result2){
die("Error on mysql query".mysqli_error());
}
else{
$msg="<center><h4><font color='#FF0000'>Congratulation, you have made your vote.</h4></center></font>";
include 'student.php';
exit();
}
}
?>
the errors are at code including
$sess= $_SESSION['SESS_NAME']; and at username="'.$_SESSION['SESS_NAME'].'"
i have tried every possibility so can you check my code?
mainly the error is undefined index at $session[session_name]?
Are you sure the session 'SESS_NAME' is getting set? In the code above you are only trying to access its value. Undefined index is the error thrown when there is no session with that name.
Looks like to me you haven't declared the variable $_SESSION['SESS_NAME']. Try doing the following
var_dump($_SESSION);
This will show you all the defined variables in the session, if SESS_NAME isn't there then it hasn't been defined. Maybe you have failed to define it somewhere else?

PHP NOTICE:Undefined offset 1

I am facing a problem that undefined offset :1. I can't understand that what type of error it is. Can anyone tell me that why such error occurs in php
<?php
$host="localhost";
$dbusername="root";
$dbpassword="";
$dbname="school";
$conn=mysql_connect($host,$dbusername,$dbpassword) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
if(isset($_POST['submit']))
{
$cls=$_POST['hhcls'];
{
{
{
$query=mysql_query("select * from stu_class where class='$cls'",$conn);
while($data=mysql_fetch_row($query))
{
$r1=$data[0];
$r=$_POST[$r1]; //THIS LNE ERROR
echo $r;
$query1="update stu_class set rollno=".$r." where ad_no=".$r;
$sql_query1=mysql_query($query1) or die(mysql_error());
if($sql_query1)
{
echo "<script type='text/javascript'>alert('Students Details Updated Successfully');</script>";
}
else
{
echo "<script type='text/javascript'>alert('Updation Failed');</script>";
}
}
}
}
}
}
?>
I am getting error while passing data to another query
Of course )
Look:
$query = mysql_query("select * from stu_class where class='$cls'", $conn);
// Now we got not query, but result of this query in $query
while ($data = mysql_fetch_row($query)) {
// Every iteration we will have in $data array (not associated)
// of fields (next row from database)
$r1 = $data[0];
// After this line we have value of first column of current line in $r1
// usually this is integer ID field and if first ID in database is 1,
// then $r1 = 1
$r = $_POST[$r1]; //THIS LNE ERROR
// here you trying to set $r = $_POST[1] because $r1 = 1
// but you have no any POST variable with key 1.
When you trying to get some array member that doesn't exist, you will get notice "Undefined offset %key%". In strict mode you will get exception.

Undefined property: stdClass

I'm getting the following error on these lines
Notice: Undefined property: stdClass::$id on line 36
Notice: Undefined property: stdClass::$id on line 40
Notice: Undefined property: stdClass::$screen_name on line 40
Line 36:
$vOAuth1 = mysql_query("SELECT * FROM `atwitter_oauth_users` WHERE `oauth_provider` = 'twitter' AND `oauth_uid` = '{$oUserInfo->id}'"); // searching for user in database
Line 40:
mysql_query("INSERT INTO `atwitter_oauth_users` (`oauth_provider`, `oauth_uid`, `username`, `oauth_token`, `oauth_secret`) VALUES ('twitter', {$oUserInfo->id}, '{$oUserInfo->screen_name}', '{$aAccessToken['oauth_token']}', '{$aAccessToken['oauth_token_secret']}')");
This is the whole code:
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
require_once('inc/header.php');
require_once('inc/twitteroauth.php');
global $sConsumerKey, $sConsumerSecret;
session_start();
if (! empty($_GET['oauth_verifier']) && ! empty($_SESSION['oauth_token']) && ! empty($_SESSION['oauth_token_secret'])) {
} else { // some params missed, back to login page
header('Location: http://www.domain.com/livetweeter/tw_login.php');
echo "parameters missed";
}
$oTwitterOauth = new TwitterOAuth($sConsumerKey, $sConsumerSecret, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$aAccessToken = $oTwitterOauth->getAccessToken($_GET['oauth_verifier']); // get access tokens
$_SESSION['access_token'] = $aAccessToken; // saving access token to sessions
$oUserInfo = $oTwitterOauth->get('account/verify_credentials'); // get account details
if(isset($oUserInfo->error)){
header('Location: http://www.domain.com/livetweeter/tw_login.php'); // in case of any errors - back to login page
echo "error";
} else {
global $sDbName, $sDbUserName, $sDbUserPass;
$vLink = mysql_connect($sDbHost, $sDbUserName, $sDbUserPass);
mysql_select_db($sDbName);
$vOAuth1 = mysql_query("SELECT * FROM `atwitter_oauth_users` WHERE `oauth_provider` = 'twitter' AND `oauth_uid` = '{$oUserInfo->id}'"); // searching for user in database
$aOauthUserInfo = mysql_fetch_array($vOAuth1);
if (empty($aOauthUserInfo)) { // if user info not present - add them into database
mysql_query("INSERT INTO `atwitter_oauth_users` (`oauth_provider`, `oauth_uid`, `username`, `oauth_token`, `oauth_secret`) VALUES ('twitter', {$oUserInfo->id}, '{$oUserInfo->screen_name}', '{$aAccessToken['oauth_token']}', '{$aAccessToken['oauth_token_secret']}')");
$vOAuth2 = mysql_query("SELECT * FROM `atwitter_oauth_users` WHERE `id` = '" . mysql_insert_id() . "'");
$aOauthUserInfo = mysql_fetch_array($vOAuth2);
} else {
mysql_query("UPDATE `atwitter_oauth_users` SET `oauth_token` = '{$aAccessToken['oauth_token']}', `oauth_secret` = '{$aAccessToken['oauth_token_secret']}' WHERE `oauth_provider` = 'twitter' AND `oauth_uid` = '{$oUserInfo->id}'"); // update tokens
}
$_SESSION['oauth_id'] = $aOauthUserInfo['id'];
$_SESSION['oauth_username'] = $aOauthUserInfo['username'];
$_SESSION['oauth_uid'] = $aOauthUserInfo['oauth_uid'];
$_SESSION['oauth_provider'] = $aOauthUserInfo['oauth_provider'];
$_SESSION['oauth_token'] = $aOauthUserInfo['oauth_token'];
$_SESSION['oauth_secret'] = $aOauthUserInfo['oauth_secret'];
mysql_close($vLink);
header('Location: http://www.domain.com/livetweeter/index.php');
echo "we've got an error";
}
if(!empty($_SESSION['oauth_username'])){
header('Location: http://www.domain.com/livetweeter/index.php'); // already logged, back to our main page
echo "this is an error";
}
?>
Note: I know I shouldn't be using mysql_query - I'll sort that once I have to script working.

Categories