Solved

PHP DROP DOWN WITH MYSQL PROBLEMS

Posted on 2011-03-09
11
293 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
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 …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now