Issue with index - unidentified index [duplicate]












-2















This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers



  • PHP ereg_replace deprecated

    2 answers



  • Warning: mysqli_error() expects exactly 1 parameter, 0 given error [closed]

    3 answers




The issue appears to be with an "unidentified index - pid". What I am trying to do is to show the body text of a linked page but get the error mentioned. I have followed a working example online and the code seems the same.



This is the php:



//Determine which page to use
if (!$_GET['pid']) {
$pageid = '1';
} else {
$pageid = ereg_replace("[^0-9]", "", $_GET['pid']); // filter everything but numbers for security
}
// Query the body section for the proper page
$sqlCommand = "SELECT pagebody FROM pages WHERE id='$pageid' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$body = $row["pagebody"];
}
mysqli_free_result($query);
// end body query


I had noticed that in the example, the working code was placed on an online server, whereas I am using XAMPP. Could this be the issue? Will the code only work online?










share|improve this question















marked as duplicate by aynber, Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 19:06


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • It's better to use !isset or empty instead of just !
    – aynber
    Nov 20 at 18:56












  • You can better check !$_GET['pid'] with !isset($_GET['pid']). On which line do you get this error and what is that line?
    – vivek_23
    Nov 20 at 18:58












  • You might also like to check the 2nd duplicate, just in case. That ereg_replace() is deprecated and is most likely contributing to the error. Enable error reporting php.net/manual/en/function.error-reporting.php
    – Funk Forty Niner
    Nov 20 at 19:07












  • You are leaving yourself open to an sql injection; use a prepared statement.
    – Funk Forty Niner
    Nov 20 at 19:10
















-2















This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers



  • PHP ereg_replace deprecated

    2 answers



  • Warning: mysqli_error() expects exactly 1 parameter, 0 given error [closed]

    3 answers




The issue appears to be with an "unidentified index - pid". What I am trying to do is to show the body text of a linked page but get the error mentioned. I have followed a working example online and the code seems the same.



This is the php:



//Determine which page to use
if (!$_GET['pid']) {
$pageid = '1';
} else {
$pageid = ereg_replace("[^0-9]", "", $_GET['pid']); // filter everything but numbers for security
}
// Query the body section for the proper page
$sqlCommand = "SELECT pagebody FROM pages WHERE id='$pageid' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$body = $row["pagebody"];
}
mysqli_free_result($query);
// end body query


I had noticed that in the example, the working code was placed on an online server, whereas I am using XAMPP. Could this be the issue? Will the code only work online?










share|improve this question















marked as duplicate by aynber, Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 19:06


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • It's better to use !isset or empty instead of just !
    – aynber
    Nov 20 at 18:56












  • You can better check !$_GET['pid'] with !isset($_GET['pid']). On which line do you get this error and what is that line?
    – vivek_23
    Nov 20 at 18:58












  • You might also like to check the 2nd duplicate, just in case. That ereg_replace() is deprecated and is most likely contributing to the error. Enable error reporting php.net/manual/en/function.error-reporting.php
    – Funk Forty Niner
    Nov 20 at 19:07












  • You are leaving yourself open to an sql injection; use a prepared statement.
    – Funk Forty Niner
    Nov 20 at 19:10














-2












-2








-2








This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers



  • PHP ereg_replace deprecated

    2 answers



  • Warning: mysqli_error() expects exactly 1 parameter, 0 given error [closed]

    3 answers




The issue appears to be with an "unidentified index - pid". What I am trying to do is to show the body text of a linked page but get the error mentioned. I have followed a working example online and the code seems the same.



This is the php:



//Determine which page to use
if (!$_GET['pid']) {
$pageid = '1';
} else {
$pageid = ereg_replace("[^0-9]", "", $_GET['pid']); // filter everything but numbers for security
}
// Query the body section for the proper page
$sqlCommand = "SELECT pagebody FROM pages WHERE id='$pageid' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$body = $row["pagebody"];
}
mysqli_free_result($query);
// end body query


I had noticed that in the example, the working code was placed on an online server, whereas I am using XAMPP. Could this be the issue? Will the code only work online?










