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

x
?
Solved

PHP DROP DOWN WITH MYSQL PROBLEMS

Posted on 2011-03-09
11
Medium Priority
?
325 Views
Last Modified: 2012-05-11
HI Experts,

Im having a problem with my drop down box and it passing the variable to the url and retrieveing the data from the database.

please code someone please take a look at the code and advise me where im gonig wrong, The code exectutes but returns a blank page. when it should return the following...

Customer: Mrs Anna Norris
Mobile Number: 07777777777

many thanks for your time it is greatly appricated.

I know it is blank because the variable is not being passed.. ive included the code snippets i appricate everyones time here. so any contribution is much appricated.

ALSO PLEASE READ

if possible could someone help me format the outcome into a table with the stuructre of the following.

Customer:               Mobile Number:
MRS ANNA             07777777777
MR  BOB                 0789654178

Many thanks again.


////////// THIS IS MY DROP DOWN BOX ////////////

 <?php
error_reporting(E_ALL);
include 'myphp.php';
?>
<select id="ddlCompanies">
<?php
$sql = "SELECT customer_name FROM customer ORDER BY title";
$rs = mysql_query($sql);
echo $sql;
while($row = mysql_fetch_array($rs)) {
   echo ("<option>" . $row['customer_name'] . "</option>");
}
?>
</select>
<br />
<input type="button" onclick="var val = document.getElementById('ddlCompanies').options[document.getElementById('ddlCompanies').selectedIndex].value; var url = 'companyInfo.php?val=';url+=val;window.location=url;" value="Submit..." />

///////THIS IS PAGE IT DIRECTS TOO ////////////// 

<?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('Customer: ' . $row['customer_name']);
   echo('Mobile Number: ' . $row['mobile_number']);
}
   ?>

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
  • 6
  • 5
11 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35082252
Try with some simple select options

    echo "<option>John</option>";
    echo "<option>George</option>";
    echo "<option>Tom</option>";
    echo "<option>Jerry</option>";
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35082268
Hi roads i used the following code still nothing happend

Nothing was passed into the url

when you manually type it into the url it works fine
<?php
error_reporting(E_ALL);
include 'myphp.php';
?>
<select id="ddlCompanies">
<?php
$sql = "SELECT customer_name FROM customer ORDER BY title";
$rs = mysql_query($sql);
echo $sql;
while($row = mysql_fetch_array($rs)) {
	echo "<option>MRS ANNA NORRIS</option>";
    echo "<option>George</option>";
    echo "<option>Tom</option>";
    echo "<option>Jerry</option>";
  // echo ("<option>" . $row['customer_name'] . "</option>");
}
?>
</select>
<br />
<input type="button" onclick="var val = document.getElementById('ddlCompanies').options[document.getElementById('ddlCompanies').selectedIndex].value; var url = 'companyInfo.php?val=';url+=val;window.location=url;" value="Submit..." />

Open in new window

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35082281
Try with this syntax:

echo "<option value=".$row['customer_name'].">" . $row['customer_name'] . "</option>";
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35082293
Check if this alerts the good target address:

<?php
error_reporting(E_ALL);
//include 'myphp.php';
?>
<select id="ddlCompanies">
<?php
//$sql = "SELECT customer_name FROM customer ORDER BY title";
//$rs = mysql_query($sql);
//echo $sql;
//while($row = mysql_fetch_array($rs)) 
{
	echo "<option>MRS ANNA NORRIS</option>";
    echo "<option>George</option>";
    echo "<option>Tom</option>";
    echo "<option>Jerry</option>";
  // echo ("<option>" . $row['customer_name'] . "</option>");
}
?>
</select>
<br />
<input type="button" onclick="var val = document.getElementById('ddlCompanies').options[document.getElementById('ddlCompanies').selectedIndex].value; var url = 'companyInfo.php?val=';url+=val; alert(url); window.location=url;" value="Submit..." />

Open in new window

0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35082303
Also,... why not using a simple <form> ? there you can POST variable instead of GET.
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35082367
the pop up message from the webpage is my link but with an empty value.

im doing it this way because i need it to retrieve the data from the database and use it to populate the drop down.. once the drop down has been selected for it to re-direct to the new page.

thnx
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35082378
jus did this one

echo "<option value=".$row['customer_name'].">" . $row['customer_name'] . "</option>";


and it passed MRS of MRS ANNA NORRIS into the url anyway of getting the whole thing in there?

thnx for help
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35082401
Use

echo "<option value=\"".$row['customer_name']."\">" . $row['customer_name'] . "</option>";
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35082415
works thanks alot i appricate your help..

any ideas on how to get this ouput into a table like metioned above of.

Customer                             Mobile Number
MRS ANNA NORRIS           077777777777

et??
0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 2000 total points
ID: 35082435
I guess 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>".$row[mobile_number]."</td></tr>";
   echo"</table>";
}
   ?>

Open in new window

0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35082499
You sir are a legend, Ill close this questions seems as tho you have answerd two but looks out for my question on how to make the number into a variable/link to be clicked and be passed into the url again. it will be labelled

" Create HyperLink using MySQL data"
0

Featured Post

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

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