PHP - Href Behaving Diffrently In Browser
Hi,
When i tried to click the a href in the page, its showing diffrently in firefox I have attached the screenshot of the page, page opening as (jpeg image) thanks Similar TutorialsHi guys; I've managed to find my way into something of a maze. <td> <a href="'Details/21/index.php'"?id= . $id .'>" . $row['id'] . "</a> </td> I'm looking at this line in the code. I realise it's currently in the wrong syntax but I'm just trying multiple different variations. At the moment I'm actually just trying to make it go to a static link but my real goal is to - get it to pick up the id number, of the id row I click, and concatenate that with the rest of my address string. Then use that as the href. Something like this: - "'Details/' + $id + '/index.php'" It's really confusing me though inside this loop and for some reason the id number is being picked up as an int, by the looks of things. It's getting above my level of understanding. Any chance one of you masters would through a n00b a lifeline?
This is my code below
<!DOCTYPE html> <html> <head> <title>LifeSaver DB</title> <h1> LifeSaver Database </h1> </head> <body> <table> <tr> <th>Id</th> <th>Location</th> <th>Initials</th> <th>TimeStamp</th> <th>Notes</th> </tr> <?php $conn = mysqli_connect("localhost", "meh", "pas", "DB"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM LifeSaver1 ORDER BY id DESC"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { //for href row $id = $row['id']; $Footage = ['Footage']; echo "<tr> <td> <a href="'Details/21/index.php'"?id= . $id .'>" . $row['id'] . "</a> </td> <td>" . $row["Location"] . "</td> <td>" . $row["Initials"]. "</td> <td>" . $row["TimeStamp"]. "</td> <td>" . $row["Notes"] . "</td> </tr>";} //show table echo "</table>"; } else { echo "0 results"; } $conn->close(); ?> </table> </body> <style> table, td, th { border: 1px solid black; margin: auto; } table { border-collapse: collapse; color: #000; <!--font colour --> font-family: monospace; font-size: 18px; text-align: center;} th { background-color: #337AFF; color: white; font-weight: bold; } tr:nth-child(odd) {background-color: #add8e6} </style> </html> Edited February 8, 2020 by JonnyDriller Hello all, Can anyone help me , the below code which creates a drop down list for a user works fine on a desktop but on a mobile seems to be random the course it selects
Thanks in advance
<?php // database connect include('../db_connect.php'); // We need to use sessions, so you should always start sessions using the below code. session_start(); // If the user is not logged in redirect to the login page... if (!isset($_SESSION['loggedin'])) { header('Location: login.php'); exit(); } // if submit button selected run code if(isset($_POST['submit'])){ $_SESSION['district'] = $_POST['district']; header('Location: add_d_choice.php'); } ?> <!DOCTYPE html> <html> <!-- Compiled and minified CSS --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"> <!-- Compiled and minified JavaScript --> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> <!--Import Google Icon Font--> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <header> <?php include('../menu.php'); ?> </header> <body bgcolor=#fafafa> <br> <br> <div class="container"> <div class="row"> <div class="card col s10 m8 l6 xl4 push-l3 push-m2 push-s1 push-xl4 z-depth-5"> <div class="card-content"> <div class="input-field col s12 m12 l12 xl12"> <form action="add_choice.php" method="POST"> <select name = "district"> <label>Select District you raced at</label> <option value="" disabled selected>Choose your district</option> <option value="Z">Zwift TT - Z</option> <option value="">--------------------</option> <option value="A">Central A</option> <option value="B">East - B</option> <option value="C">Lincolnshire - C</option> <option value="D">Liverpool - D</option> <option value="E">London East - E</option> <option value="F">London North - F</option> <option value="G">London South - G</option> <option value="H">London West - H</option> <option value="J">Manchester - J</option> <option value="K">Midland - K</option> <option value="L">North - L</option> <option value="M">North East - M</option> <option value="N">South East Midlands - N</option> <option value="O">North Midlands - O</option> <option value="P">South - P</option> <option value="Q">South East - Q</option> <option value="R">South Wales - R</option> <option value="S">South West - S</option> <option value="T">Teeside - T</option> <option value="U">West - U</option> <option value="V">Yorkshire - V</option> <option value="W">Scotland - W</option> <option value="Y">National - Y</option> </select> <input class="btn teal accent-4" type="submit" name="submit" value="Submit"> <br> <br> </form> </div> </div> </div> </div> </div> </div> <!-- Javacript --> <script src=https://code.jquery.com/jquery-3.4.1.min.js></script> <!-- Compiled and minified JavaScript --> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> <script> $(document).ready(function(){ $('.sidenav').sidenav(); $('select').formSelect(); $('.datepicker').datepicker(); $(".dropdown-trigger").dropdown(); }); </script> </body> <footer> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <?php include('../footer.php'); ?> </footer> </html>
I have the following session timeout code which should redirect users of a website to a page (session_expired.php) which prints out a message telling the user that his session has expired. I include this code at the top of every page in the website, that requires user authentication. Code: [Select] <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) { // last request was more than 30 minates ago session_destroy(); // destroy session data in storage session_unset(); // unset $_SESSION variable for the runtime header("location: session_expired.php"); } $_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp ?> The session_expired.php page which I will include below, has a login link, which takes the user to a login page (access_denied.php) Code: [Select] <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //Set the page title before the header file $title = 'Session Expired'; require ('header.php'); //need the header ?> <div id="content" class=""> <div id="left_content" class=""> </div> <!--closes left content--> <div id="right_content" class=""> <div id= "right_content_inner_border"> <h5 style ="position:relative;left:660px;top:1px;"> <a style="text-decoration:none" href="access_denied.php">[Login]</a> </h5> <h3 style ="position:relative;left:110px;top:100px; font-color:blue;"> You Session Expired Due to Inactivity! </h3> </div> <!--closes right content inner border--> </div> <!--closes right content--> </div> <!--closes content--> <?php require ('footer.php'); //need the footer ?> Now here lies the problem. When i set the session timeout to say 60 seconds to test the code, everything seems to work perfectly. The authenticated page gets redirected to session_expired.php after 1 minute and when the user clicks on the login link, he is taken back to the login page(access_denied.php). However, when I replace the time with 1800 seconds, the page notice that when I leave the page idle for JUST about 5 minutes, it gets redirected NOT even to the expected session_expired.php page but strangely, directly to the login page(access_denied.php). What could be going wrong here? Any hint is appreciated. I'd like to use an application that's not browser based, on Internet Explorer. I've read somewhere that this is possible with a PHP script, but which one? If you can get me on the right track, I'd really appreciate it. Cheers. Hi all, I have written a piece of code querying the database to display the last ten posts from different users on a forum/blog. This is displaying the titles of the posts but I am unsure how to create a link (complete novice) to read the content of those posts. I get the syntax etc but can't really get my head around the target, if you catch my drift. I have created a new php file called recentposts but am unsure of how to take it from there. The code for both is below. The first piece of code works fine but when I click read more I am getting an undefined variable message on line 11 (I'm guessing there should be a link between the two pieces of code) and I am getting mysqli_fetch_array() expects parameter 1 to be mysqli_result on line 12. Any thoughts/hints/suggestions welcome. Thanks in advance. Code: [Select] <?php $connection = @mysqli_connect('localhost','root','','BLOG_PROJECT') //Make a connection to the database or die(mysqli_connect_error("Could not connect to the server")); //If it doesn't connect give the error message $latestposts= mysqli_query($connection,"SELECT author_id, title FROM blogposts ORDER BY timeofpost DESC LIMIT 9");//Query the database while($displayposts=@mysqli_fetch_array($latestposts)){ //go and get the information echo "{$displayposts['title']}</br>"; echo "<a href='recentposts.php'>Read more</a></br>"; } ?> And the recentposts.php is Code: [Select] <?php $connection = @mysqli_connect('localhost','root','','BLOG_PROJECT') or die(mysqli_connect_error("Could not connect to the server")); $detail= mysqli_query($connection,"SELECT * FROM blogposts WHERE 'title', 'content', 'timeofpost' = $content"); while($singlepage = mysqli_fetch_array($connection,$detail)){ extract($singlepage); echo "<h2>{$singlepage['title']}</h2></br>"; echo "{$singlepage['content']}</br>"; echo "{$singlepage['timeofpost']}"; } ?> How do I post data when a user clicks a link? I know that for a submit button you just use the name attribute, but I'm not sure how to do it with a link. Hey there. Firstly may I apologise if this is the wrong forum for this question. I wasn't overly sure. I'm currently developing an aplication within php which allows a user to upload a file which is saved to a directory and information on the file which is saved to a databse (including the file name). This information is then displayed in a table along with the directory location concatinated with the file name to provide a file location. My only issue is that being new to PHP I am unsure how to change this address to a workable link using a href. Any help in adapting the below script would be much apreciated. Thanks, Rick. echo "<table border='1'><tr>"; for($fieldIterator = 1; $fieldIterator < $numFields; $fieldIterator++) { echo "<th>".mysql_field_name($result, $fieldIterator)."</th>"; } echo "</tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row[1] . "</td>"; echo "<td>" . $row[2] . "</td>"; echo "<td>" . $row['Price'] . "</td>"; echo "<td>" . $row['Genre'] . "</td>"; echo "<td>" . $row['Category'] . "</td>"; echo "<td>$ref= C:\wamp\www/.$row[ImageAddress] </td>"; echo "</tr>"; } echo "</table>"; Hi, im trying to create a link where it takes the row reference number and direct user to the revelant page, however i can get it work, this is my URL HREF can u please tell me what im doing wrong? thanks <td><?php echo $reference; ?><?php echo "a href='display.php?reference=".$row['reference']."'?>View Here</a>"</td> how to echo href id value Thanks ! Code: [Select] if (isset($_GET['edit']) && $_GET['edit'] == 'textupdate') { echo " {$_GET['id']} ! <br>" ; } <a href= \"{$_SERVER['PHP_SELF']}?edit=textupdate\" id=\"edit{$row['id']}\" >Edit</a> Hello, I have created a webpage that essentially generates an sql query and then puts the results into a table that is displayed. On one of the columns in this displayed table, I want to allow the user to click on each of the values which will in turn execute a php function. I have the hyperlink working but this is to a separate page. What I actually need to do is firstly - just ran a php function that will create a new table beneath the currently displayed one. Secondly, once this is achieved, I need to pass some value to the function so that the generated table is dependent on the value that was clicked. I've tried a few things and researched but I am struggling. I am a beginner. Any help would be greatly appreciated. Here is an extract of the code used for inputting data into the original table - showValuesSR is the function name <?php while (!$rsMetrics->EOF) { ?> <tr> <?php for ($x=0; $x<$numberOfFields; $x++) { if ($fieldNames[$x] == "Values_SR"){ ?> <td><a href= ?showValuesSR><?php echo $rsMetrics->fields[$fieldNames[$x]]->Value?></a></td> <?php } else{ ?> <td><?php echo $rsMetrics->fields[$fieldNames[$x]]->Value?></td> <?php } } ?> </tr> <?php $rsMetrics->MoveNext(); } ?> </table> <?php function showValuesSR(){ ?> <table border="0" cellpadding="5" width="100%"> <tr><td background="../images/table_toolbar_bkg.gif" align="center"><font color="Blue" face="verdana" size="2"><strong>function working</strong></td></tr> </table> <?php } ?> how can i pass more then one value via href with this kind of method echo "<a href=\"submit_docs.php?prop_id=".$prop_id."\">Click </a>"; tnx I'm using the code from Chapter 12 in Beginning PHP4 to display my data. For some reason, the hyperlinks that are suppose to sort columns do not work neither does the "View Record" function. The "Next" button also fails to load the next set of data. I also set register_global=on in the php.ini. Below is the code: Code: [Select] <?php include "./common_db.inc"; function list_records() { global $default_dbname, $user_tablename; global $default_sort_order, $default_order_by, $records_per_page; global $sort_order, $order_by, $cur_page; global $PHP_SELF; $link_id = db_connect($default_dbname); if(!$link_id) error_message(sql_error()); $query = "SELECT count(*) FROM $user_tablename"; $result = mysql_query($query); if(!$result) error_message(sql_error()); $query_data = mysql_fetch_row($result); $total_num_user = $query_data[0]; if(!$total_num_user) error_message('No User Found!'); $page_num = $cur_page + 1; $total_num_page = $last_page_num = ceil($total_num_user/$records_per_page); html_header(); echo "<CENTER><H3>$total_num_user records found. Displaying the page $page_num out of $last_page_num.</H3></CENTER>\n"; if(empty($order_by)) { $order_by_str = "ORDER BY $default_order_by"; $order_by = $default_order_by; } else $order_by_str = "ORDER BY $order_by"; if(empty($sort_order)) { $sort_order_str = $org_sort_order = $default_sort_order; $sort_order = 'DESC'; } else { $sort_order_str = $org_sort_order = $sort_order; if($sort_order == 'DESC') $sort_order = 'ASC'; else $sort_order = 'DESC'; } if(empty($cur_page)) { $cur_page = 0; } $limit_str = "LIMIT ". $cur_page * $records_per_page . ", $records_per_page"; $query = "SELECT project, route, config FROM $user_tablename $order_by_str $sort_order_str $limit_str"; $result = mysql_query($query); if(!$result) error_message(sql_error()); ?> <DIV ALIGN="CENTER"> <TABLE BORDER="1" WIDTH="90%" CELLPADDING="2"> <TR> <TH WIDTH="25%" NOWRAP> <A HREF="<?php echo "$PHP_SELF?action=list_records&sort_order=$sort_order&order_by=route"; ?>"> Route </A> </TH> <TH WIDTH="25%" NOWRAP> <A HREF="<?php echo "$PHP_SELF?action=list_records&sort_order=$sort_order&order_by=project"; ?>"> Project </A> </TH> <TH WIDTH="25%" NOWRAP> <A HREF="<?php echo "$PHP_SELF?action=list_records&sort_order=$sort_order&order_by=config"; ?>"> Config </A> </TH> <TH WIDTH="25%" NOWRAP>Action</TH> </TR> <?php while($query_data = mysql_fetch_array($result)) { $route = $query_data["route"]; $project= $query_data["project"]; $config = $query_data["config"]; echo "<TR>\n"; echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$route</TD>\n"; echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$project</TD>\n"; echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$config</TD>\n"; echo "<TD WIDTH=\"25%\" ALIGN=\"CENTER\"> <A HREF=\"javascript:open_window('$PHP_SELF?action=view_record& project=$project');\">View Record</A></TD>\n"; echo "</TR>\n"; } ?> </TABLE> </DIV> <?php echo "<BR>\n"; echo "<STRONG><CENTER>"; if($page_num > 1) { $prev_page = $cur_page - 1; echo "<A HREF=\"$PHP_SELF?action=list_records&sort_order=$org_sort_order& order_by=$order_by&cur_page=0\">[Top]</A>"; echo "<A HREF=\"$PHP_SELF?action=list_records&sort_order=$org_sort_order& order_by=$order_by&cur_page=$prev_page\">[Prev]</A> "; } if($page_num < $total_num_page) { $next_page = $cur_page + 1; $last_page = $total_num_page - 1; echo "<A HREF=\"$PHP_SELF?action=list_records&sort_order=$org_sort_order& order_by=$order_by&cur_page=$next_page\">[Next]</A> "; echo "<A HREF=\"$PHP_SELF?action=list_records&sort_order=$org_sort_order& order_by=$order_by&cur_page=$last_page\">[Bottom]</A>"; } echo "</STRONG></CENTER>"; html_footer(); } function view_record() { global $default_dbname, $user_tablename; global $project; global $PHP_SELF; if(empty($project)) error_message('Empty User ID!'); $link_id = db_connect($default_dbname); if(!$link_id) error_message(sql_error()); $query = "SELECT route, project, config, opfieldc, opfieldrd, mod FROM $user_tablename WHERE project = '$project'"; $result = mysql_query($query); if(!$result) error_message(sql_error()); $query_data = mysql_fetch_array($result); $route = $query_data["route"]; $project = $query_data["project"]; $config = $query_data["config"]; $mod = $query_data["mod"]; html_header(); echo "<CENTER><H3> Record for User No.$route - $project($config) </H3></CENTER>"; ?> </TR> </TABLE> </DIV> <?php } html_footer(); switch($action) { case "view_record"; view_record(); break; default: list_records(); break; } ?> Appreciate any insight you can offer Good day: Im trying to get the image of an article, which is stored in a folder, and href it with a page and the article id, which is the variable to be passed to the next page. I had href it but when I add the id to be passed I get an error. Here is the code: Code: [Select] <?php $connection = mysql_connect("localhost", "username", "password"); mysql_select_db("articles", $connection); $query="SELECT imagename, description, articledid FROM article_description ORDER BY visits DESC LIMIT 0,9"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table width ="1000" border="1" cellspacing="2" cellpadding="2"> </tr> <?php $j=0; $f6='articles.php'; while ($j < $num) { $f8=mysql_result($result,$j,"articleid"); $f9=mysql_result($result,$j,"imagename") ?> <td><a href="<?php echo $f6?aid=$f8; ?>"> <img src="articleimages/<?php echo $f9; ?>"alt="" name="picture" width="100" height="70" border="1" /> </a> </td> <?php $j++; } ?> Any help will be appreciated. Hi, my PHP skills are kinda weak and I've been trying to get this to work, but for some reason, the href isn't linking properly. Can anyone help me with this? Code: [Select] $titlehigh = preg_replace ( "'($var)'si" , "<strong> \1</strong>" , $row_linkcat[ 'sid' ] ); $linkhigh = preg_replace ( "'($var)'si" , "<strong> \1</strong>" , $row_linkcat[ 'title' ] ); $linkdesc = preg_replace ( "'($var)'si" , "<strong> \1</strong>" , $row_linkcat[ 'creator' ] ); $filehigh = preg_replace ( "'($var)'si" , "<strong> \1</strong>" , $row_linkcat[ 'file' ] ); $linkpic = preg_replace ( "'($var)'si" , "<strong> \1</strong>" , $row_linkcat[ 'parent' ] ); foreach($trimmed_array as $trimm){ if($trimm != 'b' ){ $titlehigh = preg_replace( "'($trimm)'si" , "<strong> \1</strong>" , $titlehigh); } //end highlight ?> <p> <center> <?php echo "<a href='http://www.wootability.com/WootStrips/newstrips.php?id='" . $linkpic . "'>$linkhigh</a>"; ?><br /> For some reason, the href is just a blank id. I'd be very appreciate if anyone could help. Thanks! Hi there! I'm trying to put 2 variables using href. Ive got it already, but when I tried to insert the page=1, which is the the variable for my paginated code.It doesn't work. When I used the codes below, from other page (I don't used variable) it works Code: [Select] <a href='module_viewpaginated.php?page=1' but when I used this code, I've got the variable $course and $program, but I don't know how to insert page for my pagination Code: [Select] <a href='module_viewpaginated.php?course=".$courseid."&program=".$program." ' I hope my problem is clear. I want to combine the two. Any help would be greatfull!! this one is form2 .php and there is action link button where im want the target to open new browser for example now m using google chrome so when im click the action link it will open another browser which is bit actually the photo is in one im dont know how to combine that why im splitted but how to target like that Howdy, I'm in trouble here. Does someone know how to wrap a url which is in the string with href tag without writing like a few hundred line long code? Example: Befo "This is a url http://www.domain.com and then some text" After: "This is a url <a href="http://www.domain.com">http://www.domain.com</a> and then some text" the string is to be received by a flash application right after. Hi guys, I'm trying to add this link <a href="<?php CONFIG_SITE_PATH ?>/settings.php"> to somewhere in the red text below. Can someone please show me how/where I would do this. $userObj->_userId = $_SESSION['G_userId'.CONFIG_SITE_NAME]; $userObj->getUserDetails(); echo '.$userObj->_name.'</span> / <a href="logout.php" >Logout</a></span>'; How can I set a variable when <a href="#">Link</a> is clicked? for example to set $variableX as integer of 1? Im fairly new to PHP and have a quick question. I am creating a mail system from scratch and I have two main SQL rows, ID and read. I need to put a link around the ID so that it only pops up in a pop up window that message. This is the coding I have so far, feel free to point out where I have gone wrong: <? include('../config/config.php'); $Query = sprintf("SELECT * FROM qa LEFT JOIN EmployeeInfo ON(qa.Agentsname = EmployeeInfo.Name) WHERE EmployeeInfo.Name LIKE '%s'", mysql_real_escape_string($_SESSION['SESS_NAME'])); $result = mysql_query($Query); $num_rows = mysql_num_rows($result); echo "<table border='0' cellspacing='10' cellpadding='10'>"; echo "<tr>"; echo "<td><strong>Message ID</strong></td><td><strong>Team Lead</strong></td><td><strong>Unread/Read</strong></td><td><strong>Score</strong></td>"; while($row = mysql_fetch_array($result)) { echo "<tr><td><a href='http://10.0.11.5/form/employees/attendance/qaview.php?id='". $row['ID'] . ">" . $row['ID'] . "</a></td><td>" . $row['Name'] . "</td><td>" . $row['read'] . "</td><td>" . $row['Score'] . "</td></tr>"; } echo "</table>"; ?> and this is the qaview.php page <? include('../config/config.php'); $query = doquery("SELECT * FROM qa WHERE ID='$ID'"); $update_query=doquery("UPDATE qa SET read='1' WHERE ID='$ID'"); $row = mysql_fetch_array($query); echo "<td><strong>" . $row['Name'] . "</strong></td></tr>"; ?> |