[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to resolve the attached EDIT UPLOAD using PHP?

Posted on 2012-09-10
6
Medium Priority
?
582 Views
Last Modified: 2012-09-10
Dear EE experts,

Please see the attached embed script for the 'editupload.php' that we have
<?php
//include("connect.php");
extract($_POST); 
		extract($_GET); 

//$objConnect = odbc_connect("********","","") or die("Database Connect Failed");
	$dbname="*******"; 
	//$dbhost="xxx.xx.xxx.xxx";
	$dbhost="xxx.xx.xxx.xxx";
	$dbuser="*******";
	$dbpass="**********";
	
/*	$dbname="*************"; 
	$dbhost="*************"; 
	$dbuser="*************";
	$dbpass="*************";
*/

@$Conn=mysql_connect("$dbhost","$dbuser","$dbpass") or die("Not Connect");
mysql_select_db("$dbname",$Conn) or die ('error');

//$objConnect=odbc_connect("*********","","") or die("Error Connect to Database");
//$objConnect=odbc_connect("*********","","") or die("Error Connect to Database");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta name="Author" content="Oliver Dan A. Arcillo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">

<meta name="GENERATOR" content="Mozilla/4.7 [en] (Win98; I) [Netscape]">

<title>..:: Stiebel Eltron's iPhoto Stock Gallery - Powered by STE IT Dept. ::..</title>


<style TYPE="text/css">
<!--
	a
 	{
  		color:#000080;
		font-family:verdana;
		text-decoration:none;
		font-size:12px
	}
	
	
	a:active
 	{
  		color:red;

	}

	a:hover
 	{
  		color:#FF0000;
		text-decoration:none;
		cursor:crosshair;
	}
		
	table
	{
		font-family:verdana;
	}
	
	td
	{
		font-family:verdana;
		font-size:10e;
	}

	.td	
	{
		font-family:verdana;
		font-size:10e;
	}
	
	.b
	{
		font-color:#0A0EB7;
	}		

-->
</STYLE>

<!--END DHTML-->

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array.

theImages[0] = '../IMG/xg-header-00.jpg'
theImages[1] = '../IMG/xg-header-01.jpg'
theImages[2] = '../IMG/xg-header-02.jpg'
theImages[3] = '../IMG/xg-header-03.jpg'
theImages[4] = '../IMG/IL-header.jpg'

// do not edit anything below this line

var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}

//  End -->
</script>


</head>

<body bgproperties="fixed" bgcolor="#000000" onLoad="javascript:startmenu()">

<table width="760" border="0" cellspacing="3" cellpadding="1">
  <tr>
    <td width="134"><img src="IMG/logo_res.jpg" alt="STIEBEL ELTRON" /></td>
    <td width="620" valign="top" bgcolor="#666666" align="center">
    	<SCRIPT LANGUAGE="JavaScript">
    	<!-- Begin
		showImage();
		//  End -->
		</script>
    </td>
    <td width="134"><img src="IMG/white_square.png" alt="STIEBEL ELTRON" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="right" bgcolor="#999999"><font face="Verdana, Geneva, sans-serif" color="#ffffff">
   
	</td>
    <td bgcolor="#666666" align="center">&nbsp;</td>
  </tr>
 
  <tr>
    <td>&nbsp;</td>
    <td  bordercolor="#999999" bgcolor="#FFFFFF" align="center">
    
  
<table width="540" border="0" cellpadding="2" cellspacing="2">
 <tr bgcolor="#999999"  style="font-size:14px">
   <td colspan="3" align="center"><strong>Update Title Name</strong></td>
 </tr>
 <form name="form3" action="editupload.php"> 
 <tr style="font-size:12px">
    <td width="101">Location :</td>
    <td width="251" align="left">
    <select style="font-size:12px;color:#006699;font-family:verdana;width:200px" name="menu" onchange="location=document.form3.menu.options[document.form3.menu.selectedIndex].value;">
       <option value=""><?php echo $_GET['typename'];?></option>
       <?php  $sql="SELECT * FROM  producttype";
