PHP - Display Content On Index.php And Not On Index.php?dynamic
Hi there,
I was wondering if there is a way to display content on only my index.php page? I believe there is a way and I have done it before, but some of my pages use index.php?category etc. Is there a way to show content just on index.php and not on any dynamic pages? Thanks Similar TutorialsI really dont no what the problem is and im new here so i dont no if this is the right place to put this but im trying to make a registration page for my server and when i bring it up it says Undefined index: action in C:\xampp\htdocs\index.php on line 56 and idk what to do >.< this is the line that has the problem if($_POST['action']!="signup") so hopefully u guys could help me :/ Im using xampp btw Hello everyone, i have this page in my website called "index.php": <?php include("include/open_conn.php");?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>name site</title> </head> <body> <div id="container"> <?php include("include/header.php");?> <?php include("include/content.php");?> <?php include("include/footer.php");?> </div> </body> </html> <?php include("include/close_conn.php");?> The content change dinamically with this code "content.php": $pages_dir = 'pages'; if (!empty($_GET['menu'])) { $pages = scandir($pages_dir, 0); unset($pages[0], $pages[1]); $menu = $_GET['menu']; if (in_array($menu.'.php', $pages)) { include($pages_dir.'/'.$menu.'.php'); } So, when i change the page the url will be " index.php?menu=nameofmypage ". But now i want to put an image only in my index.php page, a sort of welcome to the users, but with this codes the image will appear in all the other page because i change only the content. I know that i could create a page named "home.php" and do all i want, but i want to change the first page that the user see when he types the address of my website. thank you! Hello. I am attempting to display content from a database to a web page. I have SELECT * etc to do this, plus the menu that should be displayed has links to pages. This would display text to the page depending on the link, for this to work I use the id of the page ($Get['id']). Following advice (not code), I have attempted the following:
<!DOCTYPE html> <html> <?php include 'includes/headsection.php'; ?> <body> <?php // query database if (!empty($_GET['id']) && (intval($_GET['id']) == $_GET['id'])) { $pdo_statement = $conn->prepare("SELECT * FROM pages WHERE id=:id ORDER BY id ASC"); $pdo_statement->execute(['id' => $_GET['id']]); $result = $pdo_statement->fetchAll(); } ?> <!-- topMenu --> <table id="topMenu"> <tr> <td><h1 class="siteName">Site name</h1></td> <td> <?php if(!empty($result)) { foreach($result as $row) { ?> <a href="index.php?id=<?php echo $row['id']; ?>"><?php echo $row['menuheader']; ?></a> <?php } } ?> </td> </tr> </table> This issue is that the top menu (home, etc), does not appear, and there are no errors to suggest what I have done wrong. Any help will be appreciated. I include a picture of what I mean. There should be Home | other | etc...
i'm running code on what i only want to be the HOME page, but the current site it built using GET variables with index.php needless to say, the home page is accessed either as domain.com/ or domain.com/index.php - i'm hoping someone can show me how to check for this condition, that it is only index.php without anything further I'm only slightly familiar with $_SERVER['uri'], etc... So i don't know just what to ask. thanks for anyone's help. Glenn An open question this, and one that may or may not bear fruit. But here we go anyway. index.php is a special case I feel because it is often the default script that is called for a web site. Moreover, I keep mine in the freely available root directory, but the rest of my php is out of the root for security purposes - in a directory called "lib". The app I am working on at the present time requires that a user logs on first. So, the code I have in my index.php is very simple: Code: [Select] <?php /* Require Log In */ require("lib/ezLogin.php"); ?> This at least is what I have presently. So I have a few questions: 1. Is treating index.php as a special case, a reasonable approach would you say? 2. Is the separation of the rest of the non-client php files a real security improvement? 3. When you declare the css path, do you use absolute path names? If so, how might it be done so it will work on local (testing) AND the main server (production) with no code change? 4. includes_path - I assume this is the path to the includes directory. However, I am not sure/happy/comfortable with this just yet. Can more than one path be included in this? (I have Googled around but still unhappy) If so, how so? Does this approach works across platforms? If not, is there a way to make it? Many thanks for any help. S I have two files an sample.html which has just a search box some javascript on it to display images when users start typing on this search box. the sample.html works when i entre localhost\index.html now, i have an index.php. when i include("index1.html"); the search box appears but the javascript does not work? why? do i need to relink the following in my sample.html??? <script type="text/javascript" src="autocomplete/lib/jquery.js"></script> <script type='text/javascript' src='jquery.autocomplete.js'></script> <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" /> fyi i am using wordpress. So I've searched for a few hours already, and decided to give in to asking on a forums. On the site I'm working on, I want the navigation to look like www.website.com/index.php?id=2 instead of www.website.com/contacts.htm Also, the way I did it before, I renamed my main home page as 'main.php' and when you go to the site, index.php will display what's on main.php, but will still show www.website.com/index.php?id=1. I've done it before a few years ago, but I lost the site and forgot how to do it. I'm pretty sure there's a if/else if statement that comes into play, but I don't remember. I hope this all makes sense. Thanks Hi guys I am getting an error of Code: [Select] Notice: Undefined index: photo_filename in /home/sites/haldonguesthouse.co.uk/public_html/new-site/admin/upload.php on line 28 I understand that the error would suggest that the field is not referenced on the form that is used to post the values through. Below is the form code that is used to post the values Code: [Select] <form id="add_gallery" action="upload.php" method="post"> <table> <tr> <td>Gallery Name</td> <td><select name="category" id="category"> <option>Please select...</option> <option value="14">Superior Double Room</option><option value="15">Superior Single Room</option><option value="16">Double en-suite</option><option value="17">Twin or Triple Room, en suite</option><option value="18">Family Room for 4</option><option value="19">Single Room with Private Facilities</option><option value="20">Double Room with Private Facilities</option><option value="21">The Gallery</option></select></td> </tr> <tr> <td> Photo 1: <input name='photo_filename[]' type='file' /> </td> </tr> <tr> <td> Title: <input name='photo_caption[]' type="text" size="30"> </td> </tr><tr> <td> Photo 2: <input name='photo_filename[]' type='file' /> </td> </tr> <tr> <td> Title: <input name='photo_caption[]' type="text" size="30"> </td> </tr><tr> <td> Photo 3: <input name='photo_filename[]' type='file' /> </td> </tr> <tr> <td> Title: <input name='photo_caption[]' type="text" size="30"> </td> </tr><tr> <td> Photo 4: <input name='photo_filename[]' type='file' /> </td> </tr> <tr> <td> Title: <input name='photo_caption[]' type="text" size="30"> </td> </tr><tr> <td> Photo 5: <input name='photo_filename[]' type='file' /> </td> </tr> <tr> <td> Title: <input name='photo_caption[]' type="text" size="30"> </td> </tr><tr> <td> Photo 6: <input name='photo_filename[]' type='file' /> </td> </tr> <tr> <td> Title: <input name='photo_caption[]' type="text" size="30"> </td> </tr><tr> <td> Photo 7: <input name='photo_filename[]' type='file' /> </td> </tr> <tr> <td> Title: <input name='photo_caption[]' type="text" size="30"> </td> </tr><tr> <td> Photo 8: <input name='photo_filename[]' type='file' /> </td> </tr> <tr> <td> Title: <input name='photo_caption[]' type="text" size="30"> </td> </tr><tr> <td> Photo 9: <input name='photo_filename[]' type='file' /> </td> </tr> <tr> <td> Title: <input name='photo_caption[]' type="text" size="30"> </td> </tr><tr> <td> Photo 10: <input name='photo_filename[]' type='file' /> </td> </tr> <tr> <td> Title: <input name='photo_caption[]' type="text" size="30"> </td> </tr><tr> <td></td><td><input type="submit" name="submit" value="Upload Photos"/></td> </tr> </table> </form> I've done this before and I've never gotten this notice, why am I getting it now? <p> <center><form method = "post" action = ""> <input type = "text" name = "name"> <input type = "password" name = "pass"> <input type = "submit" name = "submit"> </form> </center> </p> '; if($_POST['submit']){ echo"blah"; } Notice: Undefined index: submit Hi all, I'm currently adding something to my website which makes the user input some information before they enter the site, but I'm getting errors saying.. Notice: Undefined index: realname in /home/a5908246/public_html/next.php on line 24 Notice: Undefined index: gamer in /home/a5908246/public_html/next.php on line 48 But with them errors its not showing the actual form where you post the info into. <?php session_start(); include ("includes/config.php"); include ("includes/functions.php"); logincheck(); ini_set ('display_errors', 1); error_reporting (E_ALL); $username = $_SESSION['username']; $get = mysql_query ("SELECT * FROM users WHERE username='$username'") or die (mysql_error()); $got = mysql_fetch_object($get); ?> <html> <head> <title>Please Update..</title> </head> <body> <form action='' method='POST' name='everything'> <?php if ($got->realname == ''){ if ($_POST['realname']){ // Line 24 $input = $_POST['nameinput']; ?> <table width='50%' border='1' class='tableborder2' cellspacing='1' align='center'> <tr> <td class='e_header' align='center'>Error!</td> </tr> <tr> <td class='omg' align='center'>Please Enter your Real Name.</td> </tr> <tr> <td align='center'><input type='text' name='nameinput' class='textinput'></td> </tr> <tr> <td align='center'><input type='button' name='realname' class='button' Value='Update Name!'></td> </tr> </table> <br /> <?php mysql_query ("UPDATE users SET realname='$input' WHERE username='$username'") or die (mysql_error()); }} ?> <?php if ($got->gamertag == ''){ if ($_POST['gamer']){ // Line 48 $inputgamer = $_POST['gamertag']; ?> <table width='50%' border='1' class='tableborder2' cellspacing='1' align='center'> <tr> <td class='e_header' align='center'>Error!</td> </tr> <tr> <td class='omg' align='center'>Please Enter your Gamertag.</td> </tr> <tr> <td align='center'><input type='text' name='gamertag' class='textinput'></td> </tr> <tr> <td align='center'><input type='button' name='gamer' class='button' Value='Update Gamertag!'></td> </tr> </table> <?php mysql_query ("UPDATE users SET gamertag='$inputgamer' WHERE username='$username'") or die (mysql_error()); }} if ($got->realname != '' || $got->gamertag != ''){ // Display, welcome $realname, redirecting you to main site now... (2 seconds waiting) ?> <table width='50%' border='1' class='tableborder2' cellspacing='1' align='center'> <tr> <td class='header' align='center'>Welcome!</td> </tr> <tr> <td class='omg' align='center'>Welcome!</td> </tr> <tr> <td align='center'>You will be redirected to the main site in 2 seconds!<meta http-equiv="refresh" content="2;url=http://******.com/index2.php"></td> </tr> </table> </form> <?php } ?> Thanks for any help/advice given Hi all, I am fairly new to php. I am learning php by a book.' I am getting an undefined index error. With the following code in dreamweaver. <?php if ($row_rsCoffee['image'] == "") { echo '<img src="images/missing_image.jpg" />'; } else { echo '<img src="images/' . $row_rsCoffee['image'] . '" />'; } ?> The line the error is at: ($row_rsCoffee['image'] == "") --> Notice: Undefined index: image in C:\wamp\www\coffee\coffeevarieties.php Can anyone help with this>? Thanks in advance. Alexander Lejuez Hi, I have a problem on my index, there is something wrong in my script but cant figure out what. This is the error code: Parse error: syntax error, unexpected '<' in /home7/esolarch/public_html/new/index.php on line 45 Here is my index.php code: Code: [Select] <?php session_start(); // Must start session first thing $toplinks = ""; if (isset($_SESSION['id'])) { // Put stored session variables into local php variable $userid = $_SESSION['id']; $username = $_SESSION['username']; $toplinks = '<a href="member_profile.php?id=' . $userid . '">' . $username . '</a> • <a href="member_account.php">Account</a> • <a href="cart.php">Cart</a> • <a href="logout.php">Log Out</a>'; } else { $toplinks = '<a href="join_form.php">Register</a> • <a href="login.php">Login</a>'; } ?> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Run a select query to get my letest 6 items // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; $dynamicList = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 6"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6"> <tr> <td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="1" /></a></td> <td width="83%" valign="top">' . $product_name . '<br /> $' . $price . '<br /> <a href="product.php?id=' . $id . '">View Product Details</a></td> </tr> </table>'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Store Home Page</title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body class="Type"> <div align="center" id="mainWrapper"> <?php include_once("template_header.php");?> <div id="pageContent"> <table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td width="28%" valign="top"><h3 class="Type"><?php echo $toplinks; ?></h3></td> <td width="72%" valign="top"><h3><br /> </h3> <p><br /> </p></td> </tr> <tr> <td valign="top"><h3> </h3></td> <td valign="top"> </td> </tr> </table> </div> <?php include_once("template_footer.php");?> </div> </body> </html> Greetings, Mitch Hi, I would like to pass the value of a form name through "rsTown" but I am getting undefined index my form: Code: [Select] <form method="post" class="textbox" action="<?php print $_SERVER["PHP_SELF"]; ?>"> City/Town: <input type="text" size="26" class="searchbox" value="" name="rsTown" id="inputString" onKeyUp="lookup(this.value);" onBlur="fill();" /> <div class="suggestionsBox" id="suggestions" style="display: none;"> <img src="images/upArrow.png" style="position: relative; top: -36px; left: 105px; z-index:1;" alt="upArrow" /> <div class="suggestionList" id="autoSuggestionsList"> </div> </div> <input type="image" src="images/go.png" height="30" with="30" value="GO" /> </form> my code on same page: Code: [Select] <? $Townsearch = $_REQUEST['rsTown']; // how many rows to show per page $rowsPerPage = 20; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } $offset = ($pageNum - 1) * $rowsPerPage; $query = "SELECT * FROM pubs WHERE rsTown LIKE '$Townsearch%' LIMIT $offset, $rowsPerPage"; $result = mysql_query($query) or die(mysql_error().'<br>SQL: ' . $query); //looping counties $query1 = "SELECT rsCounty, COUNT(PubID) AS County_Count FROM pubs GROUP BY rsCounty"; $result1 = mysql_query($query1) or die(mysql_error().'<br>SQL: ' . $query1); $county_select_options = '<option value="">Search county</option>'; while ($row = mysql_fetch_assoc($result1)) { $counties[$row['rsCounty']] = $row['County_Count']; // $county_select_options .= '<option value="display.php?PubID='.$row['id'].'">'.$row['rsCounty'].' (x'.$row['County_Count'].')</option>'."\n"; } // make this arrays not strings: $values = array(); $labels = array(); // compute the sum: $total = array_sum($counties); foreach($counties as $rsCounty=>$count){ // compute percent and add to values list: $values[] = ($count*100/$total); $labels[] = $rsCounty; } // convert array $values to a string comma separated $values = implode(',',$values); // same conversion for $labels but '|' separated $labels = implode('|', $labels); $url = 'http://chart.apis.google.com/chart?cht=p3&chd=t:'.$values.'&chs=480x200&chl='.$labels.'&chco=b0d584'; ?> <img src="<?php echo $url ?>" /> <? // start main page while($row = mysql_fetch_array($result)){ echo '<div id="pubholder" class="wrap">'; $PUBID = $row['PubID']; $RSPUBNAME = $row['rsPubName']; $RSADDRESS = $row['rsAddress']; $RSPOSTCODE = $row['rsPostCode']; $RSTEL = $row['rsTel']; $RSTOWN = $row['rsTown']; $RSCOUNTY = $row['rsCounty']; //div container of header and information echo <<<EOF <a title="$PUBID" id="$PUBID" name="$PUBID"></a> <div class="entry_header"> <div class="pubname">$RSPUBNAME</div> EOF; if ($_SESSION["RSUSER"] == "admin") { echo "<a href=\"edit.php?PUBID=$PUBID\" class=\"small\">edit this pub</a>"; } echo "</br>"; echo "</br>"; echo "<div class=\"county\">".$RSCOUNTY."</div><div class=\"town\">".$RSTOWN."</div>"; echo "</div>"; echo "</div>"; } // how many rows we have in database $query = "SELECT COUNT(*) AS numrows FROM pubs"; $result = mysql_query($query) or die('Error, query failed'); $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); // print the link to access each page $self = $_SERVER['PHP_SELF']; $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?page=$page\">$page</a> "; } } // creating 'previous' and 'next' link // plus 'first page' and 'last page' link // creating previous and next link // plus the link to go straight to // the first and last page if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; $first = " <a href=\"$self?page=1\">[First Page]</a> "; } else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } // print the page navigation link echo "<div class=\"centertext\">"; echo $first . $prev . $nav ." Showing page <strong>$pageNum</strong> of <strong>$maxPage</strong> pages " . $next . $last; echo "</div>"; ?> Also, I need my pagination sorting out if anyone can help?! take a look at my site: http://www.retroandvintage.co.uk/default.php I've tried multiple mysql tutorials thus far and some of them, have codes like this: $Page = $_GET["BLAH"]; if(!$_GET["BLAH"]) , I get an error of "Notice: Undefined Index: BLAH" in the file location and line number. Does anybody know what undefined index means and how I can patch up the problem? Thanks! want to carry over session to help page? but getting the error undefined index. Any help would be greatly appreciated! //getting my value from database table and put it into session $_SESSION["user_firstname"] = $data["Firstname"]; //decides on where the user gets re-directed to. if ($_SESSION["user_priority"] == '1') { header("Location: AdminSection.php"); } else { header("Location:LoggedIn.php"); } if ($_SESSION["user_times_loggged_in"] == '0') { header("Location:UsingTheSystem.php"); } //Help page <?php session_start(); $name = $_SESSION["user_firstname"]; echo $name; ?> any idea why its not picking up the session? Thanks i got a problem on undefined index...but if i use Xampp i can run in nicely with our error..but in wamp it say undefined index... what i supposed to do.... so that i can run it in both xampp and wamp nicely it says. Notice: Undefined index: logged in C:\wamp\www\WAR\luga\index.php on line 10 Notice: Undefined index: userlogin in C:\wamp\www\WAR\luga\index.php on line 54 Notice: Undefined index: password in C:\wamp\www\WAR\luga\index.php on line 54 wrong pawssword or username, please try againplease enter your login information to proceed with our site Code: [Select] <html> <head> <title>login page</title> </head> <body bgcolor="white" style="color:black"> <form action="index.php" method=get> <h1 align="center" style="color:black" >Welcome to this simple application</h1> <?php session_start(); if( $_SESSION["logging"]&& $_SESSION["logged"]) { print_secure_content(); } else { if(!$_SESSION["logging"]) { $_SESSION["logging"]=true; loginform(); } else if($_SESSION["logging"]) { $number_of_rows=checkpass(); if($number_of_rows==1) { $_SESSION[user]=$_GET[userlogin]; $_SESSION[logged]=true; print"<h1>you have loged in successfully</h1>"; print_secure_content(); } else{ echo "wrong pawssword or username, please try again"; loginform(); } } } function loginform() { echo "please enter your login information to proceed with our site"; echo ("<table border='2'><tr><td>username</td><td><input type='text' name='userlogin' size'20'></td></tr><tr><td>password</td><td><input type='password' name='password' size'20'></td></tr></table>"); echo "<input type='submit' >"; echo "<h3><a href='registerform.php'>register now!</a></h3>"; } function checkpass() { $servername="localhost"; $username="root"; $conn= mysql_connect($servername,$username)or die(mysql_error()); mysql_select_db("uploads",$conn); $sql="select * from users where name='$_GET[userlogin]' and password='$_GET[password]'"; $result=mysql_query($sql,$conn) or die(mysql_error()); return mysql_num_rows($result); } function print_secure_content() { echo("<b><h1>hi mr.$_SESSION[user]</h1>"); echo "<br><h2>only a logged in user can see this</h2><br><a href='logout.php'>Logout</a><br>"; } ?> </form> </body> </html> This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=357652.0 Hello i am new to php and i was wondering if someone knew how to do this. I just need a simple index.php file that lists the files and folders in a directory but i need it to look exactly like this (With Bullets): Thank You In Advance (I also need it to open the folder directory if a folder is clicked on and button for Parent Directory) |