Jump to content

Archived

This topic is now archived and is closed to further replies.

selliott

[SOLVED] $id = $_GET['id'] - can't get it to work :(

Recommended Posts

I'm trying to adjust and use some code on a Windows server that I've used on a linux in the past, but I can't quite get this "id" issue resolved.  I keep getting this error:

 

Notice: Undefined index: id in E:\web\joshwiserac\htdocs\admin\photos\photos.php on line 9

 

 

Here's my code:

<?php 



//--------define connectivity information
$ConnString="DRIVER={SQL Server};SERVER=server_URL_here;DATABASE=database_name_here";
$DB_User="database_username_here";
$DB_Passwd="password_here";
$id = $_GET['id']; //--this is where my problem is
$table = "photos$id"; 
//-------Query database
$QueryString="SELECT * FROM $table";
//-------connect to database
$Connect = odbc_connect( $ConnString, $DB_User, $DB_Passwd );  
$Result = odbc_exec( $Connect, $QueryString ); 

//    MAKE THE XML DOC


$nl = "\r\n"; 

    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" . $nl; 
  echo "<master>" . $nl; 

while($r = odbc_fetch_array( $Result ) )
{
        
    echo '<node photo="' . $r['photo'] . '" description="' . $r['description'] . '">' . $nl; 
    echo '</node>' . $nl; 
}

echo "</master>" . $nl;

odbc_free_result( $Result );
odbc_close( $Connect );
?>

 

 

Share this post


Link to post
Share on other sites

It's not an error; it's a notice, i.e. a warning that your code is insufficient for the error_reporting setting you cose (or exists on your server).

 

Define $id before you assign a value to it and the notice will evaporate.

Share this post


Link to post
Share on other sites

I disagree. I believe it is referring to the $_GET['id'], rather than the $id variable. To do it correctly, do this:

<?php 



//--------define connectivity information
if (!isset($_GET['id']) die("ID not set...");
$ConnString="DRIVER={SQL Server};SERVER=server_URL_here;DATABASE=database_name_here";
$DB_User="database_username_here";
$DB_Passwd="password_here";
$id = $_GET['id']; //--this is where my problem is
$table = "photos$id"; 
//-------Query database
$QueryString="SELECT * FROM $table";
//-------connect to database
$Connect = odbc_connect( $ConnString, $DB_User, $DB_Passwd );  
$Result = odbc_exec( $Connect, $QueryString ); 

//    MAKE THE XML DOC


$nl = "\r\n"; 

    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" . $nl; 
  echo "<master>" . $nl; 

while($r = odbc_fetch_array( $Result ) )
{
        
    echo '<node photo="' . $r['photo'] . '" description="' . $r['description'] . '">' . $nl; 
    echo '</node>' . $nl; 
}

echo "</master>" . $nl;

odbc_free_result( $Result );
odbc_close( $Connect );
?>

 

or, to just mask the notice, do this:

 

<?php 



//--------define connectivity information
$ConnString="DRIVER={SQL Server};SERVER=server_URL_here;DATABASE=database_name_here";
$DB_User="database_username_here";
$DB_Passwd="password_here";
$id = @$_GET['id']; //--this is where my problem is
$table = "photos$id"; 
//-------Query database
$QueryString="SELECT * FROM $table";
//-------connect to database
$Connect = odbc_connect( $ConnString, $DB_User, $DB_Passwd );  
$Result = odbc_exec( $Connect, $QueryString ); 

//    MAKE THE XML DOC


$nl = "\r\n"; 

    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" . $nl; 
  echo "<master>" . $nl; 

while($r = odbc_fetch_array( $Result ) )
{
        
    echo '<node photo="' . $r['photo'] . '" description="' . $r['description'] . '">' . $nl; 
    echo '</node>' . $nl; 
}

echo "</master>" . $nl;

odbc_free_result( $Result );
odbc_close( $Connect );
?>

Share this post


Link to post
Share on other sites

Still isn't working :(  I'm not sure what I'm doing wrong.  If I just make $id = "1", it works...but $_GET['id'] isn't getting the "1" out of the id column of the db and applying it. 

 

When I just try adding:

if (!isset($_GET['id']) die("ID not set...");

I get an error on the line where this code is added, which is line 6...

Parse error: syntax error, unexpected T_EXIT in E:\web\joshwiserac\htdocs\admin\photos\photos.php on line 6

 

Just adding the @ before $_GET['id'];  also produces an SQL error:

Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver]

Invalid object name 'photos'., SQL state S0002 in SQLExecDirect in E:\web\joshwiserac\htdocs\admin\photos\photos.php on line 16


[color=red][b]Anyway, maybe I'm doing something completely wrong that is messing everything up, so here's the original code that works on a linux server with mysql.  I had to make some changes to try to get it to work properly on the windows server with a MSSQL 2005 db...but may have made some mistakes in converting it...[/b][/color]

[code=php:0]
<?php

//          GET MONTHS
$id = $_GET['id'];

//--------define connectivity information
$database = "db_name_here";
$table = "photos$id";
$user = "user_name_here";
$password = "password_here";
//-------connect to database
mysql_connect("localhost", $user, $password) or die("Could not connect to database");
mysql_select_db($database) or die("Could not select database");
//-------Query database
$query = "SELECT * FROM $table"; //ORDER BY date ASC";
$myQuery = mysql_query($query);
//-------manage data
while($row = mysql_fetch_array($myQuery)) {
$photos[] = $row['photo'];
$descriptions[] = $row['description'];
$thumbnails[] = $row['thumbnail'];
}

//------close connection
mysql_close();



//    MAKE THE XML DOC
header("Content-Type: application/xml; charset=ISO-8859-1");
echo '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n";
echo '<master>' . "\n";
for ($i=0; $i<count($photos); $i++) {

echo '<node photo="' . $photos[$i] . '" description="' .$descriptions[$i] . '" thumbnail="' .$thumbnails[$i] . '"/>' . "\n";

}
echo '</master>';
?>
[/code]

Share this post


Link to post
Share on other sites
Still isn't working Sad  I'm not sure what I'm doing wrong.  If I just make $id = "1", it works...but $_GET['id'] isn't getting the "1" out of the id column of the db and applying it.

 

$_GET gets information from the url, not the database.

Share this post


Link to post
Share on other sites

My bad, I missed a )...

 