$Query_sql=mysql_query($sql);
while ($rs=mysql_fetch_array( $Query_sql))
{
  
  $typeid=$rs["typeid"];
  $typename=$rs["typename"];
  $groupid=$rs["groupid"];
?>
       <option value="editupload.php?ty=<?php echo $typeid?>&typename=<?php echo $typename?>">
             <?php echo $typename?>                 </option>
                <?php echo $typename?>
        <?php } ?>
     </select>             </td>
    <td width="168">&nbsp;</td>
    </tr>
    </form>
  <form id="form1" name="form1" method="GET" action="editupload.php" enctype="multipart/form-data">  
   <tr  style="font-size:12px">
    <td>Series :</td>
    <td align="left">
   <select name="series" id="series" style="width:200px">  
   <?php  
$ty=trim($_GET['ty']);
if($ty!=""){	
$sql="SELECT * FROM  series where typeid=$ty ORDER BY  typeid,series_name ";
$Query_sql=mysql_query($sql);
while ($rs=mysql_fetch_array( $Query_sql))
{
  
  $seriesid=$rs["seriesid"];
  $seriesname=$rs["series_name"];
?>
<option value="<?php echo $seriesid?>"><?php echo $seriesname?></option>
<?php }?>
    <?php 
//odbc_close($objConnect);

}
?>    </select> 
       </td>
    <td><input type="submit" name="button" id="button" value="Search" /></td>
    </tr>

  <tr align="left">
    <td colspan="3" style="padding-bottom: 1px; BORDER-BOTTOM:#33CCFF 2px solid;" height="10">&nbsp;</td>
   
    </tr></form> 
  <form name="form2" method="post" action="delete.php">  
    <tr align="left" style="font-size:12px">
    <td valign="top" >Title Name  &gt;&gt;  </td>
    <td colspan="2"><table width="100%" height="22" border="0" cellpadding="0" cellspacing="1">
   <?php 
$seriesid=trim($_GET['series']);
if($seriesid!=""){
$sqlpd="SELECT * FROM  products  where seriesid=$seriesid  ORDER BY  product_name  ";
$pd=mysql_query($sqlpd);
// $now=odbc_fetch_row($pd);
$i=0;
while($rs=mysql_fetch_array($pd))
{ 
$i=$i+1;
$id=$rs["ID"];
$productname=$rs["product_name"];

  ?> 
      <tr style="font-size:12px">
        <td width="37" height="20" ><?php echo $i; ?>.</td>
        <td width="352"><a href="preview_upload.php?id=<?php echo $id;?>"><?php echo $productname;?></a></td>
        <td width="20">
          <input type="checkbox" name="chkMessageID[]" id="checkbox"  value="<?php echo $id;?>"/>         
          
           </td>
      </tr>
    <?php  }  } ?>  
    </table></td>
   
    </tr>
    
    <tr align="left">
    <td  colspan="3" align="right"><input name="hdnLine" type="hidden" value="<?php echo $i;?>" /><?php if($i>0){ echo "<input name=button type=submit   value=Del>";  } ?></td>
    
    </tr>
    </form>
    <tr align="left">
    <td></td>
    <td class="td">&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
</table>

    </td>
    <td bgcolor="#999999">&nbsp;</td>
  </tr>
    <tr>
    <td>&nbsp;</td>
    <td align="center" bgcolor="#999999">
    	 <a href="admin.php"><img src="IMG/back.png"  border="0"/><font size="0.5e"><br />
BACK TO ADMIN PAGE</font></a>
    </td>
    <td bgcolor="#666666">&nbsp;</td>
  </tr>
</table>
<?php 
//odbc_close($objConnect);
?>

</body>
</html>

Open in new window

