Undefined property: stdClass - php

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.

Related

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?

Unable to get session variable to save into my database

Can anyone help me in getting the group_id from a session and save into the database, it seems not to working, been working on it for a while now. The error i am getting is Notice: Undefined index: group_name
This is my script
include('db.php')
//Get User Info
if(isset($_SESSION['username'])){
$LoggedUser = $_SESSION['username'];
if($GetUser = $mysqli->query("SELECT * FROM users WHERE username='$LoggedUser'")){
$UserInfo = mysqli_fetch_array($GetUser);
$LoggedUsername = strtolower($UserInfo['username']);
$LoggedUserLink = preg_replace("![^a-z0-9]+!i", "-", $LoggedUsername);
$LoggedUserLink = strtolower($LoggedUserLink);
$UserId = $UserInfo['user_id'];
$GetUser->close();
}else{
printf("Error: %s\n", $mysqli->error);
}
}
//Get Group info
if(isset($_SESSION['group_name'])){
$LoggedGroup = $_SESSION['group_name'];
if($GetGroup = $mysqli->query("SELECT * FROM groups WHERE group_name='$LoggedGroup'")){
$GroupInfo = mysqli_fetch_array($GetGroup);
$LoggedGroupname = strtolower($GroupInfo['group_name']);
$LoggedGroupLink = preg_replace("![^a-z0-9]+!i", "-", $LoggedGroupname);
$LoggedGroupLink = strtolower($LoggedGroupLink);
$GroupId = $GroupInfo['group_id'];
$GetGroup->close();
}else{
printf("Error: %s\n", $mysqli->error);
}
}
//getting variables and inserting into a database
if($_POST)
{
$User = $UserId;
$Group = $GroupId;
$mysqli->query("INSERT INTO tb_name(group_id_fk, user_id_fk) VALUES ('$Group', '$User')");
die('<div class="alert alert-success" role="alert">You have been added successfully to the group.</div>');
}else{
die (mysqli_error());
}
?>
Thanks
A session is started with the session_start() function.
Session variables are set with the PHP global variable: $_SESSION.
<?php
// Start the session
session_start();
// Set session variables
if(isset($_SESSION['username'])) {
---- Your Statements -----
}
?>
you need to start a session first by session_start(); before using $_SESSION global

Undefine index: session error