Try:

if (!isset($_GET['id'])) die("ID not set...");

 

Also, where are you getting "$_GET"? A form I'm assuming? using the "get" method, not post?

Share this post


Link to post
Share on other sites

Ok, I didn't catch that ) either.

 

I think I found out what the whole GET['id'] code is for now.  While searching through the flash actionscript (gallery side) I found that the php file is called as photos.php?id="+loadID  So when I apply "?id=1" to the end of the URL, the XML file shows up for this one entry.

 

 

Did I convert the original code over properly, from the linux/mysql version, or were there mistakes in there...either in the top section or even the lower section that creates the XML?  I suspect I didn't convert the XML part correctly, because it's not working in my flash gallery...so something still seems to be wrong  ???

Share this post


Link to post
Share on other sites

Thanks for all the help...I think I finally have all the bugs worked out.  Turns out the issues weren't what I thought at first...but at least it all lead to a solution, since I probably wouldn't have noticed the ?id= in the actionscript and found out what the GET['id'] was even for.  Anyway, it's working now :)

 

And an FYI for anyone else that runs across this thread, this was the final code I used.

 

<?php 

//--------define connectivity information
$ConnString="DRIVER={SQL Server};SERVER=server_url_here;DATABASE=db_name_here";
$DB_User="db_username_here";
$DB_Passwd="db_password_here";
$id = $_GET['id'];
$table = "photos$id"; 
//-------Query database
$QueryString="SELECT * FROM $table";
//-------connect to database
$Connect = odbc_connect( $ConnString, $DB_User, $DB_Passwd );  
$Result = odbc_exec( $Connect, $QueryString ); 

  while($row = odbc_fetch_array( $Result ) )
  {
  	$photos[] = $row['photo'];
$descriptions[] = $row['description'];
  }


//    MAKE THE XML DOC


$nl = "\r\n"; 

    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" . $nl; 
echo '<master>' . "\n";
for ($i=0; $i<count($photos); $i++) {

echo '<node photo="' . $photos[$i] . '" description="' .$descriptions[$i] . '"/>' . "\n";

}
echo '</master>';

odbc_close( $Connect );
//odbc_free_result( $Result );
?>

 

 

Share this post


Link to post
Share on other sites

If it is solved, remember to click the topic solved button at the bottom of the page.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.