Solved

PHP DROP DOWN WITH MYSQL PROBLEMS

Posted on 2011-03-09
11
316 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

630 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