0

I have 2 variables to send records.php, '$id' and '$row[0]". After it, I want to use them in newrecords.php with $_Get method.

Here 's index.php

 echo '<td align="center">'.$row[0].'-)&nbsp;<a href="newrecords.php?mid=&id=' . $id . $row[0] . '"$ >'.  $row[3] . "&nbsp;" . $row[4] .'</a></td>';

There's something going wrong.I see this url "newrecords.php?mid=&id=44" i want to see like this "mid=4&id=4" and after this

newrecords.php

if (isset($_GET['mid']))
    {
        $id = $_GET['mid'];
}

if (isset($_GET['id']))
        {
            $nid = $_GET['id'];
    }

Is it right way to get them?

1
  • That is the right way to get them. Commented Aug 7, 2014 at 8:31

3 Answers 3

5

your url is not correct try this

echo '<td align="center">'.$row[0].'-)&nbsp;<a href="newrecords.php?mid='.$id.'&id='.$row[0].'" >'.  $row[3] . '&nbsp;' . $row[4] .'</a></td>';
Sign up to request clarification or add additional context in comments.

Comments

1

You URL is malformed. You have to separate each key/value with a &. And better use &amp; if it's in HTML.

echo('<td align="center">'.$row[0].'-)&nbsp;<a href="newrecords.php?id='.
      $id.'&amp;mid='.$row[0].'"$ >'.$row[3]."&nbsp;".$row[4].'</a></td>');

So the structure is ?key1=value1&key2=value2&key3=value3

That way you can get them with $_GET['key1'] and $_GET['key2'] and $_GET['key3'].

The way you get them, you are using isset, that's tricky because they might be set but have no value. You can also use empty() for that. It actually checks whether a value is not 0 or empty. So if you don't use 0 as a record id you can better use that. And I also if they are id's I would cast them (making sure they are integers)

$id = (int)$_GET['id'];
if (!empty($id)){ ... }

2 Comments

Do not need to isset them?
Well, that depends, of course is more neat to do that. I would rather advice you to use if (!empty($_GET['key1'])){..}. That way if a value is empty, it gets false. isset also returns true with empty values. If your values are always numbers, you can secure the thing a bit to force casting them to integers. By using $key1 = (int)$_GET['key1']; if (!empty($key1)){..}
1

What you are doing? i think it is wrong. It will show url like "newrecords.php?mid=&id=44" this instead of your code you should try like this.

echo '<td align="center">'.$row[0].'-)&nbsp;<a href="newrecords.php?mid='.$id.'&id='.$row[0].'" >'.  $row[3] . '&nbsp;' . $row[4] .'</a></td>';

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.