tags:

views:

79

answers:

3

I don't know why but the code below is working when I have a different query:

$result = mysql_query("SELECT * FROM student WHERE IDNO='".$_GET['id']."'")
   ?>
<?php while ( $row = mysql_fetch_array($result) ) {

    ?>
     <?php list($year,$month,$day)=explode("-", $row['BIRTHDAY']); ?>
    <tr>
    <td width="30" height="35"><font size="2">Month:</td>
    <td width="30"><input name="mm" type="text" id="mm"  onkeypress="return handleEnter(this, event)" value="<?php echo $month;?>">

    <td width="30" height="35"><font size="2">Day:</td>
    <td width="30"><input name="dd" type="text" id="dd" maxlength="25"  onkeypress="return handleEnter(this, event)" value="<?php echo $day;?>">

    <td width="30" height="35"><font size="2">Year:</td>
    <td width="30"><input name="yyyy" type="text" id="yyyy" maxlength="25"  onkeypress="return handleEnter(this, event)" value="<?php echo $year;?>">

And it works when this is my query:

$idnum = mysql_real_escape_string($_POST['idnum']);

mysql_select_db("school", $con);
  $result = mysql_query("SELECT * FROM student WHERE IDNO='$idnum'");

Please help, why do I get the undefined offset error when I use this query:

$result = mysql_query("SELECT * FROM student WHERE IDNO='".$_GET['id']."'")

I assume that the query is the problem because its the only thing that's different between the two.

A: 

You are missing a semi-colon ; there:

$result = mysql_query("SELECT * FROM student WHERE IDNO='".$_GET['id']."'") ;?>

Also make sure that you are getting the id:

var_dump($_GET);

And it is named really id or something else.

You might go like:

if ($_GET['id'])
{
   // your further code.......
}

.

Update Based On Comment

Make sure that the date is coming up fine, try this:

print_r($row['BIRTHDAY']);

and see if everything is coming up or it is empty.

Sarfraz
yeah I notice it after posting but still no luck.
@user225269: see my updated answer please.
Sarfraz
the rest of the data that corresponds to $_GET['id'] is loading. Only the $year, $month, and $day isn't loading and gets the undefined offset. why is that
@user225269: make sure that date is coming up and not empty, try this inside the loop: `print_r($row['BIRTHDAY']);`. Chances are that some birthdates are coming empty and for that reason you are getting the notice error.
Sarfraz
A: 

Are you showing all errors?

Check that there is an index called 'id' within your $_GET array.

Extrakun
there's an index called 'id' because the rest of the data is loading. Year, section, lastname, and everything from the database that corresponds to the 'id'.
@user225629: That's not necessarily true... You should always var_dump your variable to make sure it's the value you're expecting, even if it is processing something. It may not be what you expected.
animuson
yeah, I tested it already. I even checked the mysql db manually if its showing the same as the one that is showed by php code
A: 

Is $_GET['id'] defined? In your first query which supposedly works, you're using $_POST['idnum'] which is a different request method and different key. Undefined offset is a non-fatal error/warning telling you that the key doesn't exist in the array. An easy way to fix this is to change the PHP error reporting, although in thise case you need to figure out which variable you actually need to use.

animuson