PHP - Php Dynamic Index And Homepage
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! Similar TutorialsHi 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 I 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 Hi, I have these variables for pages I navigate to because I pass them in the query string. However, I need a variable for the homepage (index.php), before any query string is created. I cant declare a vari $_GET['intro'] ; $_GET['about'] ; $_GET['contact'] ; However, I need a variable for the homepage (index.php), before any query string is created. I cant declare a variable in index.php because it will be used throughout the entire website. I also cant declare the variable in home.php (the bulk content of the homepage) because I need to use the variable before home.php is included. Is their a trick for this? Thanks! Hello, I never really gave a serious thought to the above question until now that I'm trying to actually launch a live site. Well I'm sure most of you are familiar with this situation, where a user my enter a wrong, non existent url, whose root happens to be your domain name. For example, instead of entering domain.com/greetings, the user may wrongly type domain.com/grewtings . How can I make my site to redirect such erroneous urls to my homepage, instead of to my webhost's homepage with an error message? Appreciate all answers. This topic has been moved to Website Critique. http://www.phpfreaks.com/forums/index.php?topic=346717.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=357107.0 I Have a protected members section on my site for staff. I would like it so that information specific to that member of staff would appear on their homepage straight after login. Just basic information that is stored on a MySQL database so they can login and check appointments and clients etc for the week etc. is this something that is possible to do in PHP and MySQL? or am I going mad? At the moment I have the entire table on the members homepage and the only way I've figured out to specify a member to only show one users information is to use - (SELECT * FROM Tutors WHERE name = 'XXX'. I don't like this method as it would mean i would have to have a separate files for each member. I was hoping I could do something along the lines of - WHERE name = ' relative to the login name used'. but I am sure I am flogging a dead horse here. So many websites do this kind of thing and I'm surprised after scouring the net for hours and hours that I haven't found any useful information or tutorials on the subject. I am fairly new to programming in PHP and MySQL and am only just getting to grips with the lingo. Maybe I've just been seacrhing the wrong thing, I don't Know. Any help at all would be amazing and much appreciated, a nudge in the right direction would be a start as I'm getting nowhere on my own THANKS Folks, I need help (Php code ) to generate a Dynamic Text on a Base Image. What i want to do is, to make this Image as header on my Site and to make this Header Specific to a Site, i want to Add the Domain Name on the Lower Left of the Image. Got the Idea? Here is the Image link: Quote http://img27.imageshack.us/i/shoppingheader1.jpg/ PHP Variable that holds the Domain name is: $domain All i need the Dynamic PHP Codes that i can put on all my sites to generate this Text on Image (Header) Dynamically... May Anyone Help me with this Please? Cheers Natasha T. Hi all I need to combine these two scripts: Firstly, the following decides which out of the following list is selected based on its value in the mySQL table: <select name="pack_choice"> <option value="Meters / Pack"<?php echo (($result['pack_choice']=="Meters / Pack") ? ' selected="selected"':'') ?>>Meters / Pack (m2)</option> <option value="m3"<?php echo (($result['pack_choice']=="m3") ? ' selected="selected"':'') ?>>Meters / Pack (m3)</option> <option value="Quantity"<?php echo (($result['pack_choice']=="Quantity") ? ' selected="selected"':'') ?>>Quantity</option> </select> Although this works OK, I need it also to show dynamic values like this: select name="category"> <?php $listCategories=mysql_query("SELECT * FROM `product_categories` ORDER BY id ASC"); while($categoryReturned=mysql_fetch_array($listCategories)) { echo "<option value=\"".$categoryReturned['name']."\">".$categoryReturned['name']."</option>"; } ?> </select> I'm not sure if this is possible? Many thanks for your help. Pete I get this error on my homepage : Warning: implode() [function.implode]: Invalid arguments passed in /home/shqip1/peqini.com/wp-content/themes/sportpress/functions/wpzoom-widgets.php on line 1469 This is the code to modify http://pastebin.com/RiBsyG3c Thanks 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 ive been having an issue with this for a long time and i never found a fix from pure google so i have come to ask other human beings heres my code: Code: [Select] <a href="index.php?page=news">News</a> <?php define ('page', 'page'); switch($_GET[page]) { case "news": include "news.php"; break; case "is-it-for-me": include "for_me.php"; break; } ?> This is what shows up when first entering index.php Quote Notice: Undefined index: page in C:\xampp\htdocs\template1\index.php on line 35 Thanks in advance, Sycohazza hi all, i have made a counter as a module for my website. when i directly go to de module and start de counter i see the picure en he does his work, butt wen i call it in de index.php by include('modules/counter/counter.php') then i see een not loaded picturebox and i dont know why it doesnt works ? you can see the counter and the problem on: http://nieuw.pc-hulp-online.nl/index.php can someone help me to make it als work with include()?? thnx Hello, I am coding a new game, but rather than having links like /usersonline.php i would like to have game.php?page=usersonline I have never done this before so I'm looking for a quick heads up on the basics if possible. Thanks in advance. Brad Please explain the philosophy here..
if this is ok and generates no errors or Notices
$result = mysqli_query($connection, $query); if (!$result) { die("Database Query Failed: " . mysql_error()); } else { } while ($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>Address</td>"; echo "<td>"; echo $row['streetaddress']; echo "</td></tr>"; }Why does this code which is seemingly the same - aside from the logic test - generate an Undefined Index Notice? if (!empty($row['child1name'])) { echo "<tr>"; echo "<td colspan=\"2\">"; echo $row['child1name'] . " (" . $row['child1age'] . ")"; }and is the correct answer to decalre all of these variables in advance? thanks. im having problems with the initial loading of a page "Undefined index". i no the problem is due to 2 $vars having no value but i dont no how to get around the problem. its a form that posts to itself then pulls from the database. once you hit submit the problem goes away. i just need to sort the 1st page load out thanks the problem is the 1st 2 lines of the snippet. snippet $ser_type=$_POST['list']; $search = $_POST['search']; if ($search == '' || $search == ' '){ echo "Search Field is Empty - Please Input a Search Query!"; die; } else{ if ($ser_type=="sku"){ $sql = "SELECT * from $tbl_name WHERE sku like '%$search%' or rsku like '%$search%'"; $result = mysql_query($sql); full code <?php include("http://localhost/dsgi/includes/header.html"); ?> <!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>Modify DataBase</title> </head> <body> <form method="post" action="main.php"> <table class="tablesrch" width=583 height="101" border="0" align=center> <tr> <td height="32" colspan="2"> <div align="center">Enter Search: <input type=text name='search' size=20 maxlength=255> </div></td> </tr> <tr> <td width="193" align="right">Search By:</td> <td width="380"><label> <input name="list" type="radio" id="SKU" value="sku" checked> SKU <input name="list" type="radio" id="make" value="make"> Make <input type="radio" name="list" id="model" value="model"> Model</label></td> </tr> <td height="28" colspan="2"><div align="center"><input type=submit></div></td></tr> </table> </form> <p align="center"> </p> <table class="table2" align="center"> <tr> <td align="center"> <?php //include("http://localhost/dsgi/includes/config.php"); $INC_DIR = $_SERVER["DOCUMENT_ROOT"]. "/dsgi/includes/"; include($INC_DIR. "config.php"); // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $tbl_name="dsgi_serval"; // Retrieve data from database $ser_type=$_POST['list']; $search = $_POST['search']; if ($search == '' || $search == ' '){ echo "Search Field is Empty - Please Input a Search Query!"; die; } else{ if ($ser_type=="sku"){ $sql = "SELECT * from $tbl_name WHERE sku like '%$search%' or rsku like '%$search%'"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { echo "Image is on the server. If not green please inform imaging team"; ?> </td> </tr> </table> <table class="table1" width="800" height="72" align="center"> <tr class="tablehead"> <th width="113" align="center">Recon SKU</th> <th width="66" align="center">Orig SKU</th> <th width="90" align="center">Make</th> <th width="169" align="center">Model</th> <th width="58" align="center">Recovery</th> </span></span></tr> <?php while ($rows=mysql_fetch_array($result)){ // table bg colour $choice = strtoupper($rows['comments']); $findme = 'FAIL'; $findme1 = 'PASS'; $mystring2 = trim($rows['comments']); $pos2 = stripos($mystring2, $findme); $pos1 = stripos($mystring2, $findme1); if ($pos1 !== false){ $bgc = "pass" ; } elseif ($pos2 !== false){ $bgc = "fail" ; }else{ $bgc = "wait" ; } ?> <tr id="tabledata" class="<?php echo "$bgc"; ?>"> <td> <?php echo $rows['sku'] ; ?></td> <td> <?php echo $rows['rsku']; ?></td> <td> <?php echo $rows['make']; ?></td> <td> <?php echo $rows['model']; ?></td> <td> <?php echo $rows['recovery']; ?></td> </tr> <?php } } else { $sql = "SELECT * from dsgi_request WHERE sku = '$search'"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { while ($rows=mysql_fetch_array($result)){ ?> Image not found on server. <br> please Inform Engineering Team. <?php } ?> <?php }else{ ?> Image not found on server.<br> please Inform Engineering Team. </table> <table width="350" border="1" align="center" cellpadding="0" cellspacing="1"> <tr> <td><form name="form1" method="post" action="request_ac.php"> <table width="100%" border="1" cellspacing="1" cellpadding="3"> <tr> <th colspan="3" > Image Request </th> </tr> <tr> <td>SKU</td> <td>:</td> <td><input name="sku" type="text" id="sku" size="30" maxlength="6" /></td> </tr> <tr> <td width="97">Make</td> <td width="3">:</td> <td width="222"><input name="make" type="text" id="make" size="30"></td> </tr> <tr> <td>Model</td> <td>:</td> <td><input name="model" type="text" id="model" size="30"></td> </tr> <tr> <td>OS</td> <td>:</td> <td><input name="os" type="text" id="os" value="Which Version? Home, Basic?" size="30" /></td> </tr> <tr> <td>Serial</td> <td>:</td> <td><input name="serial" type="text" id="serial" size="30" /></td> </tr> <tr> <td>Bcn</td> <td>:</td> <td><input name="bcn" type="text" id="bcn" size="30" /></td> </tr> <tr> <td>Cell</td> <td>:</td> <td><label> <select name="personel" id="personel"> <option selected="selected">Laptop Cell</option> <option>Cell A</option> <option>Cell B</option> <option>Cell C</option> <option>Desk Top's</option> </select> </label></td> </tr> <tr> <td>Date</td> <td>:</td> <td><input name="date" type="text" id="date" value="<?php echo date("d, M, Y - h:i:s"); ?>" size="30" readonly="readonly" /></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form> </td> </tr> </table> <?Php } } } else{ $sql = "SELECT * from $tbl_name WHERE $ser_type like '%$search%'"; $result = mysql_query($sql); $srch = strtoupper($search); $sertype = strtoupper($ser_type); // echo "$sertype Search Result's For $srch"; echo "Searched $sertype For $srch"; ?> </td> </tr> </table> <table class="table1" width="800" height="72" align="center"> <tr class="tablehead"> <td>Recon SKU</td> <td>Orig SKU</td> <td>Make</td> <td>Model</td> <td>Recovery</td> </tr> <?php while ($rows=mysql_fetch_array($result)){ // table bg colour $choice = strtoupper($rows['comments']); $findme = 'FAIL'; $findme1 = 'PASS'; $mystring2 = trim($rows['comments']); $pos2 = stripos($mystring2, $findme); $pos1 = stripos($mystring2, $findme1); if ($pos1 !== false){ $bgc = "pass" ; } elseif ($pos2 !== false){ $bgc = "fail" ; }else{ $bgc = "wait" ; } // $bgc = "#EE2C2C" ;red // $bgc = "#FF6600" ; amber ?> <?php $make = strtoupper($rows['make']); ?> <tr id="tabledata" class="<?php echo "$bgc"; ?>"> <td> <?php echo $rows['sku'] ; ?></td> <td> <?php echo $rows['rsku']; ?></td> <td> <?php echo $make; ?></td> <td> <?php echo $rows['model']; ?></td> <td> <?php echo $rows['recovery']; ?></td> </tr> <?php } } } ?> <p> </p> </body> </html> hi guys, I have a form which allows me to update my database with the inputted values, the form works and it updates my database, however I have these error messages all over my webpage Notice: Undefined index: title in C:\xampp\htdocs\CS2410\add_dvd.php on line 12 Notice: Undefined index: category in C:\xampp\htdocs\CS2410\add_dvd.php on line 13 Notice: Undefined index: quantity in C:\xampp\htdocs\CS2410\add_dvd.php on line 14 Notice: Undefined index: price in C:\xampp\htdocs\CS2410\add_dvd.php on line 15 Notice: Undefined index: bar_code in C:\xampp\htdocs\CS2410\add_dvd.php on line 16 the code is below Code: [Select] <?php session_start(); // a security measure, if unautherised users attempt to directly access the page they are redirected to the index page if (!($_SESSION['autherised']== true)) { header("Location:index.php"); } //make a connection to the server or terminate the script if a connection cannot be estabilshed $svc = @mysql_connect("localhost","root") or die ('unable to connect to server'.' '.mysql_error()); //make a connection to the databaes or terminate the script if a connection cannot be estabilshed $dbc = @mysql_select_db("aston_shopdb",$svc) or die ('unable to connect to database'.' '.mysql_error()); $nameofdvd = $_POST['title']; $categoryofdvd = $_POST['category']; $quantity = $_POST['quantity']; $dvdprice = $_POST['price']; $bar_id = $_POST['bar_code']; $sql = "INSERT INTO item SET Title='$nameofdvd', Category='$categoryofdvd', Quantity='$quantity', Price='$dvdprice', Bar_code='$bar_id'"; if (@mysql_query($sql)) { echo('<p>New DVD added</p>'); } else { echo('<p>Error adding new dvd: ' . mysql_error() . '</p>'); } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" type="text/css" href="aston-shop-scheme.css" /> <title>Add a New DVD</title> </head> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <p>Enter the new DVD:<br /> Title: <input type="text" name="title" size="20" maxlength="255" /><br /> Category: <input type="text" name="category" size="20" maxlength="255" /><br /> Quantity: <input type="text" name="quantity" size="20" maxlength="255" /><br /> Price: <input type="text" name="price" size="20" maxlength="255" /><br /> Barcode: <input type="text" name="bar_code" size="20" maxlength="255" /><br /> <input type="submit" name="submit" value="SUBMIT" /></p> </form> <table class ="standard" > <tr> <td> <input type ="button" class="input" onClick ="location.href='all_products.php'" value ="View all products"> </td> </tr> <tr> <td> <input type ="button" onclick ="location.href='Logout.php'" value ="Log out"> <td> </tr> </table> </body> </html> please help!!! nick MOD EDIT: code tags added. |