Solved

PHP DROP DOWN WITH MYSQL PROBLEMS

Posted on 2011-03-09
11
301 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
  • 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 500 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

839 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