PHP - Echoing Variable On Link Page
Hi, I know it is probely not a regex question but I don't know the right category. I have 2 variables like $variable1 and $ variable2 which are placed in a loop now I want the $variable to be echo't in a link like <a href="http://exampe.com/$variable1"/> On this dynamicly generated page I want to output the $varible1 of this link and $variable2 while($row = mysql_fetch_assoc($result)) { echo " <tr>"; echo " <td>" . $row["variable1"] . "</td>"; echo " <td>" . $row["variable2"] . "</td>"; echo " </tr>"; Similar TutorialsI have stored some texts in the database associated with a variable name in my database ... I intend to use this in my site as global text using the variable name ... This is the code I've created in a php file, which I'm 'including' in my webpage . <div style="display:none"> <?php mysqli_select_db($xxx, $database_xxx); $query_Recordset1 = "SELECT * FROM text_declares"; $Recordset1 = mysqli_query($xxx, $query_Recordset1) or die(mysqli_error()); $row_Recordset1 = mysqli_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysqli_num_rows($Recordset1); ?> <?php do { echo '$' . $row_Recordset1['bd_variable'] . ' = "' . $row_Recordset1['bd_desc'] . '"<br>'; } while ($row_Recordset1 = mysqli_fetch_assoc($Recordset1)); echo 'Company Name =' . $company_full_name ; ?> </div> When i execute the file, this is the ouput Quote
$company_full_name = "Some Company Pvt. Ltd." not able to figure out why the $company_full_name is not showing in the echo. Many Thanks for the support . Hi, I am trying to insert a variable in the body of an email lik so: Code: [Select] $message = "Dear Administrator,\n\nthe following distributor\n\n'.$row_admin_login_RS['distributor_company_name'].'\n\nHas modified his Distributor information record.\n\"; I know it must be a syntax error...but I can't figure it out. Thanks Hi, I'm new to php and just trying to practice with some codes I have. I have a php code to delete an entry from a database, all works well but I want to try to use the 'onclick' event to prompt for confirmation. However, when I add this I end up with a blank page. Then original code was: echo('<p>' . $commenttext . '<a href="adddelete.php?deletecomment=' . $commentid . '">' . 'Delete this Comment</a></p>'); I changed it to: echo('<p>' . $commenttext . '<a href="adddelete.php?deletecomment=' . $commentid . ' onclick='return confirm('Are you SURE you want to delete this comment?')'">' . 'Delete this Comment</a></p>'); Anyone know what the problem could be, or an alternative way to get a confirmation before deleting? Thanks in advance. Hi, I'm working on a page that GETs a value that is passed in the URL. This variable echos correctly up until I try echoing it inside an if statment where it needs to be. The variable is called $siteid. Inside my if statement I have a query that runs WHERE id='$siteid' Inside this if statement it won't echo out. It is the weirdest thing. I tried to hardcode the siteid as 95, to test it, and the query updated my database as it should. However, leaving it as the variable it will not work. Any help solving this mystery that I've been banging my head over for hours would be greatly appreciated! My variable echos correctly up until the line that says: // $siteid will Echo up until here. After this point it stops working. The query I am having issues with is after the line that says: // Problem lies in this query. My SQL Table: id int(11) No userid int(11) No url varchar(2083) No credits int(11) No 0 dailyviews int(11) No 0 todayviews int(11) No 0 totalviews int(11) No active tinytext No title varchar(50) No confirmed tinytext No And my code: <?php session_start(); if (isset($_SESSION['username'])){ $loginstatus = "logout"; $username = $_SESSION['username']; include_once('inc/connect.php'); $siteid = $_GET['siteid']; $message = "messagebox"; $success = " "; $error = " "; $useridquery = "SELECT id FROM users WHERE username='$username'"; $useridresult = mysql_query($useridquery); $useridrow = mysql_fetch_assoc($useridresult); $userid = $useridrow['id']; $result1 = mysql_query("SELECT * FROM websites WHERE `id`='$siteid' && userid='$userid'"); $siterow1 = mysql_fetch_assoc($result1); $titledb = $siterow1['title']; $urldb = $siterow1['url']; $maxviewsdb = $siterow1['dailyviews']; $statusdb = $siterow1['active']; $titlenew = $_POST['title']; $urlnew = $_POST['url']; $maxviewsnew = $_POST['maxviews']; $statusnew = $_POST['status']; if($statusnew=="Active"){ $statusnew = "yes"; } else{ $statusnew = "no"; } $editnewsite = $_POST['editnewsite']; if($success!=""){ $message = ""; } else{ $message = "messagesuccess"; } // $siteid will Echo up until here. After this point it stops working. if($editnewsite){ if($titlenew){ if($urlnew){ if($maxviewsnew){ function valid_url($urlnew) { return ( ! preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $urlnew)) ? FALSE : TRUE; } if(valid_url($urlnew)){ //Check if URL is a Duplicate for current user $results = mysql_query("SELECT * FROM `websites` WHERE `userid`='$userid' AND `url`='$url'"); $rows = mysql_num_rows($results); if ($rows<=0) { $siteidnew = $siteid; // Problem lies in this query. $update = "UPDATE `websites` SET `title`='$titlenew', `url`='$urlnew', `dailyviews`='$maxviewsnew', `active`='$statusnew' WHERE `id`='$siteid' && `userid`='$userid'"; mysql_query($update); $titledb = $titlenew; $urldb = $urlnew; $maxviewsdb = $maxviewsnew; $statusdb = $statusnew; echo $titledb; echo $urldb.$maxviewsdb.$statusdb."<br>".$siteid; // PROBLEM HERE exit(); } else{ $error = "You have already submitted that site"; $message = "messageerror"; } } // here else { $error = "Invalid URL"; $message = "messageerror"; } } else{ $error = "Type in the Maximum Views you<br />want your site to get daily!"; $message = "messageerror"; } } else{ $error = "Type in the Url of your website!"; $message = "messageerror"; } } else{ $error = "Type in a Title for your site!"; $message = "messageerror"; } } } else{ $loginstatus = "login"; header("Location: index.php"); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="description" content="Free Piano Sheet Music - Sheet Music Haven" /> <meta name="keywords" content="Piano,Sheet,Music,Haven,Score,Piece,Top,Trade" /> <meta name="author" content="Sheet Music Haven" /> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" /> <title>Edit Sites - Sheet Music Haven</title> <link rel="stylesheet" type="text/css" href="styles/style.css" /> <link rel="stylesheet" type="text/css" href="styles/editsites.css" /> <script type="text/javascript"> function make_blank() { if(document.login.username.value =="Username"){ document.login.username.value =""; document.login.username.style.color ="#000000"; } } function make_blank1() { if(document.login.password.value =="Password"){ document.login.password.value =""; document.login.password.type ="password"; document.login.password.style.color ="#000000"; } } function undoBlank() { if(document.login.username.value == ""){ document.login.username.value ="Username"; document.login.username.style.color="#ccc"; } } function undoBlankpass() { if(document.login.password.value == ""){ document.login.password.value ="Username"; document.login.password.style.color="#cccccc"; } } function inputLimiter(e,allow) { var AllowableCharacters = ''; if (allow == 'NumbersOnly'){AllowableCharacters='1234567890';} var k; k=document.all?parseInt(e.keyCode): parseInt(e.which); if (k!=13 && k!=8 && k!=0){ if ((e.ctrlKey==false) && (e.altKey==false)) { return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1); } else { return true; } } else { return true; } } </script> </head> <body bgcolor="#343331"> <!-- Header --> <div id="header"> <div id="headerleft"></div> <div id="headermiddle"><a href="index.php"><img src="img/logo.png"></a></div> <div id="headerright"> <?php echo "<form name='login' action='inc/$loginstatus.php' method='POST'>";?> <div class="loginboxdiv" id="username"> <input type="text" class="loginbox" name="username" value="Username" onFocus="make_blank();" onBlur="undoBlank();"> </div> <div class="loginboxdiv" id="password"> <input class="loginbox" type="text" name="password" type="text" value="Password" onFocus="make_blank1();" onBlur="undoBlankpass();"> </div> <div id="login"> <?php echo "<input type='image' src='img/$loginstatus.png' alt='".ucfirst($loginstatus)."'>";?> </div> </form> <div id="register"> <a href="register.php"><img src="img/register.png"></a> </div> <div id="forgotpassword"> <a href="resetpassword.php" class="forgot">Forgot Password?</a> </div> </div> </div> <!-- Content Top --> <div id="contenttop"> <div id="links"> <table cols="7"> <tr> <td align="center" valign="middle" width="100px" height="48px"><a href="index.php"><img src="img/home.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="member.php"><img src="img/member.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="addsheet.php"><img src="img/addsheet.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="advertise.php"><img src="img/advertise1.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="faq.php"><img src="img/faq.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="terms.php"><img src="img/terms.png"></a></td> <td align="center" valign="middle" width="100px" height="48px"><a href="contact.php"><img src="img/contact.png"></a></td> </tr> </table> <!-- 92x30 --> </div> </div> <!-- Content Middle --> <div id="contentmiddle"> <div id="content"> <div id="headeditsites"></div> <br /> <div id="editsite"> <form action="editsites.php" method="post" name="newsite"> Title: <input type="text" name="title" value="<?php echo $titledb; ?>"><br /> Url: <input type="text" name="url" value="<?php echo $urldb; ?>"><br /> Max Views: <input type="text" maxlength="11" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" name="maxviews" value="<?php echo $maxviewsdb; ?>"><br /> <select name="status"><option value='Active' name='active'>Active</option><option value='Passive' name='passive'>Passive</option></select><br /><br /> <center><input type="submit" name="editnewsite" value="Edit Site"></center> </form> </div> </div> </div> <!-- Content Bottom --> <div id="contentbottom"> </div> </body> </html>
When I echo out my variable in the php file it works fine but when I put the variable in a table cell it doesn't echo out. am i going about this in the right way? it doesn't seem to be echoing anything Code: [Select] <?php mysql_select_db($database_uploader, $uploader); $totalHits = mysql_query("SELECT SUM(hits) AS totalHits FROM userDataTracking") or die(mysql_error()); mysql_close($con); echo $totalHits; ?> <? $array = array('eggs', 'bacon', 'football', 'baseball', 'ford', 'toyota'); $rand_index = mt_rand(0, count($array) / 2 - 1) * 2; ?> <?php echo "$array[$rand_index]"; ?><?php echo "$array[$rand_index+1]"; ?> i dunno why this doesn't work. I want to echo both values three of the pairs such as eggs bacon or football baseball I need to know how to echo multiple things on the same page. If you do understand the last line then don't read this next part. So say if had just a textbox and a submit button. I already know how to make it where they type something and they hit submit and echo's to the page. But after it echos I want to know how to make it where if they entered in another body of text it would enter on the same page right under the last echo, or the last thing they typed. So if you could help me with this or just post a code for me that would be nice. Some code from my pages ,
Page1 ( Redirecting page )
<html> <title>login_redirect.</title> body> <form name="redirect" action="http://mysite/page2.php" method="post"> <input type="hidden" name="mac" value="$(mac)"> </form> <script language="JavaScript"> <!-- document.redirect.submit(); //--> </script> </body> </html>Page 2 ( select product ) <?php session_start(); ini_set('display_errors',1); error_reporting(E_ALL); include '../lib/config.php'; include '../lib/opendb.php'; // get user mac adres from redirect post page1 $_SESSION['macid'] = $_POST['mac']; // set $macid for other use ( maybe not needed, am learning ) $macid = $_SESSION['macid']; // echo $macid does show mac adress, so variable is not empty here if (!empty($_POST["submit"])) { $product_choice = $_POST['accounttype']; $query= "SELECT AccountIndex, AccountCost, AccountName FROM AccountTypes WHERE AccountIndex='$product_choice'"; $result = mysql_query($query) or die('Query failed. ' . mysql_error()); while($row = mysql_fetch_array($result)) { $_SESSION['AccountIndex'] = $row['AccountIndex']; $_SESSION['AccountCost'] = $row['AccountCost']; $_SESSION['AccountName'] = $row['AccountName']; } header('Location: page3.php'); } // did leave out the other/html/form stuff herePage 3 ( show Session variables ) <?php ini_set('display_errors',1); error_reporting(E_ALL); session_start(); print_r($_SESSION); ?>Now, on page 3 i do see the right session varables, only the "macid" is empty. why ? Hello.
I have a bit of a problem. When I fetch the link field from the database.i don't see an actual link on the page.
One more thing, what type of field should I use to store the link in the database? Probably there is where I went wrong.
All help is
Hy, How can I put a link to a variable without doing like: Code: [Select] <a href='#'>$var</a> I heard that can be other ways. Thanks Hi. I have a sort of security script which checks a few things, how can i save the url of the link that was clicked, so i can pass it through the script then if all is good, continue on to the url, if not send them somewhere else let me try to explain better with a little text picture user clicks link ----------------------> link goes to my security script --------------------> if the check passes, continue to original links url so basically i just need to know how to save the links url as a variable trying to post a link to the database Code: [Select] $amessage ="<a href="link.php">this is a link </a>"; then return that link later on another page. I have this link "https://localhost/what/index.php?album=parent%2Fsubalbum&image=1coffee.jpg" Am trying to insert a variable(eid=86) so that it comes before all other variables to read thus "https://localhost/what/index.php?eid=86&album=parent%2Fsubalbum&image=1coffee.jpg" Regards Hi guys, I want to find the most efficient way of setting a php variable through a link.
What I'm trying to achieve is to allow the user to select a category and their location and store the two variables to update my database results. I first used the GET method, but since the page refreshes when the user selects any other Get variable, so it ends up reseting the variables. Currently I have the category and locations as drop down menu with links to each of the options. I'll appreciate any help. Thank you. :]
I have a page that lists out some basic information about each quiz this particular student has taken (call it "quiz summary"). I am creating another page that will have all details of a particular quiz by itself (call it "quiz detail"). If I have a link for each quiz on the "quiz summary" page, how do I tell the "quiz detail' page which link they clicked on? Or which quiz they have selected. I was thinking it would work if I assigned a session variable to each link and then the "quiz detail" page could verify which returns true still and show details for that quiz. Would this logic work? Npot sure how to do it anyone though. thanks for any help! ive done a page that works fine but id like to add links to the results so i can view the models. working page here http://sts.hostei.com/dsgi/list_records.php in the make column i want a link that will only show the make clicked. if this was a fixed page i no how to do it but i cannot figure out to make it from the way ive discribed. i know i have to alter this line <td><div align="center"><?php echo $rows['make']; php?></div></td> but no idea how to do this. do i create a new page for the query? if so how do i pass the $var? is it possable to do this from the same page? ie appear undr the main table. Thanks <?php include("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"); $sql = "SELECT make, COUNT(*) AS total, SUM(IF(comments = \'pass\', 1, 0)) AS withComments FROM dsgi_serval GROUP BY make ORDER BY COUNT(*) DESC"; $result=mysql_query($sql); php?> <table width="319" border="1"><tr> <td colspan="4"><font size="4" face="Verdana"> <strong><div align="center">Validation Total's </div></strong></font> </td> </tr> <tr> <td width="137" align="center"><strong>Make</strong></td> <td width="85" align="center"><strong>Total</strong></td> <td width="75" align="center"><strong>Validated</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ php?> <tr> <td><div align="center"><?php echo $rows['make']; php?></div></td> <td><div align="center"><?php echo $rows['total']; php?></div></td> <td><div align="center"><?php echo $rows['withComments']; php?></div></td> </tr> <?php } php?> <tr> <td><div align="center">Totals</div></td> <td> <div align="center"> <?php // counts all rows $query = "SELECT make, COUNT(make) FROM dsgi_serval "; $result1 = mysql_query($query) or die(mysql_error()); // Print out result while($row1 = mysql_fetch_array($result1)){ echo $row1['COUNT(make)']; } ?> </div></td> <td><div align="center"> <?php // counts passes $query = "SELECT make, COUNT(make) FROM dsgi_serval where comments like 'pass'"; $result2 = mysql_query($query) or die(mysql_error()); while($row2 = mysql_fetch_array($result2)){ echo $row2['COUNT(make)']; } ?> </div></td> </tr> </table> <?php mysql_close(); php?> I have to put a link that can be clicked around the first name and last name variables in the echo statement below. I also need to add a variable from the Select query to the link such as: 'www.phpfreaks.com/admin/customers.php?page=1&cID="VARIABLE HERE" &action=edit' I've tried a bunch of things and none seem to work. while($row = mysql_fetch_array($result)){ echo '<tr><td>' . $row['customers_firstname'] . " " . $row['customers_lastname'] . '</td><td>' . date("M. d, Y", strtotime($row['date'])) . '</td><td>' . $row['plan_id'] . '</td></tr>'; David Hello all! I am somewhat new to PHP and SQL, but I think I have a basic understanding of how the language works. I have read through a million different websites and forums, and have tried a million different ways but am just not getting anywhere! This is what I am trying to do... I have a text link that I want to click through to an outside URL from my website. This outside URL was already entered into an SQL database, and I just cant seem to get the text link to bring up the outside URL from the database. This is what I have so far... 1.) My webpage that I am working on is www.mywebsite.com/articles.php 2.) I want the text "Read more..." on this webpage to click through to an outside URL, like "http://www.google.com", which was already entered into an SQL database under the title of "article_link" in a new window 3.) So I would like for "Read more..." to click through the outside URL that was entered into "article_link" in the database Code: [Select] <?php echo <p><a href="\' . $article_link . '\" target="_blank">Read more...</a></p>; ?> Nothing I have tried has worked so far, nothing clicks through to the outside URL in the "article_link" entry from the database. Sorry if I am being redundant, I have been at this all day! Please help and thank you in advance!! Hey, I'm trying to save a MySQL-Link source as an instance variable in my query class. The problem is that MySQL sees it as an invalid MySQL-Link (supplied argument is not a valid MySQL-Link resource). What I'm I doing wrong? //Walle Code: [Select] private $connection; //Construct public function __construct(&$connection) { $this->connection = $connection; } //Where the error occurs public function exe_query($sql) { $result = mysql_query($sql, $this->connection); if(!$result) { throw new Exception(mysql_error()); } return $result; } |