papillonstudios Posted June 19, 2009 Share Posted June 19, 2009 I'm trying to make the navbar for my cms editable from the admin panel, but well no success. heres the code <?php //Checks to see if theyre allowed to edit their profile if ($uCan['admin']) { //Double security incase the admin hasn't set a guest membergroup if ($uId) { //If the form hasn't been submitted, show it. if (!$_POST['update']) { ?> <form method="post"> <table width="75%"> <?php //Selecting the News From trhe Table news $query = "SELECT * FROM `nav`"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { echo '<tr><td>Link ' . $row['id'] . '<input type="text" size="25" maxlength="200" name="linkname' . $row['id'] . '" value="' . $row ['linkname'] .'"></td><td> <input type="text" size="25" maxlength="200" name="link"' . $row['id'] . '" value="' . $row ['link'] .'"> </td></tr>'; } ?> <tr><td><input type="submit" name="update" value="Change Navbar"></td></tr> </table> </form> <?php } //Or else it has been submitted... else { //Get information from the forms secure it all. $linknames = $_POST['linkname']; $links = $_POST['link']; $errors = array(); foreach ($linknames as $key => $value) { // optional, but this checks if everything is okay and not empty if (isset($links[$key]) && !empty($links[$key]) && !empty($value)) { $query = mysql_query(sprintf('UPDATE nav SET linkname%1$d = "%2$s" link%1$d = "%3$s" WHERE id = %1$d LIMIT 1;', $key, $value, $links[$key])); if (!$query) $errors[] = array('id' => $key, 'msg' => mysql_error()); } } if ($errors = count($errors)) echo sprintf('%d were found.', $errors); //A query to update everything } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/162868-database-table-not-updating/ Share on other sites More sharing options...
papillonstudios Posted June 19, 2009 Author Share Posted June 19, 2009 i tried var_dump($linksnames); and i get NULL and for var_dump($links); i got string(24) "index.php?action=contact" if that means anything Quote Link to comment https://forums.phpfreaks.com/topic/162868-database-table-not-updating/#findComment-859409 Share on other sites More sharing options...
priti Posted June 19, 2009 Share Posted June 19, 2009 Referring this --- linkname' . $row['id'] it is creating linkname1,linkename2,linkname3 so $linksnames is not an array try print linkname1 [ considering $row['id'] = 1] I think you are trying to make this as an array? Right? Quote Link to comment https://forums.phpfreaks.com/topic/162868-database-table-not-updating/#findComment-859416 Share on other sites More sharing options...
papillonstudios Posted June 19, 2009 Author Share Posted June 19, 2009 ok lets make this simple i will explain what i want it to do and well will go form there. I want the script to show 14 fields 7 linknames and 7 links and these fields will show to current linkname and link for a link in the navbar.(stored in database) then you can change the name of a link or the link url itself and click submit and it changes it in the database thus displaying the new link name or url in the navbar. if theres a better way of doing it then please tell Quote Link to comment https://forums.phpfreaks.com/topic/162868-database-table-not-updating/#findComment-859423 Share on other sites More sharing options...
priti Posted June 19, 2009 Share Posted June 19, 2009 I didn't understand but is following is your requirement link 1 :yahoo http://www.yahoo.com link 2:blog http://www.dummy.com submit button So when you change yahoo to gmail and link to www.gmail.com in database Link 1 sud get update to gmail-linkname and http://www.gmail.com as link (right) If above is the scenario then i recommend you to use 'update button' in front of all link set i.e link1 yahoo link update link link2 gmail link update link so when you click update button this will identify which link set to get modify .i.e $url= "link=$row['linkname']&linkurl=$row['link']"; <a href="samescript.name?$url"/>update</a> so when you click on update link it will hit the same script and perform the update query if(isset($_GET['link']) && isset($_GET['linkname'])) { query to update } I hope this may help. Let me know if any issues you come across. Quote Link to comment https://forums.phpfreaks.com/topic/162868-database-table-not-updating/#findComment-859507 Share on other sites More sharing options...
papillonstudios Posted June 19, 2009 Author Share Posted June 19, 2009 ok i get what you mean and thats a great idea but what would the update query look like? ok heres what the navbar looks like.(currently Home <> Downloads <> Games <> Videos <> LinkName <> LinkName you get the point and then i have the nav.php folder in the admin section.(currently) [LinkName] [Link] [LinkName] [Link] [LinkName] [Link] [LinkName] [Link [LinkName] [Link] [LinkName] [Link] [LinkName] [Link] [update Links] Quote Link to comment https://forums.phpfreaks.com/topic/162868-database-table-not-updating/#findComment-859685 Share on other sites More sharing options...
papillonstudios Posted June 22, 2009 Author Share Posted June 22, 2009 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/162868-database-table-not-updating/#findComment-861457 Share on other sites More sharing options...
priti Posted June 23, 2009 Share Posted June 23, 2009 'UPDATE nav SET linkname = "$_GET['linkname']" , link= "$_GET['linkname']" WHERE id = $_GET['id'] LIMIT 1;' will this will be helpful? Quote Link to comment https://forums.phpfreaks.com/topic/162868-database-table-not-updating/#findComment-861758 Share on other sites More sharing options...
papillonstudios Posted June 24, 2009 Author Share Posted June 24, 2009 I got it working, but now i got another most likely easier to solve. It gives me this error when i submit a link(i took your advice and make a change link button for each) heres the error Error message = You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' url = WHERE id =' at line 1 heres my code <?php //Checks to see if theyre allowed to edit their profile if ($uCan['admin']) { //Double security incase the admin hasn't set a guest membergroup if ($uId) { //If the form hasn't been submitted, show it. if (!$_POST['update']) { ?> <form method="post"> <table width="75%"> <?php //Selecting the News From trhe Table news $query = "SELECT * FROM `nav`"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { echo '<tr><td><input type="text" size="25" maxlength="200" name="linkname" value="' . $row ['linkname'] .'"></td><td> <input type="text" size="25" maxlength="200" name="url" value="' . $row ['url'] .'"> </td><td><input type="submit" name="update" value="Change Link "' . $row[' id'] . '></td></tr>'; } ?> </table> </form> <?php } //Or else it has been submitted... else { //Get information from the forms secure it all. $sitename = secure($_POST['linkname']); $url = secure($_POST['url']); $update = mysql_query("UPDATE nav SET linkname = " . $_GET['linkname'] . " , url = " . $_GET['url'] . " WHERE id = " . $_GET['id'] . ";"); if ($update) echo 'Link ' . $row['id'] . ' had been updated, click <a href="index.php?action=upnav">here</a> '; else echo "Error message = ".mysql_error(); //A query to update everything } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/162868-database-table-not-updating/#findComment-862459 Share on other sites More sharing options...
priti Posted July 1, 2009 Share Posted July 1, 2009 $query="UPDATE nav SET linkname = '" . $_GET['linkname'] . "' , url = '" . $_GET['url'] . "' WHERE id = " . $_GET['id'] . " echo $query; // run this query in mysql directly. try this Quote Link to comment https://forums.phpfreaks.com/topic/162868-database-table-not-updating/#findComment-866878 Share on other sites More sharing options...
joel24 Posted July 1, 2009 Share Posted July 1, 2009 Error message = You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' url = WHERE id =' at line 1 url = WHERE id =, none of the variables are being sent in the url? ... does your url look like whatever.php?id=X&url=Z&linkname=Y x, y and z are obviously the user input from the field. you should change the db query to the following in case the variables arent sent. //check if linkname, url and id are sent in the URL if (isset($_GET['linkname'], $_GET['url'], $_GET['id']) { $update = mysql_query("UPDATE nav SET linkname = " . $_GET['linkname'] . " , url = " . $_GET['url'] . " WHERE id = " . $_GET['id'] . ";"); } Quote Link to comment https://forums.phpfreaks.com/topic/162868-database-table-not-updating/#findComment-866886 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.