PHP - Trying To Modify A Search To Use Mysqli Help
Hi,
I'm trying to modify a search code but I'm not able to get any results and I'm not getting any errors.
The page is supposed to allow the user to search by one or multiple fields and return the according results.
The code was originally using the depreciated MySQL and I was trying to modify to MYSQLI.
I'm not sure that I'm using it correctly.
I have attached the files. If anyone can look at it and possibly correct it I'd greatly appreciate it.
Attached Files:
index.html - User Search Page
search.php - Search Code
Users.txt - Data I've been using (rename to csv).
I'm using WAMP.
Thanks,
Mitka
Attached Files
index.html 521bytes
3 downloads
search.php 1.53KB
4 downloads
Users.txt 916bytes
0 downloads
Similar Tutorials
I have a website I am attempting to display searchable results in 25-row pages. The database has over 30k rows in it. All text nothing fancy, 3 columns, ID Title and Artist. Basically a songlist. With “The Code That Works”, when I load index.php, I get ALL 30k+ rows displayed, even with the limits defined. With the code that doesn’t work, I can’t get the search function to populate results. Here’s a copy of recent errors in error.log with “The Code That Works” [31-Dec-2019 22:36:11 UTC] PHP Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/musicso1/karaoke.musicsoundlife.com/index.php on line 31 [31-Dec-2019 22:36:11 UTC] PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/musicso1/karaoke.musicsoundlife.com/index.php on line 31 [31-Dec-2019 22:36:11 UTC] PHP Warning: Use of undefined constant num - assumed 'num' (this will throw an Error in a future version of PHP) in /home/musicso1/karaoke.musicsoundlife.com/index.php on line 32 [31-Dec-2019 22:36:11 UTC] PHP Notice: Undefined index: page in /home/musicso1/karaoke.musicsoundlife.com/index.php on line 37 Here’s the code that works: <?php $localhost = ""; $username = "rsearch"; $password = ""; $dbname = "ke"; $con = new mysqli($localhost, $username, $password, $dbname); if( $con->connect_error){ die('Error: Connection' . $con->connect_error); } $sql = "SELECT * FROM `TABLE 1`"; if( isset($_GET['search']) ){ $name = mysqli_real_escape_string($con, htmlspecialchars($_GET['search'])); $sql = "SELECT * FROM `TABLE 1` WHERE (`Title` LIKE '%$name%') OR (`Artist` LIKE '%$name%') LIMIT 25"; } $result = $con->query($sql) or die('Could Not Search Database' . $con->error); ?> <!DOCTYPE HTML> <html> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="title" content="Catalog"> <meta name="description" content=""> <meta name="keywords" content=""> <meta name="robots" content="index, follow"> <meta name="language" content="English"> <meta name="revisit-after" content="15 days"> <meta name="author" content=""> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <link rel="stylesheet" href="main.css" /> <link rel="stylesheet" href="bootstrap.min.css"> <noscript><link rel="stylesheet" href="noscript.css" /></noscript> <script type="text/javascript"> function mousehandler(e) { var myevent = (isNS) ? e : event; var eventbutton = (isNS) ? myevent.which : myevent.button; if ((eventbutton == 2) || (eventbutton == 3)) return false; } document.oncontextmenu = mischandler; document.onmousedown = mousehandler; document.onmouseup = mousehandler; function disableCtrlKeyCombination(e) { var forbiddenKeys = new Array("a", "s", "c", "x", "u"); var key; var isCtrl; if (window.event) { key = window.event.keyCode; //IE if (window.event.ctrlKey) isCtrl = true; else isCtrl = false; } else { key = e.which; //firefox if (e.ctrlKey) isCtrl = true; else isCtrl = false; } if (isCtrl) { for (i = 0; i < forbiddenKeys.length; i++) { //case-insensitive comparation if (forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase()) { return false; } } } return true; } </script> </head> <body oncontextmenu="return false" class="is-preload"> <div id="wrapper"> <nav id="nav"></nav> <div id="main"> <article id="contact" class="panel"> <header> <h2>Search Catalog</h2> <p>Updated as of 12/31/2019</p> </header> <div class="row"> <div class="container"> <form action="" method="GET"> <input type="text" placeholder="Search by Song Title or Artist" name="search"> <input type="submit" value="Search" name="btn" class="btn btn-sm btn-primary"> </form> <hr /> <h2>Search Results</h2> <table class="table table-striped table-bordered"> <tr> <th style='width:50px;'><strong>Title</strong></th> <th style='width:150px;'><strong>Artist</strong></th> </tr> <?php while($row = $result->fetch_assoc()){ ?> <tr> <th><?php echo $row['Title']; ?></th> <th><?php echo $row['Artist']; ?></th> </tr> <?php } ?> </table> <table class="table table-striped table-bordered"> <thead> <h2> Catalog</h2> </thead> <tbody> <?php if (isset($_GET['page_no']) && $_GET['page_no']!="") { $page_no = $_GET['page_no']; } else { $page_no = 1; } $total_records_per_page = 15; $offset = ($page_no-1) * $total_records_per_page; $previous_page = $page_no - 1; $next_page = $page_no + 1; $adjacents = "2"; $result_count = mysqli_query($con,"SELECT COUNT(*) As total_records FROM `TABLE 1`"); $total_records = mysqli_fetch_array($result_count); $total_records = $total_records['total_records']; $total_no_of_pages = ceil($total_records / $total_records_per_page); $second_last = $total_no_of_pages - 1; // total page minus 1 $result = mysqli_query($con,"SELECT * FROM `TABLE 1` LIMIT $offset, $total_records_per_page"); while($row = mysqli_fetch_array($result)){ echo "<tr> <th>".$row['Title']."</th> <th>".$row['Artist']."</th> </tr>"; } mysqli_close($con); ?> </tbody> </table> <div style='padding: 10px 20px 0px; border-top: dotted 1px #CCC;'> <strong>Page <?php echo $page_no." of ".$total_no_of_pages; ?></strong> </div> <ul class="pagination"> <?php // if($page_no > 1){ echo "<li><a href='?page_no=1'>First Page</a></li>"; } ?> <li <?php if($page_no <= 1){ echo "class='disabled'"; } ?>> <a <?php if($page_no > 1){ echo "href='?page_no=$previous_page'"; } ?>>Previous</a> <?php if($page_no >= $total_no_of_pages){ echo "class='disabled'"; } ?> <a <?php if($page_no < $total_no_of_pages) { echo "href='?page_no=$next_page'"; } ?>>Next</a> <?php if($page_no < $total_no_of_pages){ echo "<a href='?page_no=$total_no_of_pages'>Last ››</a>"; } ?> </li> </ul> <form action="mail.php" method="post"> <div id="Request"> <div class="row"> <div class="col-12-medium"> <input type="text" name="name" placeholder="Enter Your Name" /> </div> <div class="col-12-medium"> <input type="text" name="title" placeholder="Enter Song Title(s)" /> </div> <div class="col-12-medium"> <input type="text" name="artist" placeholder="Enter Artist Name(s)" /> </div> <div class="col-12-medium"> <input type="text" name="key" placeholder="Key Changes? +/-, 1-8" /> </div> <div class="col-12-medium"> <input type="submit" value="Send Message" ><input type="reset" value="Clear All" /> </div> </div> </div> </form> </div> </div> </article> </div> <div id="footer"> <ul class="copyright"> <li>© SLE Inc.</li><li>Design: <a href="">SLE</a></li><li>License<a href="License.txt">.txt</a></li> </ul> < nav id="nav"> </nav> </div> </div> </body> </html> This is the code I am trying to use to add pagination into my result set also, however, for some reason it consistently rells me that $result isn’t defined or that Mysqli_fetch_arrays are not defined, when I feel like they are but maybe Im just missing it again? <?php $localhost = ""; $username = "rsearch"; $password = ""; $dbname = "ke"; $con = new mysqli($localhost, $username, $password, $dbname); if( $con->connect_error){ die('Error: Connection' . $con->connect_error); } $tbl_name="`Table 1`"; $adjacents = 3; if( isset($_GET['search']) ){ $name = mysqli_real_escape_string($con, htmlspecialchars($_GET['search'])); $query = "SELECT COUNT(*) as num FROM $tbl_name WHERE (`Title` LIKE '%$name%') OR (`Artist` LIKE '%$name%')"; $total_pages = mysqli_fetch_array(mysqli_query($query)); $total_pages = $total_pages[num]; $targetpage = "index.php"; $limit = 25; $page = $_GET['page']; if($page) $start = ($page - 1) * $limit; else $start = 0; $sql = "SELECT `Artist` FROM $tbl_name LIMIT $start, $limit"; $result = $con->query($sql) or die('Could Not Search Database' . $con->error); if ($page == 0) $page = 1; $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total_pages/$limit); $lpm1 = $lastpage - 1; $pagination = ""; if($lastpage > 1) { $pagination .= "<div class=\"pagination\">"; if ($page > 1) $pagination.= "<a href=\"$targetpage?page=$prev\"> previous</a>"; else $pagination.= "<span class=\"disabled\"> previous</span>"; if ($lastpage < 7 + ($adjacents * 2)) { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } elseif($lastpage > 5 + ($adjacents * 2)) { if($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; $pagination.= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } else { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; $pagination.= "..."; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } } if ($page < $counter - 1) $pagination.= "<a href=\"$targetpage?page=$next\">next </a>"; else $pagination.= "<span class=\"disabled\">next </span>"; $pagination.= "</div>\n"; } } ?> <!DOCTYPE HTML> <html> <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="title" content="Catalog"> <meta name="description" content=""> <meta name="keywords" content=""> <meta name="robots" content="index, follow"> <meta name="language" content="English"> <meta name="revisit-after" content="15 days"> <meta name="author" content=""> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <link rel="stylesheet" href="main.css" /> <link rel="stylesheet" href="bootstrap.min.css"> <noscript><link rel="stylesheet" href="noscript.css" /></noscript> <script type="text/javascript"> function mousehandler(e) { var myevent = (isNS) ? e : event; var eventbutton = (isNS) ? myevent.which : myevent.button; if ((eventbutton == 2) || (eventbutton == 3)) return false; } document.oncontextmenu = mischandler; document.onmousedown = mousehandler; document.onmouseup = mousehandler; function disableCtrlKeyCombination(e) { var forbiddenKeys = new Array("a", "s", "c", "x", "u"); var key; var isCtrl; if (window.event) { key = window.event.keyCode; //IE if (window.event.ctrlKey) isCtrl = true; else isCtrl = false; } else { key = e.which; //firefox if (e.ctrlKey) isCtrl = true; else isCtrl = false; } if (isCtrl) { for (i = 0; i < forbiddenKeys.length; i++) { if (forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase()) { return false; } } } return true; } </script> </head> <body oncontextmenu="return false" class="is-preload"> <div id="wrapper"> <nav id="nav"> </nav> <div id="main"> <article id="contact" class="panel"> <header> <h2>Search Catalog</h2> <p>Updated as of 12/31/2019</p> </header> <div class="row"> <div class="container"> <form action="" method="GET"> <input type="text" placeholder="Search by Song Title or Artist" name="search"> <input type="submit" value="Search" name="btn" class="btn btn-sm btn-primary"> </form> <hr /> <h2>Search Results</h2> <table class="table table-striped table-bordered"> <tr> <th style='width:50px;'><strong>Title</strong></th> <th style='width:150px;'><strong>Artist</strong></th> </tr> <?php while($row = mysqli_fetch_array($result)){ echo "<tr> <th>".$row['Title']."</th> <th>".$row['Artist']."</th> </tr>"; ?> <?php } ?> <?=$pagination?> </table> <form action="mail.php" method="post"> <div id="Request"> <div class="row"> <div class="col-12-medium"> <input type="text" name="name" placeholder="Enter Your Name" /> </div> <div class="col-12-medium"> <input type="text" name="title" placeholder="Enter Song Title(s)" /> </div> <div class="col-12-medium"> <input type="text" name="artist" placeholder="Enter Artist Name(s)" /> </div> <div class="col-12-medium"> <input type="text" name="key" placeholder="Key Changes? +/-, 1-8" /> </div> <div class="col-12-medium"> <input type="submit" value="Send Message" ><input type="reset" value="Clear All" /> </div> </div> </div> </form> </div> </div> </article> </div> <div id="footer"> <ul class="copyright"> <li>© SLE Inc.</li><li>Design: <a href="">SLE</a></li><li>License<a href="License.txt">.txt</a></li> </ul> <nav id="nav"> </nav> </div> </div> </body> </html> Can I get a hand in figuring this out? I keep modifying those lines around but they aren’t fixing so maybe I’m just dumb? Edited January 1, 2020 by PsychoThe result pages is supposed to have pagination like google help me please
For right or wrong, I've been using XML to define my Doctrine entities. When the XML changes, my entities need to change. I've automated the process with a simple PHP script which allows me to swap some text to modify one of the auto-generated methods, add methods, etc. Kind of clunky but it works well enough. Now, I recently had the need to remove a given method in its entirety from a given class. I "could" just add the entire string which represents the method name, earlier comments, and script for the method to my parsing script to my parsing script and remove it, but would like to be a little more concise. For instance, say I have $script as follows: $script = <<<'EOT' class SomeEntityClass { //... more stuff above public function getSomething() { return $this->something; } /** * Get foos. * * @return \Doctrine\Common\Collections\Collection */ public function getFoos() { return $this->foos; } /** * Get somethingElse. * */ //... more stuff below } EOT; How would you recommend creating the function: removeFunction($script, 'getFoos') which would remove the given function along with its comments from the $script string and result with? $script = <<<'EOT' class SomeEntityClass { //... more stuff above public function getSomething() { return $this->something; } /** * Get somethingElse. * */ //... more stuff below } EOT; Assuming regex is the way to go, I was thinking of something like the following, but could use some help with the regex expression. function removeFunction($script, $method) { $method="public function $method("; //regex to remove script with which starts after pattern "{\n" OR "**/", contains $method, and is located before pattern "\n{" OR "\n /**" return $script; } Thanks Hi guys, this is my first post so be gentle I have a string of ingredients, eg 1kg of salf 20kg of sugar 15kg of something nice This is the portion / mix for 1 person, I would like to make it scalable, so for example multiple all ingredients by for two people etc. So how do I do this with PHP I am guessing a regexp to look at the string and modify each number by the multiplier Any suggestions would be great thanks guys I have tried google and came up empty I think I need to convert the string to an array then modify it? John how do I modify the date coming from the database in YYYY-MM-DD format to MM-DD-YYYY? Hi Folks, i am a bit stuck on how to proceed with the following and could use some input. I have a table with a whole bunch of zipcodes and places. A lot of the zipcodes are repeated and i would like to merge them e.g. 7 | 07677 | WOODCLIFF LAKE | New Jersey | 41.02 | -74 8 | 07677 | WESTWOOD | New Jersey | 41.02 | -74 9 | 07677 | WOODCLIFF LK | New Jersey | 41.02 | -74 What i would like to do is merge these into one line then delete the obsolete ones e.g. 7 | 07677 | WOODCLIFF LAKE | WESTWOOD, WOODCLIFF LK | New Jersey | 41.02 | -74 Obviously not all the zipcodes are duplicated, and with 70 odd thousand lines its a bit daunting to go through them manually. Any pointers would be useful. Hello All, I am trying to modify a value found in a csv file and I can't seem to figure this out. I already looked into fputcsv and cannot seem to make it work to just modify a value. I have a script now that outputs the csv into a table and displays a count for how many rows there are. I am parsing through a very large file and (for example) I want to replace all instances of the word "Norway" with "it works". Here's what I have so far: Code: [Select] <?php $filename='Test.txt'; $count=0; $c=0; echo '<table border=1>'; $file_handle = fopen($filename, "r+"); while (!feof($file_handle) ) { $parts = fgetcsv($file_handle); echo '<tr><td>'.$count.'</td>'; while($c<=3) { if($parts[$c]=='Norway') { $parts[$c]='It works'; //code to modify the csv value in the file } echo '<td>'. $parts[$c] .'</td>'; $c++; } $c=0; "</tr>"; $count++; } fclose($file_handle); echo '</table>'; ?> I have looked all over and can't find any examples of how to do this. Any help would be greatly apprecieated!!! I'm wondering how I can use the following code to capture the current url...... Code: [Select] <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } ?> <?php echo curPageURL(); ?> and then have the output modified to change the domain name and create a link. Example: before - http://website1.com/page after - http://website2.com/page I think this would be done using function modify_url, but I'm not sure how to do it, any help would be greatly appreciated. Thanks I require a page to be added to my website. This page will facilitate a refined search via Google, Bing and Yahoo search engine simultaneously , show the top 5 of each engine. Is this possible using php ? Thank's This interface was created by dissecting the photo that you see into 20 pieces, and floating them to the left within a container.
I would like to know if I could individually scale the pieces together, with the same multiplying factor after the multiplying factor has been determined from the device's screen resolution.
fix.jpg 81.35KB
0 downloads
I work on laravel app with my sql database mvc I modify some thing on html pages and then i run my app then write php artisan serve but after site run i dont see changes on html can you please help me Quote Warning: Cannot modify header information - headers already sent by (output started at /home3/nyhungry/public_html/storeprueba/storescripts/connect_to_mysql.php:2) in /home3/nyhungry/public_html/storeprueba/storeadmin/admin_login.php on line 29 What can I do to fix the error where a second header is called, needed but intervening admin_login.php Code: [Select] <?php session_start(); if (isset($_SESSION["manager"])) { header("location:index.php"); exit(); } ?> <?php if (isset($_POST["username"]) && isset($_POST["password"])) { $manager = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["username"]); // filter everything but numbers and letters $password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]); // filter everything but numbers and letters include "../storescripts/connect_to_mysql.php"; $sql = mysql_query( "SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1"); $existCount = mysql_num_rows($sql); if ($existCount == 1) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; } $_SESSION["id"] = $id; $_SESSION["manager"] = $manager; $_SESSION["password"] = $password; header("location:index.php"); exit(); } else { echo 'That information is incorrect, try again <a href="index.php">Click Here</a>'; exit(); } } ?> is the second header here like below in the code clashing? because in the connect_to_mysql.php there is no headers Code: [Select] <?php $_SESSION["id"] = $id; $_SESSION["manager"] = $manager; $_SESSION["password"] = $password; header("location:index.php"); exit(); <? Hey guys im getting the error Warning: Cannot modify header information - headers already sent by (output started at /home/kylegray/public_html/include/authenticate.php:12) in /home/kylegray/public_html/home.php on line 7 Any idea why this is coming up. I think its something to to with me setting the cookie setcookie("un", $id); but im not sure. home.php Code: [Select] <? include("include/config.php"); //$_SESSION["backpage"]=$_SERVER['PHP_SELF']; if($_SESSION["client_log"]!="true"){ session_unregister("MemberArea"); header("Location: index.php?redirect=".basename($_SERVER['PHP_SELF'])); exit(); } ?> authenticate.php Code: [Select] <?php include("include/required.php"); include("include/pagedetails.php"); include_once("include/authenticate.php"); $tblName = $tbluser; $id=$_SESSION["id"]; setcookie("un", $id); $ImgPath="$CatImage/"; $ImgPathsing="$SingUPImage/"; ?> This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=310049.0 Ok, here's what I'm trying to do. In Zend, you can modify a template title for a page within the actual template file even though the title has already been set. So, say I have this in a common header file: Code: [Select] <?php echo $title; ?> ..but I then want to maybe change that within my main template page, say my 'about' page. How would I go about that? Currently I do this: include($commonheader); include($content); include($footer); It's in the content where I want to be able to change the title in the header, should I need to. You can do this with Zend but it's beyond me how they do it. Should note, the above is for simplicity sake. I am doing this using OOP methods. Any help appreciated. Maybe ob_flush? Hey guys, I've searched on Google for this and have had no luck, and you guys have been EXTREMELY helpful with a few of my previous questions! Alright the error I get is: Warning: Cannot modify header information - headers already sent by (output started at /****/header.php:6) in /***/*login.php on line 65 Errr.. After I posted this I saw the Sticky regarding Header posts.. I read the post and cannot find where the issue is with this.. The PHP code comes before the form information, am I missing something? My login.php script is: Code: [Select] <?php include("header.php"); mysql_connect("10.6.186.84", "gilmdiniz", "Gil19471947") or die(mysql_error()); mysql_select_db("gilmdiniz") or die(mysql_error()); if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else echo "SUP";//header($hdir."files.php"); } } if (isset($_POST['submit'])) { if(!$_POST['username'] | !$_POST['pass']) die('<center>You did not fill in a required field! <br /> <a href="'.$hdir.'login.php"> Back to Login </a> </center>'); if (!get_magic_quotes_gpc()) $_POST['email'] = addslashes($_POST['email']); $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 == 0) die('<center>This username does not exist in our database, sorry. <br /> <a href="'.$hdir.'login.php"> Back to Login </a> </center>'); while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); if ($_POST['pass'] != $info['password']) die('<center>Incorrect password, please try again. <br /> <a href="'.$hdir.'login.php"> Back to Login </a> </center>'); else { $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); echo "SUP";//header($hdir."files.php"); } } } else { ?> <center> <a href="<?php echo $hdir .'index.php'; ?>"> Back to Home </a> <table border="1"> <tr><td> <center><h2>Login Information</h2></center> </td></tr> <tr><td> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td> Username: </td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td> Password: </td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> </td></tr> </table> </center> <?php } ?> and my header.php script is: Code: [Select] <?php $hdir = "http://www.ondemandagents.com/NewSite_ALPHA/"; ?> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="<?php echo $hdir .'style.css'; ?>" /> </head> <body> <table width="920" cellspacing="0" cellpadding="10" border="0" align="center"> <tr> <td class="bodyline"> <table align="center" border="0" width="635" height="121" background="<?php echo $hdir .'images/logo.png'; ?>"> <tr> <td height="69"> <table border="0" width="635" height="106"> <tr> <td width="800" height="70"> </td> <td width="600" height="70"> </td> </tr> <tr> <td width="400" height="18"> </td> <td width="600" height="18"> <a href="<?php echo $hdir .'index.php'; ?>" style="text-decoration: none"> <img src="<?php echo $hdir .'images/icon_mini_home.gif'; ?>" width="12" height="13" border="0" alt="Home" hspace="3" /> <font face="Arial" color="#FFFFFF" size="2">Home </font></a> <a href="<?php echo $hdir .'files.php'; ?>" style="text-decoration: none"> <img src="<?php echo $hdir .'images/icon_mini_files.gif'; ?>" width="12" height="13" border="0" alt="Files" hspace="3" /> <font face="Arial" color="#FFFFFF" size="2">Files </font></a> <a href="<?php echo $hdir .'admin.php'; ?>" style="text-decoration: none"> <img src="<?php echo $hdir .'images/icon_mini_login.gif'; ?>" width="12" height="13" border="0" alt="Administration" hspace="3" /> <font face="Arial" color="#FFFFFF" size="2">Administration</font></a> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> I have been using a header file in all my pages and scripts so far so that I wouldn't have to keep typing repetitive code.. Help is MUCH appreciated! Thanks in advance guys i'm having trouble working with my search bar, when i used wamp it worked but now online i keep getting this message Quote Cannot modify header information - headers already sent by (output started at...) I placed that code for the search bar above the html tags but i keep getting the error here is my coding Code: [Select] <?php mysql_connect("localhost", "user", "pass") or die(mysql_error()); if (isset($_POST['submit'])) { $search = mysql_real_escape_string($_POST['search']); $type = mysql_real_escape_string($_POST['type']); if ($type == true) { header("Location:http://www.link.com/searchresults.php?subdirectory=$search&type=$type"); } } ?> i have problem when adding a subject it got two subject that need to be selected by teacher , management sub and DBMS sub.. said Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\PhpProject3\navhead_user.php:57) in C:\xampp\htdocs\PhpProject3\teacher_add_subject.php on line 104.. when i select one of them it appear that error.. but when i select DBMS it inserted the subject but with error.. let say 1st i selecting management as the subject, it occur error but after refresh the page it appear in the list of the teacher subject then i add another subject DBMS subject and it occur error but the management subject is dissappear from the teach subject list.. but i try to add the management subject again it said it existed but not listed.. but in my database it inside there already only the data not appear..
navhead_user.php
<div class="row-fluid"> <div class="span12"> <div class="navbar navbar-fixed-top navbar-inverse"> <div class="navbar-inner"> <div class="container"> <!-- .btn-navbar is used as the toggle for collapsed navbar content --> <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a> <!-- Be sure to leave the brand out there if you want it shown --> <!-- Everything you want hidden at 940px or less, place within here --> <div class="nav-collapse collapse"> <!-- .nav, .navbar-search, .navbar-form, etc --> <i class="icon-facebook-sign icon-large" id="color_white"></i> <i class="icon-twitter icon-large" id="color_white"></i> <i class="icon-google-plus icon-large" id="color_white"></i> <i class="icon-github-alt icon-large" id="color_white"></i> <i class="icon-linkedin-sign icon-large" id="color_white"></i> <div class="pull-right"> <form class="navbar-search pull-left"> <i class="icon-search icon-large" id="color_white"></i> <input type="text" class="search-query" placeholder="Search"> </form> </div> <!-- end collapse --> </div> </div> </div> </div> <div class="hero-unit-header"> <div class="container"> <div class="row-fluid"> <div class="span12"> <div class="row-fluid"> <div class="span6"> <img src="admin/images/head.png"> </div> <div class="span6"> <div class="pull-right"> <!--- login button --> <?php $student_query=mysql_query("select * from teacher where teacher_id='$session_id'")or die(mysql_error()); $teacher_row= mysql_fetch_array($student_query); ?> <img src="admin/<?php echo $teacher_row['location']; ?>" class="img img-rounded" id="picture"> <div class="btn-group"> <button class="btn btn-success"><i class="icon-user icon-large"></i> <?php echo $user_row['firstname'] . " " . $user_row['lastname']; ?></button> <button class="btn dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="#logout" role="button" data-toggle="modal"><i class="icon-signout icon-large"></i> Logout</a></li> </ul> </div> <?php include('logout_modal.php') ?> </div> </div> </div> </div> </div> </div> </div>teacher_add_subject.php <?php include ('session.php'); ?> <?php include('header.php'); $user_query = mysql_query("select * from teacher where teacher_id='$session_id'") or die(mysql_error()); $user_row = mysql_fetch_array($user_query); ?> <body> <?php include('navhead_user.php'); ?> <div class="container"> <div class="row-fluid"> <div class="span3"> <div class="hero-unit-3"> <div class="alert-index alert-success"> <i class="icon-calendar icon-large"></i> <?php $Today = date('y:m:d'); $new = date('l, F d, Y', strtotime($Today)); echo $new; ?> </div> </div> <div class="hero-unit-1"> <ul class="nav nav-pills nav-stacked"> <li class="nav-header">Links</li> <li> <a href="teacher_home.php"><i class="icon-home icon-large"></i> Home <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a> </li> <li> <a href="teacher_class.php"><i class="icon-group icon-large"></i> Class <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> <li class="active"><a href="teacher_subject.php"><i class="icon-file-alt icon-large"></i> Subjects <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> <li><a href="students.php"><i class="icon-group icon-large"></i> Students <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> </ul> </div> </div> <div class="span9"> <a href="teacher_subject.php" class="btn btn-success"><i class="icon-arrow-left icon-large"></i> Back</a> <br> <br> <div class="alert alert-info"> <button type="button" class="close" data-dismiss="alert">×</button> <strong><i class="icon-user icon-large"></i> Add Subject</strong> </div> <div class="hero-unit-2"> <form class="form-horizontal" method="POST"> <div class="control-group"> <label class="control-label" for="inputEmail">Subject</label> <div class="controls"> <select name="subject" class="span6"> <option></option> <?php $query = mysql_query("select * from subject") or die(mysql_error()); while ($row = mysql_fetch_array($query)) { ?> <option value="<?php echo $row['subject_id']; ?>"><?php echo $row['subject_title']; ?></option> <?php } ?> </select> </div> </div> <div class="control-group"> <div class="controls"> <button type="submit" name="save_subject" class="btn btn-success"><i class="icon-plus-sign icon-large"></i> Add Subject</button> </div> <br> <?php if (isset($_POST['save_subject'])) { $subject = $_POST['subject']; $result = mysql_query("select * from teacher_suject where teacher_id='$session_id' and subject_id='$subject'") or die(mysql_error()); $count = mysql_num_rows($result); if ($count > 0) { ?> <div class="alert alert-danger">Subject <strong>Already Exist</strong></div> <?php } else { mysql_query("insert into teacher_suject (subject_id,teacher_id) values('$subject','$session_id')") or die(mysql_error()); header('location:teacher_subject.php'); } } ?> </div> </form> <!-- end slider --> </div> </div> </div> <?php include('footer.php'); ?> </div> </div> </div> </body> </html>teacher_subject.php <?php include ('session.php'); ?> <?php include('header.php'); $user_query = mysql_query("select * from teacher where teacher_id='$session_id'") or die(mysql_error()); $user_row = mysql_fetch_array($user_query); ?> <body> <?php include('navhead_user.php'); ?> <div class="container"> <div class="row-fluid"> <div class="span3"> <div class="hero-unit-3"> <div class="alert-index alert-success"> <i class="icon-calendar icon-large"></i> <?php $Today = date('y:m:d'); $new = date('l, F d, Y', strtotime($Today)); echo $new; ?> </div> </div> <div class="hero-unit-1"> <ul class="nav nav-pills nav-stacked"> <li class="nav-header">Links</li> <li> <a href="teacher_home.php"><i class="icon-home icon-large"></i> Home <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a> </li> <li> <a href="teacher_class.php"><i class="icon-group icon-large"></i> Class <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> <li class="active"><a href="teacher_subject.php"><i class="icon-file-alt icon-large"></i> Subjects <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> <li><a href="students.php"><i class="icon-group icon-large"></i> Students <div class="pull-right"> <i class="icon-double-angle-right icon-large"></i> </div> </a></li> </ul> </div> </div> <div class="span9"> <a href="teacher_add_subject.php" class="btn btn-success"><i class="icon-plus-sign icon-large"></i> Add Subject</a> <br> <br> <div class="hero-unit-3"> <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example"> <div class="alert alert-info"> <button type="button" class="close" data-dismiss="alert">×</button> <strong><i class="icon-user icon-large"></i> Subject Table</strong> </div> <thead> <tr> <th>Course Code</th> <th>Course Description</th> <th>Action</th> </tr> </thead> <tbody> <?php $teacher_subject_query = mysql_query("select * from teacher_suject where teacher_id='$session_id'") or die(mysql_error()); $teacher_row = mysql_fetch_array($teacher_subject_query); $subject_id = $teacher_row['subject_id']; $query = mysql_query("select * from subject where subject_id = '$subject_id'") or die(mysql_error()); while ($row = mysql_fetch_array($query)) { $id = $row['subject_id']; ?> <!-- script --> <script type="text/javascript"> $(document).ready(function(){ $('#d<?php echo $subject_id; ?>').tooltip('show') $('#d<?php echo $subject_id; ?>').tooltip('hide') }); </script> <!-- end script --> <!-- script --> <script type="text/javascript"> $(document).ready(function(){ $('#e<?php echo $subject_id; ?>').tooltip('show') $('#e<?php echo $subject_id; ?>').tooltip('hide') }); </script> <!-- end script --> <tr class="odd gradeX"> <td><?php echo $row['subject_code']; ?></td> <td><?php echo $row['subject_title']; ?></td> <td width="50"> <a rel="tooltip" title="Delete Subject" id="d<?php echo $subject_id; ?>" href="#id<?php echo $id; ?>" role="button" data-toggle="modal" class="btn btn-danger"><i class="icon-trash icon-large"></i> </a> </td> <!-- user delete modal --> <div id="id<?php echo $id; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-header"> </div> <div class="modal-body"> <div class="alert alert-danger">Are you Sure you Want to <strong>Delete</strong> this Subject?</div> </div> <div class="modal-footer"> <button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove icon-large"></i> Close</button> <a href="delete_teacher_course.php<?php echo '?id=' . $course_id; ?>" class="btn btn-danger"><i class="icon-trash icon-large"></i> Delete</a> </div> </div> <!-- end delete modal --> </tr> <?php } ?> </tbody> </table> <!-- end slider --> </div> </div> </div> <?php include('footer.php'); ?> </div> </div> </div> </body> </html> Edited by aquilina, 26 May 2014 - 04:43 PM. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=334372.0 |