share|improve this question
















This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers



  • PHP ereg_replace deprecated

    2 answers



  • Warning: mysqli_error() expects exactly 1 parameter, 0 given error [closed]

    3 answers




The issue appears to be with an "unidentified index - pid". What I am trying to do is to show the body text of a linked page but get the error mentioned. I have followed a working example online and the code seems the same.



This is the php:



//Determine which page to use
if (!$_GET['pid']) {
$pageid = '1';
} else {
$pageid = ereg_replace("[^0-9]", "", $_GET['pid']); // filter everything but numbers for security
}
// Query the body section for the proper page
$sqlCommand = "SELECT pagebody FROM pages WHERE id='$pageid' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$body = $row["pagebody"];
}
mysqli_free_result($query);
// end body query


I had noticed that in the example, the working code was placed on an online server, whereas I am using XAMPP. Could this be the issue? Will the code only work online?





This question already has an answer here:




  • “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

    28 answers



  • PHP ereg_replace deprecated

    2 answers



  • Warning: mysqli_error() expects exactly 1 parameter, 0 given error [closed]

    3 answers








php mysql indexing get






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 19:10









Funk Forty Niner

80.5k1247100




80.5k1247100










asked Nov 20 at 18:53









user3511057

388




388




marked as duplicate by aynber, Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 19:06


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by aynber, Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 19:06


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • It's better to use !isset or empty instead of just !
    – aynber
    Nov 20 at 18:56












  • You can better check !$_GET['pid'] with !isset($_GET['pid']). On which line do you get this error and what is that line?
    – vivek_23
    Nov 20 at 18:58












  • You might also like to check the 2nd duplicate, just in case. That ereg_replace() is deprecated and is most likely contributing to the error. Enable error reporting php.net/manual/en/function.error-reporting.php
    – Funk Forty Niner
    Nov 20 at 19:07












  • You are leaving yourself open to an sql injection; use a prepared statement.
    – Funk Forty Niner
    Nov 20 at 19:10


















  • It's better to use !isset or empty instead of just !
    – aynber
    Nov 20 at 18:56












  • You can better check !$_GET['pid'] with !isset($_GET['pid']). On which line do you get this error and what is that line?
    – vivek_23
    Nov 20 at 18:58












  • You might also like to check the 2nd duplicate, just in case. That ereg_replace() is deprecated and is most likely contributing to the error. Enable error reporting php.net/manual/en/function.error-reporting.php
    – Funk Forty Niner
    Nov 20 at 19:07












  • You are leaving yourself open to an sql injection; use a prepared statement.
    – Funk Forty Niner
    Nov 20 at 19:10
















It's better to use !isset or empty instead of just !
– aynber
Nov 20 at 18:56






It's better to use !isset or empty instead of just !
– aynber
Nov 20 at 18:56














You can better check !$_GET['pid'] with !isset($_GET['pid']). On which line do you get this error and what is that line?
– vivek_23
Nov 20 at 18:58






You can better check !$_GET['pid'] with !isset($_GET['pid']). On which line do you get this error and what is that line?
– vivek_23
Nov 20 at 18:58














You might also like to check the 2nd duplicate, just in case. That ereg_replace() is deprecated and is most likely contributing to the error. Enable error reporting php.net/manual/en/function.error-reporting.php
– Funk Forty Niner
Nov 20 at 19:07






You might also like to check the 2nd duplicate, just in case. That ereg_replace() is deprecated and is most likely contributing to the error. Enable error reporting php.net/manual/en/function.error-reporting.php
– Funk Forty Niner
Nov 20 at 19:07














You are leaving yourself open to an sql injection; use a prepared statement.
– Funk Forty Niner
Nov 20 at 19:10




You are leaving yourself open to an sql injection; use a prepared statement.
– Funk Forty Niner
Nov 20 at 19:10












1 Answer
1






active

oldest

votes


















0














before accessing $_GET['pid'] check if pid set or not



if (empty($_GET['pid'])) {
$pageid = '1';
} else {
.....
}





