Page 1 of 1

get and undefined index

Posted: Thu Sep 27, 2007 8:05 am
by kalfsnor
I am trying (absolute newbie) to write code to use inside a CMS (Modx)
I have a huge music publishers address list and do not want to create (and re-type) a page per publisher.
Instead I imported the whole list into a database (pianoquartet) in one table (publisher).

I managed to display a list of those publishers showing only the name field.
Now I want the namefield tolink to the rest of the details of that publisher.

When viewing the code through PHP editor i getfolloing errors:
<br />
<b>Notice</b>: Undefined index: idpd in <b>C:\Documents and Settings\Frank\My Documents\My Sites\php\franklos\listpub_Temp.php</b> on line <b>3</b><br />
<br />
<b>Notice</b>: Undefined index: idpmod in <b>C:\Documents and Settings\Frank\My Documents\My Sites\php\franklos\listpub_Temp.php</b> on line <b>4</b><br />
So "undefined index", which should come from this statement:

Code: Select all

$idpubdetails = $_GET['table'];
$idpubmod     = $_GET['field'];
Now the issue is that I dont see how to fill this "table" or "field" field. Can I write a table or fieldname here?
Whats the format, rather syntax. I ve been googling 4 hours no result.

Hope it is a simplething and someone can tell me what the problem is,

Frank.

Whole code:

Code: Select all

<?php

$idpubdetails = $_GET['table'];
$idpubmod     = $_GET['field'];


$sqlConn = mysql_connect('localhost','typo3','');
if (!$sqlConn)
{
  die ('unable to connect' . mysql_error());
}

$db = mysql_select_db('typo3', $sqlConn);




// 001: Database query

$query = "select * from publishers order by name ASC";


// 002: Execute query

$res = mysql_query($query, $sqlConn);


if (!$res)
{
   die ('Could not run query: ' . mysql_error());
}



// everything went ok, so we can display the data


echo "<h4>List of Publishers</h4>";


echo "   <table border=\"0\" cols=\"2\" cellpadding=\"0\" cellspacing=\"0\" width=\"400\">";


while ($row = mysql_fetch_array($res, MYSQL_BOTH)) 
{
  $reccnt++;

  $idpub      = $row[0];
  $publisher  = $row[3];

  $pubmodlink = "<a href=\"/typo3/index.php?id=".$idpubmod."&idpub=".$idpub."\">";
  $pubmodlink = $pubmodlink . $idpub . "</a>";

  $publink = "<a href=\"/typo3/index.php?id=".$idpubdetails."&idpub=".$idpub."\">";
  $publink = $publink . $publisher . "</a>";

  echo "          <tr>";
  echo "             <td valign=\"top\">" . $pubmodlink . "</td>";
  echo "             <td valign=\"top\">" . $publink . "</td>";
  echo "          </tr>";

}

echo "        </table>";


mysql_free_result($res);



mysql_close($sql_Conn);


?>

Posted: Thu Sep 27, 2007 9:09 am
by Zoxive
Well, from the error code you are getting, you aren't showing us all the code.

The Errors are saying that `idpd`, `idpmod` where not set in an array.

But the code you are showing doesn't have Either `idpd` or `idpmod`.

And if you are trying to get them from $_GET, use something like..

Code: Select all

$idpd = !empty($_GET['idpd'])? $_GET['idpd'] : '';
// IF $_GET['idpd'] is not empty, set it as that, other wise set it as blank

if(!empty($_GET['idpd'])){
  $idpd = $_GET['idpd'];
}else{
  $idpd = '';
}
// Same Thing, just different syntax.

Posted: Thu Sep 27, 2007 10:49 am
by kalfsnor
Correction,

my problem is actually that I would like to get a field ID from the "publisher table" in that script.
And no matter what I try and what I Google for, I keep getting the "undefined id" as result.
How to use the $_get argument?

Frank.

Posted: Fri Sep 28, 2007 1:09 pm
by Begby
If you have a page called 'mypage.php' and access it like this

http://mysite.com/mypage.php?somevar=10

Then in your source code on 'mypage.php' you can do this

Code: Select all

echo $_GET['somevar'] ; // Echoes 10, $_GET retrieves the value from the URL

echo $_GET['burrito'] ; // This will generate a notice because burrito is not in the url parameter list

What you need to do is modify your code so that you pass the variables you want as part of the URL.