Whenever someone login $_SESSION['semail']; and $_SESSION['username2'] are set. Whenever I go to profile page then I set session into a variable like $email = $_SESSION['semail'];
Then in error log an error is recorded as:
Undefined index: semail in /home/twekr/public_html/profile.php on line 11
My session start like this at top of page:
session_name('twekr');
session_start();
ob_start();
Here is the small part of script which is creating error:
<?php
session_name('twekr');
session_start();
ob_start();
if(!isset($_SESSION['semail']))
{
header("Location:https://www.twekr.com/");
}
if(isset($_GET['user']))
{
$id = $_GET['user'];
$user = $_SESSION['semail'];
$userid1 = $_SESSION['username2'];
include_once('config/db.php');
include_once('frnds/functions.php');
require('config/dbsettings.php');
$userquery= "SELECT * FROM users WHERE email='$user'";
$userquery=$sp->query($userquery) or die($sp->error);
$info=$userquery->fetch_object();
$userr = $info->username;
This is the small part of login script where I set session:
$_SESSION['username2'] = $get['username'];
$_SESSION['semail'] = $uemail;
$get is performed here below:
$check_login = mysqli_query($con, "SELECT username FROM users WHERE
email ='$uemail' AND password ='$upass'");
if(mysqli_num_rows($check_login) ==1) {
$get = mysqli_fetch_array($check_login);
$_SESSION['username2'] = $get['username'];

Variables undefined error in latest version of localhost (vertrigo_230)

Below mentioned PHP code was perfect on vertrigo_222 (and also on livehost).
Now I am trying to upgrade my localhost to vertrigo_230.
I am facing following undefined variable error or warning:
Here is code (line # 30 is mentioned):
<?php
ob_start();
session_start();
include_once("PHP_Code/db_connection.php");
if(isset($_REQUEST['data']))
$data = $_REQUEST['data'];
//Fetch All Important Information from Database in Variables
if($_SESSION['id'] && $_SESSION['pw']) //Login Must for This Informatiion
{
if(isset($_REQUEST['city_id']))
{
if($_REQUEST['city_id'])
{
$city_id = $_REQUEST['city_id'];
}
else
{
$query = "SELECT * FROM cities WHERE user_id = '$_SESSION[id]'";
$c = mysql_query($query) or die(mysql_error()." in query $query");
$city = mysql_fetch_array($c);
$city_id = $city['city_id'];
}
//Setting Current/Opened City in Session
$_SESSION['city_id'] = $city_id;
}
}
//Secure Page
if($data == "") //Line # 30
$data = "loginPage";
Please give me some solution.
define the $data as global variable and you have to use mysqli insted because mysql Officially deprecated
ob_start();
session_start();
include_once("PHP_Code/db_connection.php");
$data = '';
//your code

Resource id #6 error, Not sure how to fix it

I keep getting a 'Resource id # 6' failure when submitting a script on my website. The code I'm using is the same type of code I use for registering for the website and that works but this script doesn't work at all. What my code does is send a booking request with the fields as shown to the database. I keep getting a Resource id#6 error , and I've googled what that is but I can't seem to figure out whats wrong. I am a beginner at php , so any tips on whats to look for to avoid a resource id # 6 error would be a lot of help
<?php
//$pattern="/^.+#.+/.com/";
//error_reporting(0);
if(isset($_POST["submit"])){
$Name_of_Person = $_POST['Name_of_Person'];
$Name_of_Group = $_POST['Name_of_Group'];
$room = $_POST['room'];
$How_Many_People = $_POST['How_Many_People'];
$Date_of_Booking = $_POST['Date_of_Booking'];
$End_time = $_POST['End_time'];
$Purpose = $_POST['Purpose'];
$Contact_Number = $_POST['Contact_Number'];
$Contact_Email = $_POST['Contact_Email'];
$Alcohol = $_POST['Alcohol'];
$Security = $_POST['Security'];
$Projector = $_POST['Projector'];
$Extra_Chairs = $_POST['Extra_Chairs'];
$Extra_Info = $_POST['Extra_Info'];
$Activated = '0';
$con = mysql_connect('localhost','root','test123') or die("couldn't connect");
mysql_select_db('bookerdb') or die("couldn't connect to DB");
//if(filter_var($email, FILTER_VALIDATE_EMAIL)){//(preg_match($pattern, $_POST['Contact_Email'])){
$query = mysql_query("SELECT * FROM `booking_table` WHERE Date_of_Booking='".$Date_of_Booking."' AND room='".$room."'");
$numrows = mysql_num_rows($query);
echo $query;
if($numrows==0){
$sql="INSERT INTO `booking_table` (Name_of_Person,Name_of_Group,room,How_Many_People,Date_of_Booking,End_time,Purpose,Contact_Number,Contact_Email,Alcohol,Security,Projector,Extra_Chairs,Extra_Info, Activated) VALUES ('$Name_of_Person','$Name_of_Group','$room','$How_Many_People','$Date_of_Booking','$End_time','$Purpose','$Contact_Number','$Alcohol','$Security','$Projector','$Extra_Chairs','$Extra_Info',$Activated)";
$result = mysql_query($sql);
if($result){
echo "Sent to be approved";
$redirect_page = '../ASC.php';
$redirect = true;
if($redirect==true){
header('Location: ' .$redirect_page);
}
}else{
echo "Failed";
}
}else{
echo"There is already a requested booking on that date & time";
$redirect_page = '../EAR.php';
$redirect = true;
if($redirect==true){
header('Location: ' .$redirect_page);
}
}
/*}else{
echo "error";
$redirect_page = '../EWF.php';
$redirect = true;
if($redirect==true){
header('Location: ' .$redirect_page);
}
}*/
}
?>
You have error in your second SQL query. You try to insert 14 values into 15 columns (in values you forgot $Contact_Email).
$sql="INSERT INTO `booking_table` (Name_of_Person,Name_of_Group,room,How_Many_People,Date_of_Booking,End_time,Purpose,Contact_Number,Contact_Email,Alcohol,Security,Projector,Extra_Chairs,Extra_Info, Activated) VALUES ('$Name_of_Person','$Name_of_Group','$room','$How_Many_People','$Date_of_Booking','$End_time','$Purpose','$Contact_Number','$Contact_Email','$Alcohol','$Security','$Projector','$Extra_Chairs','$Extra_Info',$Activated)";
Than remove echo $query from your code, line 30.
In $query isn't query, but mysql result object. You can't work with that by this way, you can't echo it.

Categories