searls03 Posted April 1, 2012 Share Posted April 1, 2012 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()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/ Share on other sites More sharing options...
trq Posted April 1, 2012 Share Posted April 1, 2012 If you indented your code so that it was readable someone might actually read it and help you. Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333201 Share on other sites More sharing options...
searls03 Posted April 1, 2012 Author Share Posted April 1, 2012 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()); } Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333203 Share on other sites More sharing options...
Drummin Posted April 1, 2012 Share Posted April 1, 2012 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()); } Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333210 Share on other sites More sharing options...
searls03 Posted April 1, 2012 Author Share Posted April 1, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333211 Share on other sites More sharing options...
searls03 Posted April 1, 2012 Author Share Posted April 1, 2012 no I don't want to post an array like that. it would insert multiple rows. I only want one row. Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333212 Share on other sites More sharing options...
Drummin Posted April 1, 2012 Share Posted April 1, 2012 The problem is you can't build a single array with multiple items as each key needs to be unique. I'll get back to you on this if no one else responds. Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333214 Share on other sites More sharing options...
searls03 Posted April 1, 2012 Author Share Posted April 1, 2012 so what would be the best way to go about this? I suck at writing arrays and I need advice on them Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333216 Share on other sites More sharing options...
Drummin Posted April 1, 2012 Share Posted April 1, 2012 What is the $entryResult sevice line is doing? And what's above the query? Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333217 Share on other sites More sharing options...
Drummin Posted April 1, 2012 Share Posted April 1, 2012 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)) Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333222 Share on other sites More sharing options...
searls03 Posted April 1, 2012 Author Share Posted April 1, 2012 If I do that, it would insert multiple rows. I only want one row, Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333292 Share on other sites More sharing options...
Drummin Posted April 1, 2012 Share Posted April 1, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333298 Share on other sites More sharing options...
searls03 Posted April 1, 2012 Author Share Posted April 1, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333299 Share on other sites More sharing options...
searls03 Posted April 1, 2012 Author Share Posted April 1, 2012 I could do it using if isnot empty statements....but then I would have to limit options. I don't want to do this. Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333300 Share on other sites More sharing options...
Drummin Posted April 1, 2012 Share Posted April 1, 2012 So are you saying WHILE results are going into different selection boxes? Maybe explaining WHAT you are trying to do might help. Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333307 Share on other sites More sharing options...
searls03 Posted April 1, 2012 Author Share Posted April 1, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333315 Share on other sites More sharing options...
searls03 Posted April 1, 2012 Author Share Posted April 1, 2012 so I would need to make $_POST['label1/name1'] $_POST['label2/name2'] $_POST['label3/name3'] $_POST['label4/name4'] or as many that are as needed. then they need to combine all of those into one string for submissions. Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333319 Share on other sites More sharing options...
Drummin Posted April 1, 2012 Share Posted April 1, 2012 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 />"; } Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333322 Share on other sites More sharing options...
searls03 Posted April 1, 2012 Author Share Posted April 1, 2012 then I need a way to combine all the arrays to make one variable for posting to the spreadsheet. Quote Link to comment https://forums.phpfreaks.com/topic/260118-error-submitting/#findComment-1333325 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.