We're encountering this problem:
PHP Notice:  Undefined index:  typename in D:\hosting\7509682\html\ste\photo\editupload.php on line 160
PHP Notice:  Undefined index:  ty in D:\hosting\7509682\html\ste\photo\editupload.php on line 184
PHP Notice:  Undefined index:  series in D:\hosting\7509682\html\ste\photo\editupload.php on line 214
PHP Notice:  Undefined variable: i in D:\hosting\7509682\html\ste\photo\editupload.php on line 241
PHP Notice:  Undefined variable: i in D:\hosting\7509682\html\ste\photo\editupload.php on line 241

Open in new window


Line 160: <option value=""><?php echo $_GET['typename'];?></option>
Line 184: $ty=trim($_GET['ty']);
Line 214: $seriesid=trim($_GET['series']);
Line 241: <td  colspan="3" align="right"><input name="hdnLine" type="hidden" value="<?php echo $i;?>" /><?php if($i>0){ echo "<input name=button type=submit   value=Del>";  } ?></td>

Kindly advise how to resolve this error...

Thank you in advance...
0
Comment
Question by:Stiebel Eltron
  • 2
  • 2
  • 2
6 Comments
 
LVL 45

Expert Comment

by:Chris Stanyon
ID: 38382415
The undefined index error means that your GET array doesn't have the relevant key. In order to read the GET keys they must be present in the querystring, so for example you must load your page with a querystring, like so:

editupload.php?typename=something&ty=something&series=something.

The undefined variable error is because you define the $i variable inside an if statement (line 215), and then access it outside of the if statement (line 241). If the 'if' statement is not run, then the variable is never defined.
0
 
LVL 60

Expert Comment

by:Julian Hansen
ID: 38382418
You are trying to get a value out of the $_GET array that does not exist. This array will only be populated once you submit your form.

You should do something like this
<option value=""><?php echo isset($_GET['typename'])?$_GET['typename']:'';?></option>

Open in new window

For each of your $_GET's
0
 

Author Comment

by:Stiebel Eltron
ID: 38382474
@ChrisStanyon: we tried this, patterned from our other PHP page
editupload.php?ty=&typename=&series=

but still have remaining line that needs to be resolve, Line 241, 'Undefined variable: i'

@julianH: tried what you advised, but got lost from the other lines...
Line 160 has been resolved (as per your advise)...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 60

Accepted Solution

by:
Julian Hansen earned 2000 total points
ID: 38382506
$ty=trim($_GET['ty']);
$ty=trim(isset($_GET['ty'])?$_GET['ty']:'');

$seriesid=trim($_GET['series']);
$seriesid=trim(isset($_GET['series'])?$_GET['series']:'');

But I would recommend not doing it like this.

On entry to your script I would collect all the submitted values at the start of the script and set defaults if they don't exist and then use these values in the code so something like this

$values = isset($_GET['data'])?$_GET['data']:array();
if (empty($values)) {
$values['ty'] = '';
$values['series'] ='';
// Repeat for other submitted variables here
}

In your code replace $_GET['ty'] with $values['ty'];

Change the name of your inputs from

<select style="font-size:12px;color:#006699;font-family:verdana;width:200px" name="menu"  ... >

to

<select style="font-size:12px;color:#006699;font-family:verdana;width:200px" name="data[menu]"  ... >

In other words specify your form variables as arrays - it makes it a lot easier.
0
 
LVL 45

Expert Comment

by:Chris Stanyon
ID: 38382513
Re-read my previous comment. It tells you why you have the undefined variable. If you call your page like this:

editupload.php?ty=&typename=&series=

Then $_GET['series'] = "".

Your IF statement will never get executed, so the $i variable is never defined.

$seriesid=trim($_GET['series']);
if($seriesid!=""){
    $i=0; //this will never get executed if 'series' = ""
    while($rs=mysql_fetch_array($pd))
    {
    ...
    }
}

echo $i; //undefined variable if series=""

Open in new window

0
 

Author Closing Comment

by:Stiebel Eltron
ID: 38385305
Excellent!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month19 days, 15 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question