steveh62 Posted January 28, 2009 Share Posted January 28, 2009 I have a number of variables which I post and collect via $var = $_POST['something']; in particular the following gets sent by post <?php $labels = array( 0 => '200mm x 200mm', 1 => '200mm x 300mm', 2 => '200mm x 400mm', 3 => '200mm x 500mm', 4 => '200mm x 600mm', ); foreach ($labels as $ar => $label) { print '<label>' .$label. '</label><input id="sizes" name="sizes[' .$ar. ']" type="checkbox" onclick="setChecks(this)" value="' . $label. '"'; if ($ar == 0){ // print "checked"; } print ' /><input id="price" name="price[' .$ar. ']" type="text" class="dropdown" /><br/>'; } ?> and then picked up and used like <?php $foo = $_POST['sizes']; //if(isset($_POST['$foo'])){ if (count($foo > 0)) { // loop through the array foreach ($foo as $key => $size) { //echo $size.'<br/>'; $sprice = $_POST['price'][$key]; //echo 'price:'.$sprice; //for ($i=0;$i<count($foo);$i++) // {//now insert sizes in table spcanvas_sizes mysql_query( "INSERT INTO spcanvas_sizes(`sizes`, `canv_price`, `pid`) VALUES('".$size."', '".$sprice."', '".$id."')" ); // do something - this can be a SQL query, // echoing data to the browser, or whatever //echo "<li>$foo[$i] \n"; } //end for loop } //end if ?> THE PROBLEM IS...the data does get POSTED yet the database insert an extra record at the begining with nothing inserted ANY IDEAS ANYONE Link to comment https://forums.phpfreaks.com/topic/142795-solved-posting-variables/ Share on other sites More sharing options...
gevans Posted January 28, 2009 Share Posted January 28, 2009 do this; mysql_query( "INSERT INTO spcanvas_sizes(`sizes`, `canv_price`, `pid`) VALUES('".$size."', '".$sprice."', '".$id."')" ) or die(mysql_error()); And php will tell you the problem Link to comment https://forums.phpfreaks.com/topic/142795-solved-posting-variables/#findComment-748465 Share on other sites More sharing options...
steveh62 Posted January 28, 2009 Author Share Posted January 28, 2009 Not telling me a thing. I have errors turned on so I will see them/any if they occur. Additonally, I am NOT getting the above error Locally...everything inserts to the db as it should without including a blank entry at the start of insertion Link to comment https://forums.phpfreaks.com/topic/142795-solved-posting-variables/#findComment-748480 Share on other sites More sharing options...
steveh62 Posted January 28, 2009 Author Share Posted January 28, 2009 any ideas anyone?? please its nearly finished but for this...can't see why everything is ok locally but not on live test site Link to comment https://forums.phpfreaks.com/topic/142795-solved-posting-variables/#findComment-748496 Share on other sites More sharing options...
gevans Posted January 28, 2009 Share Posted January 28, 2009 Sorry, I miss read your problem. If you do a view source on the original page can you post your whole form? Link to comment https://forums.phpfreaks.com/topic/142795-solved-posting-variables/#findComment-748498 Share on other sites More sharing options...
steveh62 Posted January 28, 2009 Author Share Posted January 28, 2009 Basically, what happens is the array makes up 5 checkboxes with associated price inputs and on submitting gets posted. As part of the submittion, data and images get inserted to a db table and is assigned an id. **as part of knowing where to associated the sizes the code picks out the latest id and uses that to insert the sizes and prices to a particular id. But on the live test site the db is inserting a BLANK row which in turn gets pushed to the user as option 1 being blank. This does not happen locally tho' <?php $labels = array( 0 => '200mm x 200mm', 1 => '200mm x 300mm', 2 => '200mm x 400mm', 3 => '200mm x 500mm', 4 => '200mm x 600mm', ); foreach ($labels as $ar => $label) { print '<label>' .$label. '</label><input id="sizes" name="sizes[' .$ar. ']" type="checkbox" onclick="setChecks(this)" value="' . $label. '"'; if ($ar == 0){ // print "checked"; } print ' /><input id="price" name="price[' .$ar. ']" type="text" class="dropdown" /><br/>'; } ?> the above gets posted to below <?php if(get_magic_quotes_gpc()) { $gallerytype = stripslashes($_POST['gallerytype']); $wrap = stripslashes($_POST['wrap']); $frame = stripslashes($_POST['frame']); $title = stripslashes($_POST['title']); $description = stripslashes($_POST['description']); $keywords = stripslashes($_POST['keywords']); $category = stripslashes($_POST['category']); $cat = stripslashes($_POST['cat']); $foo2 = stripslashes($_POST['sizes2']); $price = stripslashes($_POST['price']); $sprice = stripslashes($_POST['price2']); $foo = stripslashes($_POST['sizes']); } else { $gallerytype = $_POST['gallerytype']; $wrap = $_POST['wrap']; $frame = $_POST['frame']; $title = $_POST['title']; $description = $_POST['description']; $keywords = $_POST['keywords']; $category = $_POST['category']; $cat = $_POST['cat']; $foo2=$_POST['sizes2']; $price = $_POST['price']; $sprice = $_POST['price2']; $foo = $_POST['sizes']; } /////////load it//////////// mysql_query( "INSERT INTO gallery(`galleryType`, `print`, `frame`, `title`, `filename`, `desc`, `keywords`, `gid`, `gCATID`) VALUES('".$gallerytype."', '".$wrap."', '".$frame."', '".$title."', '".addslashes($thumbname)."', '".$description."', '".$keywords."', '".$category."', '".$cat."')" ); //now retrieve last item from gallery as it will need to have at least 1 size applied to spsizes table $qry = mysql_query("SELECT * FROM gallery ORDER BY id DESC LIMIT 1"); while( $row = mysql_fetch_array( $qry ) ) { $id = stripslashes($row['id']); echo 'latest id:'.$id; } imagejpeg($tn, $save, 80) ; echo "<span class='dropdown'>Large image:</span> <img src='".$images_dir."/".$imagepath."'><br>"; echo "<span class='dropdown'>Thumbnail:</span><img src='".$images_dir."/tb_".$imagepath."'>"; ////get sizes//////////////////////////// ////select for specials one only size and price if(isset($foo2)){ mysql_query( "INSERT INTO spcanvas_sizes(`sizes`, `canv_price`, `pid`) VALUES('".$foo2."', '".$sprice."', '".$id."')" ); } ///checkbox//// if(isset($_POST['sizes'])){ $foo = $_POST['sizes']; //if(isset($_POST['$foo'])){ if (count($foo > 0)) { // loop through the array foreach ($foo as $key => $size) { echo $key.'<br/>'; $sprice = $_POST['price'][$key]; //echo 'price:'.$sprice; //for ($i=0;$i<count($foo);$i++) // {//now insert sizes in table spcanvas_sizes mysql_query( "INSERT INTO spcanvas_sizes(`sizes`, `canv_price`, `pid`) VALUES('".$size."', '".$sprice."', '".$id."')" )or die(mysql_error()); // do something - this can be a SQL query, // echoing data to the browser, or whatever //echo "<li>$foo[$i] \n"; } //end for loop } //end if count }//isset sizes ?> Link to comment https://forums.phpfreaks.com/topic/142795-solved-posting-variables/#findComment-748507 Share on other sites More sharing options...
gevans Posted January 28, 2009 Share Posted January 28, 2009 Start your second page with; <?php echo '<pre>'; var_dump($_POST); echo '</pre>'; You'll be able to see if anything is getting passed Link to comment https://forums.phpfreaks.com/topic/142795-solved-posting-variables/#findComment-748510 Share on other sites More sharing options...
steveh62 Posted January 28, 2009 Author Share Posted January 28, 2009 ok, it looks ok, but its creating an extra entry at the start of the insert into spcanvas_sizes on the test site. Is there a better way to get both the sizes and prices to match up and be inserted into the table?? rgds steve Link to comment https://forums.phpfreaks.com/topic/142795-solved-posting-variables/#findComment-748543 Share on other sites More sharing options...
steveh62 Posted January 28, 2009 Author Share Posted January 28, 2009 so does anybody know why the submittion is inserting an empty entry before inserting the data [sizes] and an associative [price] the array gets looped thru the size array we price[$key] - as $key is the pointer for the size array - so in essence it shuold get the data from 0 to 4 if they are checked and as we loop it inserts the data into the table 'spcanvas_sizes. Link to comment https://forums.phpfreaks.com/topic/142795-solved-posting-variables/#findComment-748552 Share on other sites More sharing options...
steveh62 Posted January 28, 2009 Author Share Posted January 28, 2009 ok sorted it I was testing for magic_quotes_gpc which errored using stripslashes. so I have edited that out and now it inserts fine...missus Link to comment https://forums.phpfreaks.com/topic/142795-solved-posting-variables/#findComment-748565 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.