Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to create a Hyperlink using MYSQL data to be passed into a url

Posted on 2011-03-09
4
Medium Priority
?
446 Views
Last Modified: 2012-05-11
Hi Experts,

What im trying to do is

Make some data from mysql into a hyperlink so when the hyperlink is pressed sends the hyperlink for example "0777777777" into the array and would then direct onto the next page.

so the url once the link is clicked would be something like

http://localhost/billing.php?val=07777777777
how would i make the 077777777 retrieved from the database into a link which sets as a variable?
this is what ive got so far. see attached

Many thanks for your help


<?php 
error_reporting(E_ALL);
include 'myphp.php';
$val = $_GET['val'];
$sql = "SELECT * FROM customer_details WHERE customer_name = '" . $val . "'";
$result = mysql_query($sql) or die(mysql_error() . " IN $sql"); 
$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{
   echo"<table>";
   echo "<tr><td>Customer:</td><td>".$row['customer_name']."</td></tr>";
   echo "<tr><td>Mobile Number:</td><td>".$row['mobile_number']."</td></tr>";
   echo"</table>";
}
   ?>

Open in new window

0
Comment
Question by:NeoAshura
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35082580
Try this:

<?php
error_reporting(E_ALL);
include 'myphp.php';
$val = $_GET['val'];
$sql = "SELECT * FROM customer_details WHERE customer_name = '" . $val . "'";
$result = mysql_query($sql) or die(mysql_error() . " IN $sql");
$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{
   echo"<table>";
   echo "<tr><td>Customer:</td><td>".$row['customer_name']."</td></tr>";
   echo "<tr><td>Mobile Number:</td><td><a href=\"billing.php?val=".$row['mobile_number'].">".$row['mobile_number']."</a></td></tr>";
   echo"</table>";
}
   ?>
0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 2000 total points
ID: 35082597
I think I missed one \"

echo "<tr><td>Mobile Number:</td><td><a href=\"billing.php?val=".$row['mobile_number']."\">".$row['mobile_number']."</a></td></tr>";
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35082679
again you are a legend, 10/10
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35082700
Thanks
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question