Solved

PHP DROP DOWN WITH MYSQL PROBLEMS

Posted on 2011-03-09
11
296 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
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…

914 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

15 Experts available now in Live!

Get 1:1 Help Now