Jump to content

Recommended Posts

im having problems with the initial loading of a page "Undefined index". i no the problem is due to 2 $vars having no value but i dont no how to get around the problem.

 

its a form that posts to itself then pulls from the database.

once you hit submit the problem goes away. i just need to sort the 1st page load out

 

thanks

 

the problem is the 1st 2 lines of the snippet.

snippet

$ser_type=$_POST['list'];
$search = $_POST['search'];
if ($search == '' || $search == ' '){

echo "Search Field is Empty - Please Input a Search Query!";
die;
}
else{
if ($ser_type=="sku"){
$sql = "SELECT * from $tbl_name WHERE sku like '%$search%' or rsku like '%$search%'";
$result = mysql_query($sql);

 

full code

 

<?php
include("http://localhost/dsgi/includes/header.html");
?>
<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Modify DataBase</title>
</head>

<body>
<form method="post" action="main.php"> 
<table class="tablesrch" width=583 height="101" border="0" align=center> 
<tr>
  <td height="32" colspan="2"> <div align="center">Enter Search:
  <input type=text name='search' size=20 maxlength=255>
  </div></td>
  </tr>
<tr>
  <td width="193" align="right">Search By:</td>
  <td width="380"><label>
    <input name="list" type="radio" id="SKU" value="sku" checked>
    SKU
         
           
           
           
          <input name="list" type="radio" id="make" value="make">
    Make
     
     
     
    <input type="radio" name="list" id="model" value="model">
    Model</label></td>
</tr>
   
<td height="28" colspan="2"><div align="center"><input type=submit></div></td></tr> 
</table>
</form>
<p align="center"> </p>
<table class="table2"  align="center">
  <tr>
    <td align="center">
<?php

//include("http://localhost/dsgi/includes/config.php"); 

$INC_DIR = $_SERVER["DOCUMENT_ROOT"]. "/dsgi/includes/"; 
include($INC_DIR. "config.php"); 


// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
$tbl_name="dsgi_serval"; 


// Retrieve data from database 
$ser_type=$_POST['list'];
$search = $_POST['search'];
if ($search == '' || $search == ' '){

echo "Search Field is Empty - Please Input a Search Query!";
die;
}
else{
if ($ser_type=="sku"){
$sql = "SELECT * from $tbl_name WHERE sku like '%$search%' or rsku like '%$search%'";
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0) {

echo "Image is on the server. If not green please inform imaging team";

?>
</td>
  </tr>
</table>
<table class="table1" width="800" height="72"  align="center">
  

<tr class="tablehead">
<th width="113" align="center">Recon SKU</th>
<th width="66" align="center">Orig SKU</th>
<th width="90" align="center">Make</th>
<th width="169" align="center">Model</th>
<th width="58" align="center">Recovery</th>
</span></span></tr>
<?php

while ($rows=mysql_fetch_array($result)){

// table bg colour
$choice = strtoupper($rows['comments']);

$findme    = 'FAIL';
$findme1    = 'PASS';
$mystring2 = trim($rows['comments']);
$pos2 = stripos($mystring2, $findme);
$pos1 = stripos($mystring2, $findme1);

if ($pos1 !== false){ 
$bgc = "pass" ; }    
elseif ($pos2 !== false){
$bgc = "fail" ;   
}else{
$bgc = "wait" ; }
?>

<tr id="tabledata" class="<?php echo "$bgc"; ?>">
<td> <?php echo $rows['sku'] ; ?></td>
<td> <?php echo $rows['rsku']; ?></td>
<td> <?php echo $rows['make']; ?></td>
<td> <?php echo $rows['model']; ?></td>
<td> <?php echo $rows['recovery']; ?></td>

</tr>



<?php



}
}
else {
$sql = "SELECT * from dsgi_request WHERE sku = '$search'";
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0) {
while ($rows=mysql_fetch_array($result)){
?>
Image not found on server. <br>
please Inform Engineering Team.
<?php
}
?>
<?php
}else{
?>
Image not found on server.<br> 
please Inform Engineering Team.
</table>
<table width="350" border="1" align="center" cellpadding="0" cellspacing="1">
  <tr>
  <td><form name="form1" method="post" action="request_ac.php">
  <table width="100%" border="1" cellspacing="1" cellpadding="3">
<tr>
<th colspan="3" >
  Image Request
</th>
  </tr>
  <tr>
    <td>SKU</td>
    <td>:</td>
    <td><input name="sku" type="text" id="sku" size="30" maxlength="6" /></td>
  </tr>
  <tr>
  <td width="97">Make</td>
  <td width="3">:</td>
  <td width="222"><input name="make" type="text" id="make" size="30"></td>
  </tr>
  <tr>
  <td>Model</td>
  <td>:</td>
  <td><input name="model" type="text" id="model" size="30"></td>
  </tr>
  <tr>
    <td>OS</td>
    <td>:</td>
    <td><input name="os" type="text" id="os" value="Which Version? Home, Basic?" size="30" /></td>
  </tr>
  <tr>
    <td>Serial</td>
    <td>:</td>
    <td><input name="serial" type="text" id="serial" size="30" /></td>
  </tr>
  <tr>
    <td>Bcn</td>
    <td>:</td>
    <td><input name="bcn" type="text" id="bcn" size="30" /></td>
  </tr>
  <tr>
    <td>Cell</td>
    <td>:</td>
    <td><label>
      <select name="personel" id="personel">
        <option selected="selected">Laptop Cell</option>
        <option>Cell A</option>
        <option>Cell B</option>
        <option>Cell C</option>
        <option>Desk Top's</option>
        </select>
      </label></td>
  </tr>
  <tr>
  <td>Date</td>
  <td>:</td>
  <td><input name="date" type="text" id="date" value="<?php echo date("d, M, Y - h:i:s"); ?>" size="30" readonly="readonly" /></td>
  </tr>
  <tr>
  <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
  </tr>
  </table>
  </form>
  </td>
  </tr>
</table>
<?Php
}
}
}
else{
$sql = "SELECT * from $tbl_name WHERE $ser_type like '%$search%'";
$result = mysql_query($sql);
$srch = strtoupper($search);
$sertype = strtoupper($ser_type);
// echo "$sertype Search Result's For $srch";
echo "Searched $sertype For $srch";
?>
</td>
  </tr>
</table>
<table class="table1" width="800" height="72" align="center">
  

<tr class="tablehead">
<td>Recon SKU</td>
<td>Orig SKU</td>
<td>Make</td>
<td>Model</td>
<td>Recovery</td>
</tr>
  
<?php

while ($rows=mysql_fetch_array($result)){

// table bg colour
$choice = strtoupper($rows['comments']);

$findme    = 'FAIL';
$findme1    = 'PASS';
$mystring2 = trim($rows['comments']);
$pos2 = stripos($mystring2, $findme);
$pos1 = stripos($mystring2, $findme1);

if ($pos1 !== false){ 
$bgc = "pass" ; }    
elseif ($pos2 !== false){
$bgc = "fail" ;   
}else{
$bgc = "wait" ; }

// $bgc = "#EE2C2C" ;red
// $bgc = "#FF6600" ; amber
?>
<?php $make = strtoupper($rows['make']); ?>
<tr id="tabledata" class="<?php echo "$bgc"; ?>">
<td> <?php echo $rows['sku'] ; ?></td>
<td> <?php echo $rows['rsku']; ?></td>
<td> <?php echo $make; ?></td>
<td> <?php echo $rows['model']; ?></td>
<td> <?php echo $rows['recovery']; ?></td>
</tr>
<?php
}
}
}
?>

<p> </p>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/222841-undefined-index/
Share on other sites

i got rid of the error using this

 

if(isset($_POST['search'])){

$ser_type=$_POST['list'];
$search = $_POST['search'];

if ($search == '' || $search == ' '){

echo "Search Field is Empty - Please Input a Search Query!";
die;
}
"rest of the code"
}

 

all i need to do now is figure out how to make the above "echo" to work 1st time around.

Link to comment
https://forums.phpfreaks.com/topic/222841-undefined-index/#findComment-1152328
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.