share|improve this answer



















  • 1




    Thats a redundant check. Only The isset check is needed.
    – Ray
    Nov 20 at 19:00






  • 1




    i thought !$_GET['pid'] is for 0
    – suresh bambhaniya
    Nov 20 at 19:02






  • 1




    Would then be quicker to write if(empty($_GET['pid']), that's isset() and ! in one go.
    – minitauros
    Nov 20 at 19:05










  • This is a 50% fix.
    – Funk Forty Niner
    Nov 20 at 19:08


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














before accessing $_GET['pid'] check if pid set or not



if (empty($_GET['pid'])) {
$pageid = '1';
} else {
.....
}





share|improve this answer



















  • 1




    Thats a redundant check. Only The isset check is needed.
    – Ray
    Nov 20 at 19:00






  • 1




    i thought !$_GET['pid'] is for 0
    – suresh bambhaniya
    Nov 20 at 19:02






  • 1




    Would then be quicker to write if(empty($_GET['pid']), that's isset() and ! in one go.
    – minitauros
    Nov 20 at 19:05










  • This is a 50% fix.
    – Funk Forty Niner
    Nov 20 at 19:08
















0














before accessing $_GET['pid'] check if pid set or not



if (empty($_GET['pid'])) {
$pageid = '1';
} else {
.....
}





share|improve this answer



















  • 1




    Thats a redundant check. Only The isset check is needed.
    – Ray
    Nov 20 at 19:00






  • 1




    i thought !$_GET['pid'] is for 0
    – suresh bambhaniya
    Nov 20 at 19:02






  • 1




    Would then be quicker to write if(empty($_GET['pid']), that's isset() and ! in one go.
    – minitauros
    Nov 20 at 19:05










  • This is a 50% fix.
    – Funk Forty Niner
    Nov 20 at 19:08














0












0








0






before accessing $_GET['pid'] check if pid set or not



if (empty($_GET['pid'])) {
$pageid = '1';
} else {
.....
}





share|improve this answer














before accessing $_GET['pid'] check if pid set or not



if (empty($_GET['pid'])) {
$pageid = '1';
} else {
.....
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 at 19:10

























answered Nov 20 at 18:57









suresh bambhaniya

861113




861113








  • 1




    Thats a redundant check. Only The isset check is needed.
    – Ray
    Nov 20 at 19:00






  • 1




    i thought !$_GET['pid'] is for 0
    – suresh bambhaniya
    Nov 20 at 19:02






  • 1




    Would then be quicker to write if(empty($_GET['pid']), that's isset() and ! in one go.
    – minitauros
    Nov 20 at 19:05










  • This is a 50% fix.
    – Funk Forty Niner
    Nov 20 at 19:08














  • 1




    Thats a redundant check. Only The isset check is needed.
    – Ray
    Nov 20 at 19:00






  • 1




    i thought !$_GET['pid'] is for 0
    – suresh bambhaniya
    Nov 20 at 19:02






  • 1




    Would then be quicker to write if(empty($_GET['pid']), that's isset() and ! in one go.
    – minitauros
    Nov 20 at 19:05










  • This is a 50% fix.
    – Funk Forty Niner
    Nov 20 at 19:08








1




1




Thats a redundant check. Only The isset check is needed.
– Ray
Nov 20 at 19:00




Thats a redundant check. Only The isset check is needed.
– Ray
Nov 20 at 19:00




1




1




i thought !$_GET['pid'] is for 0
– suresh bambhaniya
Nov 20 at 19:02




i thought !$_GET['pid'] is for 0
– suresh bambhaniya
Nov 20 at 19:02




1




1




Would then be quicker to write if(empty($_GET['pid']), that's isset() and ! in one go.
– minitauros
Nov 20 at 19:05




Would then be quicker to write if(empty($_GET['pid']), that's isset() and ! in one go.
– minitauros
Nov 20 at 19:05












This is a 50% fix.
– Funk Forty Niner
Nov 20 at 19:08




This is a 50% fix.
– Funk Forty Niner
Nov 20 at 19:08



Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen