ben_johnson1991 Posted April 28, 2010 Share Posted April 28, 2010 Hey guys, ive simply have a table printed with all the page details on. the fields are shown on the 2nd part of the php script bellow. The print works fine, all $i increase each row.... the problem is when its posted, for some reason the posts aren't coming through correctly or nothing.. the count only counts 1, and update doesnt do anything, but it apparently runs correctly as it print UPDATED.. I'm pretty sure its a minor mess up, but i'm using trial and error and getting no where. any guidance would be much appreciated!! Cheers, Ben. include_once "connect_to_mysql.php"; //////////SPupdate if(isset($_POST['updateSP'])){ $size = count($_POST['id']); print 'Count: '.$size.''; $i = 0; while ($i < $size) { // define each variable $pmainp_id= $_POST['pmainp_id'][$i]; $porder_no = $_POST['porder_no'][$i]; $pname = $_POST['pname'][$i]; $plink = $_POST['plink'][$i]; $ppage = $_POST['ppage'][$i]; $id = $_POST['id'][$i]; $query = mysql_query("UPDATE pages SET mainp_id = '$pmainp_id', order_no='$porder_no', name = '$pname', link='$plink', page = '$ppage' WHERE subp_id = '$id' LIMIT 1"); print"".$pname." UPDATE<br/>"; ++$i; } if($query){ print "UPDATED"; } else{ print "UPDATE FAIL"; } } //////////////////////////////////////////////////////////////////////////// ///////// SUB PAGES //////////////////////////////////////////////////////////////////////////// $subopageget = mysql_query("SELECT * FROM pages ORDER BY mainp_id, order_no ASC"); $i = 1; while ($srow = mysql_fetch_array($subopageget)){ $subp_id = $srow['subp_id']; $mainp_id = $srow['mainp_id']; $link = $srow['link']; $name = $srow['name']; $order_no = $srow['order_no']; $page = $srow['page']; $subpagerow .= ' <input type="hidden" name="id[$i]" id="id[$i]" value"'.$subp_id.'" /> <tr> <td><input name="pmainp_id[$i]" type="text" value="'.$i.' - '.$mainp_id.'"/></td> <td><input name="porder_no[$i]" type="text" value="'.$order_no.'"/></td> <td><input name="pname[$i]" type="text" value="'.$name.'"/></td> <td><input name="plink[$i]" type="text" value="'.$link.'"/></td> <td><input name="ppage[$i]" type="text" value="'.$page.'"/></td> </tr> '; ++$i; } Link to comment https://forums.phpfreaks.com/topic/200020-simple-update-while-confusion/ Share on other sites More sharing options...
mcjwb Posted April 28, 2010 Share Posted April 28, 2010 Is it down to the outputted html in the variable "$subpagerow"? The $i doesn't look like it'll get parsed in some places, e.g. id="id[$i]" should be id="id['.$i.']" Does that help? Link to comment https://forums.phpfreaks.com/topic/200020-simple-update-while-confusion/#findComment-1049811 Share on other sites More sharing options...
ben_johnson1991 Posted April 28, 2010 Author Share Posted April 28, 2010 Cheers for the reply. I've changed the $i as suggested $subpagerow .= ' <input type="hidden" name="id['.$i.']" id="id['.$i.']" value"'.$subp_id.'" /> <tr> <td><input name="pmainp_id['.$i.']" type="text" value="'.$mainp_id.'"/></td> <td><input name="porder_no['.$i.']" type="text" value="'.$order_no.'"/></td> <td><input name="pname['.$i.']" type="text" value="'.$name.'"/></td> <td><input name="plink['.$i.']" type="text" value="'.$link.'"/></td> <td><input name="ppage['.$i.']" type="text" value="'.$page.'"/></td> </tr> '; which now produces the correct $size variable, but still the update isnt actually updating. Link to comment https://forums.phpfreaks.com/topic/200020-simple-update-while-confusion/#findComment-1049843 Share on other sites More sharing options...
PFMaBiSmAd Posted April 28, 2010 Share Posted April 28, 2010 There is no equal sign = in the value = "..." attribute - <input type="hidden" name="id['.$i.']" id="id['.$i.']" value"'.$subp_id.'" /> Link to comment https://forums.phpfreaks.com/topic/200020-simple-update-while-confusion/#findComment-1049849 Share on other sites More sharing options...
ben_johnson1991 Posted April 28, 2010 Author Share Posted April 28, 2010 Fuck me man lol, how long i've wasted for just that! Cheers for that dude! Link to comment https://forums.phpfreaks.com/topic/200020-simple-update-while-confusion/#findComment-1049854 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.