Jump to content

error submitting


searls03

Recommended Posts

why is $item not submitting to google docs like it is supposed to?  does it have something to do with how it is in a loop?

 <?php
session_start(); 
require_once "connect.php";


if(isset($_SESSION['logged'])){
// Query member data from the database and ready it for display

$cid = $_SESSION['complete'];  
$academy = $_SESSION['academy']; 
if($academy=="Old_Cheney"){$city= "Lincoln";}else if($academy=="Yankee_Hill"){$city= "Lincoln";}else if($academy=="Holdrege"){$city= "Lincoln";}else if($academy=="Maple"){$city= "Omaha";}
else if($academy=="Center"){$city= "Omaha";}
else if($academy=="PNS"){$city= "Pensacola";}
$sql = mysql_query("SELECT * FROM login where academy ='$academy'");
while($row = mysql_fetch_array($sql)){
$date =$row["date"];
if ($date !=="".date('m-d-Y')){echo '<meta http-equiv="REFRESH" content="0;url=login.php">';
   exit(); }
   

}
}else{
echo '<meta http-equiv="REFRESH" content="0;url=login.php">';
   exit(); 
}


echo $cid;

echo $academy;
echo $city;

?>

<?php 
   // load Zend Gdata libraries
    require_once 'Zend/Loader.php';
    Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');

    // set credentials for ClientLogin authentication
    $user = "blahb";
    $pass = "password";

    try {
      // connect to API
      $service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
      $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
      $service = new Zend_Gdata_Spreadsheets($client);


      // set target spreadsheet and worksheet
      $ssKey = '0AoUMgja4GxpJdFZwbn4444444XRU5pUlE';
      $wsKey = 'od6';

$sql4 = mysql_query("SELECT * FROM labels where item_id='".$pid."'");
$counter = 0;
while($row = mysql_fetch_array($sql4)){
$label =$row["label"];
$lid=$row['id'];

$counter = $counter + 1;
print $counter . "<BR>";


$item = $_POST['item'];
}

$date1234= date('m-d-y');
if($item ==''){$item=$dri;}
      // create row content
      $row = array(
        "date" => $date1234, 
        "name" => $name, 
        "item" => $item,
        "quantity" => $qty,
        "academy" => $academy,
        "paid" => 'yes'
      );

      // insert new row
      $entryResult = $service->insertRow($row, $ssKey, $wsKey);
      
    } catch (Exception $e) {
      die('ERROR: ' . $e->getMessage());
    }
    
    ?>

Link to comment
Share on other sites

hope this helps a bit.  this is the problem area:

$sql4 = mysql_query("SELECT * FROM labels where item_id='".$pid."'");
$counter = 0;
while($row = mysql_fetch_array($sql4)){
$label =$row["label"];
$lid=$row['id'];

$counter = $counter + 1;

print $counter . "<BR>";


$item = $_POST['item'];
}

$date1234= date('m-d-y');
if($item ==''){$item=$dri;}
      // create row content
      $row = array(
        "date" => $date1234, 
        "name" => $name, 
        "item" => $item,
        "quantity" => $qty,
        "academy" => $academy,
        "paid" => 'yes'
      );

      // insert new row
      $entryResult = $service->insertRow($row, $ssKey, $wsKey);
      
    } catch (Exception $e) {
      die('ERROR: ' . $e->getMessage());
    }

Link to comment
Share on other sites

Well this may be way off, but it looks like you are wanting to build an array ($row) with values from the query and from outside as well.  There is potential for problems if the results are more than one.  As you have a counter within the query result loop I can only assume you are expecting more than one record.  If this is the case, then the query loop must surround this whole bit of code, where you make the array and submit it or whatever the $entryResult sevice line is doing.  The name of the variable for the new array should also be different than the query result loop and the values should be added within this loop.  In the code you provided there are also extra brackets, which I will assume are started above provided code.

 

Anyway, without being able to test this, I would think you be looking at something more like this.

$item = $_POST['item'];
if($item ==''){$item=$dri;}	
$date1234= date('m-d-y'); 

sql4 = mysql_query("SELECT * FROM labels where item_id='".$pid."'");
$counter = 0;
while($row = mysql_fetch_array($sql4)){
$label =$row["label"];
$lid=$row['id'];
$counter = $counter + 1; 
      // create row content
      $result = array(
        "date" => $date1234, 
        "name" => $row['name'], 
        "item" => $item,
        "quantity" => $row['qty'],
        "academy" => $row['academy'],
        "paid" => 'yes'
      );

}//while($row = mysql_fetch_array($sql4)) 
      // insert new row
      $entryResult = $service->insertRow($result, $ssKey, $wsKey);
      
    } catch (Exception $e) {
      die('ERROR: ' . $e->getMessage());
    }

Link to comment
Share on other sites

btw, this is what I am trying to post:

<input type="text" name="item" value="T-Shirt: Dry Fit" />

31<BR>
<input type="text" name="label1" value="Size" />
<select name="name1">
Size

<option value="YS">
YS</option>
<option value="YM">
YM</option>
<option value="YL">
YL</option>
<option value="AS">
AS</option>

<option value="AM">
AM</option>
<option value="AL">
AL</option>
<option value="AXL">
AXL</option>
<option value="AXXL">
AXXL</option>
</select>
</br>
2<BR>
<input type="text" name="label2" value="Color" />

<select name="name2">
Color

<option value="Black">
Black</option>
<option value="Red">
Red</option>
</select>
</br>
3<BR>
<input type="text" name="label3" value="Chevrons" />
<select name="name3">
Chevrons

<option value="5">
5</option>

<option value="4">
4</option>
<option value="3">
3</option>
<option value="2">
2</option>
<option value="1">
1</option>
<option value="0">
0</option>
</select>
</br>

 

so When the string is done.....it would look like item label1 name1 label2 name2 label3 name3.  and there could be as many as needed....so it could go all the way to label100 name100

Link to comment
Share on other sites

I think you are updating a spreadsheet, right?  Never done this but I think you're going to want the query loop to wrap around your code.

 

$item = $_POST['item'];
if($item ==''){$item=$dri;}	
$date1234= date('m-d-y'); 

sql4 = mysql_query("SELECT * FROM labels where item_id='".$pid."'");
$counter = 0;
while($row = mysql_fetch_array($sql4)){
$label =$row["label"];
$lid=$row['id'];
$counter = $counter + 1; 
      // create row content
      $result = array(
        "date" => $date1234, 
        "name" => $row['name'], 
        "item" => $item,
        "quantity" => $row['qty'],
        "academy" => $row['academy'],
        "paid" => 'yes'
      );
      // insert new row
      $entryResult = $service->insertRow($result, $ssKey, $wsKey);
      
    } catch (Exception $e) {
      die('ERROR: ' . $e->getMessage());
    }	
}//while($row = mysql_fetch_array($sql4)) 

Link to comment
Share on other sites

I would think if the WHILE loop is closed after the array, then the array will only hold the last record.  You're making columns date, name, item etc. and giving a value or row under these columns, and as it loops though the records it should update the spreadsheet adding a record under each column.  If you only want one record, then change the query to only grab one record.

Link to comment
Share on other sites

so in one row, I want all the looped results to be in one string so that it posts properly.  In one code:

<?php
// Query member data from the database and ready it for display
$sql4 = mysql_query("SELECT * FROM labels where item_id='".$pid."'");
$num_rows = mysql_num_rows($sql4);
echo $num_rows;

$counter = 0;
while($row = mysql_fetch_array($sql4)){
$label =$row["label"];
$lid=$row['id'];

$counter = $counter + 1;
print $counter . "<BR>";
?>

<input type="text" name="label<?php echo $counter; ?>" value="<?php echo $label; ?>" />
<select name="name<?php echo $counter; ?>">
<?php

this is making a multitude of text boxes.  named label1(2,3,4,etc.)  and same for  name1(2,3,4, etc.).  The problem is I need to make post variable for all this inside the posting code, but then all of those post variables combine to make one string for one insert.  does this make a little bit more sense now?  so I need to make as many as the loop runs through. 

Link to comment
Share on other sites

ok.....so the original code that makes the field boxes

<?php
// Query member data from the database and ready it for display
$sql4 = mysql_query("SELECT * FROM labels where item_id='".$pid."'");
$num_rows = mysql_num_rows($sql4);
echo $num_rows;

$counter = 0;
while($row = mysql_fetch_array($sql4)){
$label =$row["label"];
$lid=$row['id'];

$counter = $counter + 1;
print $counter . "<BR>";
?>

<input type="text" name="label<?php echo $counter; ?>" value="<?php echo $label; ?>" />
<select name="name<?php echo $counter; ?>">

this makes

<input type="text" name="label1" value="<?php echo $label; ?>" />

<input type="text" name="label2" value="<?php echo $label; ?>" />

<input type="text" name="label3" value="<?php echo $label; ?>" />

<input type="text" name="label4" value="<?php echo $label; ?>" />

<select name="name1">

<select name="name2">

<select name="name3">

<select name="name4">

 

these could go on forever and never end.  So then in the code that posts, I need to figure out a way to make all the post variables with the correct names using a counter. 

 

then I need to combine all the post variables that were made to make a string that submits the string to one box in google docs.  does this make more sense?

 

Link to comment
Share on other sites

You don't need the counter.

<input type="text" name="label[]" value="<?php echo $label; ?>" />
<select name="name[]">

 

Then in processing you'd just do something like

foreach($_POST['label'] as $k => $label){
$name=$_POST['name'][$k];
//example echo
echo "$label - $name<br />";
}

 

Link to comment
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.