PHP - Set Variable On Href Click?
How can I set a variable when <a href="#">Link</a> is clicked?
for example to set $variableX as integer of 1? Similar TutorialsHello I have a website that I am trying to upgrade so that all the data can be placed into a MySql database. I know what I need but I do not know if it is possible with PHP and MySql. I need to insert into a Href link a variable so that when the link is clicked it would initiate a MySql search for data. The variable would contain the Key id of the person whose name was clicked. This is very difficult to explain so a visit to the static website may help understand what I am trying to achieve, www.westonheritage.co.uk If you go to the second page by clicking the key then click on any of the surnames listed. I have the database setup on localhost and can get out the data I require. Kind regards ok so I just want to get the username into the url after the button is clicked Code: [Select] <?php $val = 123; ?> <a href="index.php>Button</a> How do I get the href to be Code: [Select] index.php?user=123 all help greatly appreciated. thanks I'm new to php and was wondering how I would be able to do the following: -I have a search page that allows someone to search for a particular user in the database -In the results, I want to have a <a href> link to another page which will run a sql query based on which user's link was clicked and list their posts. So right now I have been trying this code to build that href link: Code: [Select] echo '<td><a href="viewuser.php?username='.urlencode($row['username']).'>View user</a></td>'; However on the following page it is unable to retrieve the 'username' field. This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=308673.0 Hello Everyone, I'm using PHP with MySQL. One of the fields in the database is website. The code I'm using is as follows: variable: $web=mysql_result($result,$i,"web"); html/php code: <td><font face="Arial, Helvetica, sans-serif"><a href="<? echo "$web"; ?>">Website</a></font></td> What it should do is have the clickable word Website with the correct url from the database. Instead it's repeating the website the page is on. For example it's doing this: http://mywebsite/www.enteredwebsite.com Any help is appreciated. I have a php page that is trying to pass a variable like this: echo "<tr><td bgcolor='white'>" . $company_id . "</td><td bgcolor='white'><a href='companyusers.php?name=" . $company_name . "'>" . $company_name . "</a></td><td bgcolor='white'>" . $company_email . "</td><td bgcolor='white'>" . $company_status . "</td></tr>"; Then when some one clicks on that link they variable with it's value should go with the url and I'm trying to assign a variable like this: $company_name = $_POST['name']; It is not working!!! I get that "Notice: Undefined index: name in 'directory of page' on line 100" Can someone help please? This works: Code: [Select] form action="http://localhost/mysite/css/screen.css" method="post"> This does not work: Code: [Select] <?php $link_1 = "http://localhost/mysite/css/screen.css" ; $link_2 = '"' . "http://localhost/mysite/css/screen.css" .'"' ; ?> <form action=<?php echo $link_1;?> method="post"> <form action=<?php echo $link_2;?> method="post"> Why do neither of the PHP variables work? Thanks! I am new at php. I am trying to loop a number in each click of a button. See attached picture for reference. 1 should iterate after the click of the button and will stop to iterate when it gets to 5.
Here is my code: <!DOCTYPE html> <html> <body> <div>Question <?php $num = 5; $n = 1; $n <= $num; echo $n; ?> of <?php echo $num;?></div> <form method="post"> <button id="button" class="button" value="add" name="add">Click</button> </form> </body> </html>
If I try to loop it this way, <!DOCTYPE html> <html> <body> <div>Question <?php $num = 5; for($i = 1; $i <= $num; $i++){ echo $i; } ?> of <?php echo $num;?></div> <form method="post"> <button id="button" class="button" value="add" name="add">Click</button> </form> </body> </html> the result is Question 12345 of 5.
Hi 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 hey there peoples i have a bit of a problem with my php code. when i click on the name it wont play the video. but if i click on the thumbnail it plays here is the code Code: [Select] echo "<div class='Video_thumbnail'>"; echo "<a href='/Video.php?id={$row['id']}'>"; echo "<img src='http://i.ytimg.com/vi/{$row['link']}/hqdefault.jpg' width='220' height='170' alt='click' /></a>"; echo "<br>"; echo "</br>"; echo "<a href='/Video.php?={$row['id']}'>"; echo "{$row['navn']}</a>"; echo "</div>"; 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 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> 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> 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 } ?> 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>"; 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 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 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!! 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. |