spacepoet Posted November 30, 2010 Share Posted November 30, 2010 Hello: I have a question. I use to - when I was doing Classic ASP - make a single navigation file to include all aspects of site navigation. I'm trying to do that now in PHP, but keep getting errors. Can some set me straight (I am assuming what I want to do can be done in PHP). I have my myNav.php file (in an "include" subfolder): <?php function showLinks() <script type="text/javascript" src="include/spNewWindow.js"></script> <script type="text/javascript" src="include/openSesame.js"></script> <link rel="stylesheet" type="text/css" href="include/StyleSheet.css" /> ?> <?php function showTopMenu() <a href="#">Link 1</a><br /> <a href="#">Link 2</a><br /> <a href="#">Link 3</a><br /> ?> This is the myPage.php I am trying to pull it in to: <?php include('include/myNav.php'); ?> <html> <head> <title></title> <?php echo $showLinks; ?> </head> <body> <div id="myMenu"> <?php echo $showTopMenu; ?> </div> ... REST OF SITE, ETC ... </body> </html> However, this is not working at all. I have figured out how to make files for each individual aspect - Menu, Footer, META tags, etc - but I would like to do this with one file as shown above. Is this possible? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/220280-making-1-navigation-file-to-control-entire-site/ Share on other sites More sharing options...
Pikachu2000 Posted November 30, 2010 Share Posted November 30, 2010 Your function doesn't actually do anything. function showTopMenu() { $menu = "<a href=\"#\">Link 1</a><br />\n <a href=\"#\">Link 2</a><br />\n <a href=\"#\">Link 3</a><br />"; return $menu; } //Then use: echo showTopMenu(); Quote Link to comment https://forums.phpfreaks.com/topic/220280-making-1-navigation-file-to-control-entire-site/#findComment-1141505 Share on other sites More sharing options...
spacepoet Posted December 1, 2010 Author Share Posted December 1, 2010 Hey. Thank you! OK, I got it: <?php function showLinks() { $showLinks = " <script type=\"text/javascript\" src=\"include/spNewWindow.js\"></script>\n <script type=\"text/javascript\" src=\"include/openSesame.js\"></script>\n <link rel=\"stylesheet\" type=\"text/css\" href=\"include/StyleSheet.css\" />"; return $showLinks; } function showtopMenu() { $showtopMenu = " <a href=\"#\">Link 1</a><br />\n <a href=\"#\">Link 2</a><br />\n <a href=\"#\">Link 3</a><br />"; return $showtopMenu; } ?> Thanks for pointing this out. Leads to another question: I have a basic form that updates a record via a few text fields and a textarea field. I have noticed that when I add an " ' " (apostrophe) it, it adds a "/" (slash) to the data. And, I noticed you use a "/" (slash) in your fuction example. Does one need to somehow "escape" all apostrophes and quotes with PHP? If so, is there a way to pull in a code library to handle it? I use to use one in ASP programming. Like: <?php include('include/myCodeLib.php'); ?> myCodeLib.php: <?php function replaceDashes() { SOME KIND OF CODE HERE ?> } Possible? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/220280-making-1-navigation-file-to-control-entire-site/#findComment-1141642 Share on other sites More sharing options...
jcbones Posted December 1, 2010 Share Posted December 1, 2010 If it is automatically adding slashes to your data, then magic_quotes_gpc() is turned on. You should bypass this, and run mysql_real_escape_string(). This second function will properly escape the data, without leaving a slash on the quotes. Something like this should get you started: if(get_magic_quotes_gpc()) { $_POST = array_map('stripslashes',$_POST); $_GET = array_map('stripslashes',$_GET); $_COOKIE = array_map('stripslashes',$_COOKIE); } Quote Link to comment https://forums.phpfreaks.com/topic/220280-making-1-navigation-file-to-control-entire-site/#findComment-1141653 Share on other sites More sharing options...
spacepoet Posted December 1, 2010 Author Share Posted December 1, 2010 Hi: OK, thanks much for the tip and info. I truly don't know what any of that means. Is that something controled on the server/mySQL DB? I am making the jump from ASP to PHP, and need to get up to speed on things like this. Your code, is that a function to be called in via a code libraby like I mentioned, or added to the SQL UPDATE statement? My code (which I got A LOT of help on from here!) is like this: <?php include('include/myConn.php'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $myTitle = mysql_real_escape_string($_POST['myTitle']); $myDesc = mysql_real_escape_string($_POST['myDesc']); $myHeader = mysql_real_escape_string($_POST['myHeader']); $mySubHeader = mysql_real_escape_string($_POST['mySubHeader']); $myPageData = mysql_real_escape_string($_POST['myPageData']); $sql = " UPDATE myAbout SET myTitle = '$myTitle', myDesc = '$myDesc', myHeader = '$myHeader', mySubHeader = '$mySubHeader', myPageData = '$myPageData' "; mysql_query($sql) && mysql_affected_rows() ?> <script language="JavaScript"> alert("This page was updated!"); location.href = "a_About.php"; </script> <?php $query=mysql_query("SELECT * FROM myAbout") or die("Could not get data from db: ".mysql_error()); while($result=mysql_fetch_array($query)) { $myTitle=$result['myTitle']; $myDesc=$result['myDesc']; $myHeader=$result['myHeader']; $mySubHeader=$result['mySubHeader']; $myPageData=$result['myPageData']; ?> ...... <form method="post" action="<?php echo $PHP_SELF;?>"> <input type="hidden" name="POSTBACK" value="EDIT"> <div style="float: left; width: 550px;"> <textarea cols="80" rows="1" name="myTitle"><?php echo $myTitle; ?></textarea> </div> ETC ... <br /> <input type="submit" value="Submit" /> </form> This forum is really making this easier! Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/220280-making-1-navigation-file-to-control-entire-site/#findComment-1141656 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.