9three Posted December 11, 2008 Share Posted December 11, 2008 I'm back again with a similar problem *sigh* :'( I just tried out a different way of updating a row and it's not working as intended: <?php $nav_results = mysql_query("SELECT * FROM navigation"); while($field = mysql_fetch_array($nav_results)) { $id = $field['ID']; //For sake of simplicity echo "<tr><td align='center'><input type='text' name='". $field['Name'] ."' value='". $field['Name'] ."' class='field2' /></td>\n"; echo "<td align='center'><input type='text' name='URL' value='". $field['URL'] ."' class='field2' /></td>\n"; echo "<td align='center'><a href='$id'>Up</a> | <a href='$id'>Down</a></td>\n"; echo "<td align='center'><a href='nav_settings.php?delete='$id'>Delete</a></td></tr>\n"; } if(!empty($_POST['URL'])) //Update existing link { $id = $field['ID']; //For sake of simplicity $old_link = mysql_real_escape_string($_POST['URL']); $update = mysql_query("UPDATE navigation SET URL='$old_link' WHERE ID='$id'"); } else { echo 'Unable to update right: ' .mysql_error(). ' '; } ?> [/php The loop works perfect. When the script gets to the UPDATE part its where the trouble starts. It doesn't update at all(once again). I tried using mysql_error but its not throwing an error out. Although it is throwing "Unable to update:" I need the wisdom again ??? Link to comment https://forums.phpfreaks.com/topic/136565-unable-to-update-row-part-2/ Share on other sites More sharing options...
Maq Posted December 11, 2008 Share Posted December 11, 2008 Change: $update = mysql_query("UPDATE navigation SET URL='$old_link' WHERE ID='$id'"); To: $update = "UPDATE navigation SET URL='$old_link' WHERE ID='$id'"; mysql_query($update) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/136565-unable-to-update-row-part-2/#findComment-712886 Share on other sites More sharing options...
premiso Posted December 11, 2008 Share Posted December 11, 2008 $_POST['URL'] is empty if it is throwing that error. Check your POST variables. Link to comment https://forums.phpfreaks.com/topic/136565-unable-to-update-row-part-2/#findComment-712887 Share on other sites More sharing options...
9three Posted December 11, 2008 Author Share Posted December 11, 2008 I tried changing it $update = "UPDATE navigation SET URL='$old_link' WHERE ID='$id'"; mysql_query($update) or die(mysql_error()); And it doesn't throw any error out. I also checked for my Post variables if they were empty but my POST variables always contain a string. If you don't update the field, the field shows the current data in that row. Link to comment https://forums.phpfreaks.com/topic/136565-unable-to-update-row-part-2/#findComment-712889 Share on other sites More sharing options...
premiso Posted December 11, 2008 Share Posted December 11, 2008 Do me a favor and do this: <?php print_r($_POST); die(); $nav_results = mysql_query("SELECT * FROM navigation"); while($field = mysql_fetch_array($nav_results)) { $id = $field['ID']; //For sake of simplicity echo "<tr><td align='center'><input type='text' name='". $field['Name'] ."' value='". $field['Name'] ."' class='field2' /></td>\n"; echo "<td align='center'><input type='text' name='URL' value='". $field['URL'] ."' class='field2' /></td>\n"; echo "<td align='center'><a href='$id'>Up</a> | <a href='$id'>Down</a></td>\n"; echo "<td align='center'><a href='nav_settings.php?delete='$id'>Delete</a></td></tr>\n"; } if(!empty($_POST['URL'])) //Update existing link { $id = $field['ID']; //For sake of simplicity $old_link = mysql_real_escape_string($_POST['URL']); $update = mysql_query("UPDATE navigation SET URL='$old_link' WHERE ID='$id'"); } else { echo 'Unable to update right: ' .mysql_error(). ' '; } ?> And paste what that prints out. Link to comment https://forums.phpfreaks.com/topic/136565-unable-to-update-row-part-2/#findComment-712891 Share on other sites More sharing options...
9three Posted December 11, 2008 Author Share Posted December 11, 2008 It printed out: Array ( ) Link to comment https://forums.phpfreaks.com/topic/136565-unable-to-update-row-part-2/#findComment-712897 Share on other sites More sharing options...
premiso Posted December 11, 2008 Share Posted December 11, 2008 It printed out: Array ( ) Thus you are not POSTing to that form. How is the URL to be transferred to that update page? Link to comment https://forums.phpfreaks.com/topic/136565-unable-to-update-row-part-2/#findComment-712899 Share on other sites More sharing options...
Maq Posted December 11, 2008 Share Posted December 11, 2008 Post your form. Link to comment https://forums.phpfreaks.com/topic/136565-unable-to-update-row-part-2/#findComment-712901 Share on other sites More sharing options...
9three Posted December 11, 2008 Author Share Posted December 11, 2008 Well I actually have 2 forms in one HTML page. Maybe they are in conflict with each other. My 2nd form works perfect, which is to INSERT a new row. But updating it which is my 1st form, does not work at all. Ill try assigning names to them now. Well that didn't help :-\ Form1 <form name="edit" method="post" action="nav_settings.php"> <table width="95%" border="0" cellpadding="1" cellspacing="0" align="center"> <tr align="center"> <td>Name</td> <td>URL</td> <td>Sort</td> <td>Delete</td> </tr> <tr align="center"> <?php $nav_results = mysql_query("SELECT * FROM navigation"); while($field = mysql_fetch_array($nav_results)) { $id = $field['ID']; //For sake of simplicity echo "<tr><td align='center'><input type='text' name='". $field['Name'] ."' value='". $field['Name'] ."' class='field2' /></td>\n"; echo "<td align='center'><input type='text' name='URL' value='". $field['URL'] ."' class='field2' /></td>\n"; echo "<td align='center'><a href='$id'>Up</a> | <a href='$id'>Down</a></td>\n"; echo "<td align='center'><a href='nav_settings.php?delete='$id'>Delete</a></td></tr>\n"; } if(!empty($_POST['URL'])) //Update existing link { $id = $field['ID']; //For sake of simplicity $old_link = mysql_real_escape_string($_POST['URL']); $update = mysql_query("UPDATE navigation SET URL='$old_link' WHERE ID='$id'"); } ?> </tr> </table> </p> <table width="95%" border="0" cellspacing="0" cellpadding="0"> <tr align="right"> <td><p><input type="submit" name="edit" value="Save Settings" class="button" /></p></td> </tr> </table></td> </tr> </table> </form> Form2 <form name="add" method="post" action="nav_settings.php"> <table width="95%" border="0" cellpadding="1" cellspacing="0" align="center"> <tr> <td> <p class="attention">New Link</p> </td> <td align="right"> <input type="text" name="link" value="" class="field" /> </td> </tr> </table> </p> <table width="95%" border="0" cellspacing="0" cellpadding="0"> <tr align="right"> <td><p><input type="submit" name="edit" value="Add Link" class="button" /></p></td> </tr> </table></td> </tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/136565-unable-to-update-row-part-2/#findComment-712906 Share on other sites More sharing options...
Maq Posted December 11, 2008 Share Posted December 11, 2008 Why do you have 2 forms? Link to comment https://forums.phpfreaks.com/topic/136565-unable-to-update-row-part-2/#findComment-712917 Share on other sites More sharing options...
9three Posted December 11, 2008 Author Share Posted December 11, 2008 Well one form is to edit (AKA UPDATE a row) an existing row and the 2nd to add a new row (aka link) Link to comment https://forums.phpfreaks.com/topic/136565-unable-to-update-row-part-2/#findComment-712923 Share on other sites More sharing options...
9three Posted December 11, 2008 Author Share Posted December 11, 2008 Anyone got any ideas? Link to comment https://forums.phpfreaks.com/topic/136565-unable-to-update-row-part-2/#findComment-712965 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.