PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old October 20th, 2009, 12:55 PM
Naughty Naughty is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2009
Posts: 83 Naughty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 53 m 8 sec
Reputation Power: 1
Question To populate drop-down on one page and display the contents on 2nd page

Hey,

I'm trying to populate the drop-down box from db on my page1.php. So I want to populate the course part of db.

For example let's say I have a db of table called Exam. The fields are Name, phone, course etc etc.

So I populate the drop-down with course, but on submit I want to retrieve the name,phone etc etc for that particular course and display it on my page2.

How to code this part, it's kinda of confusing a bit.

PHP Code:
<?php

//Create Database connection

$connect mysql_connect("localhost""root"""); or die("Unable to connect");
$db mysql_select_db("Exam"$connect);

$options="";

$sql="SELECT course FROM Clients";
$result=mysql_query($sql);

while(
$row=mysql_fetch_array($result)) {
$course=$row["course"];
$options.="<OPTION VALUE=\"$course\">";
}
?>
<html>
<body>
<form method="post" action="page2.php">
<p>
Select Course:
<select name="course">
<OPTION VALUE=0><?=$options?>
</select>
</p>
</form>
</body>
</html>


Thanks!

Reply With Quote
  #2  
Old October 20th, 2009, 01:56 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
your drop down box looks fine. couldn't you just do a query on page2? something like "SELECT * FROM clients WHERE course='{$_POST['course']}'"

Reply With Quote
  #3  
Old October 20th, 2009, 02:26 PM
Naughty Naughty is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2009
Posts: 83 Naughty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 53 m 8 sec
Reputation Power: 1
Wont' the below code work for page2.php.

PHP Code:
<?php
$connect 
mysql_connect("localhost""root""") or die("Unable to connect");
$db mysql_select_db("Exam"$connect);

$sql="SELECT * FROM Clients WHERE course='{$_POST['course']}'";
$result=mysql_query($sql); 

echo 
$result;
?>

Reply With Quote
  #4  
Old October 20th, 2009, 02:40 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
$result will just show [object] if you echo it. you have to loop through $result and echo out all the data.

Reply With Quote
  #5  
Old October 21st, 2009, 09:59 AM
Naughty Naughty is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2009
Posts: 83 Naughty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 53 m 8 sec
Reputation Power: 1
Hope now the code is right.
PHP Code:
<?php
$connect 
mysql_connect("localhost""root"""); or die("Unable to connect");
$db mysql_select_db("Exam"$connect);

$sql="SELECT * FROM Clients WHERE course='{$_POST['course']}'";
$result=mysql_query($sql); 

while (
$row mysql_fetch_array($result)){
echo 
$row['name'];
echo 
$row['phone'];
echo 
$row['address'];
}
?>

Reply With Quote
  #6  
Old October 21st, 2009, 12:40 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
did you try to run it? thats much faster than posting here and waiting a few hours for someone to reply.

Reply With Quote
  #7  
Old October 23rd, 2009, 12:18 PM
Naughty Naughty is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2009
Posts: 83 Naughty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 53 m 8 sec
Reputation Power: 1
PHP Code:
<?php
$connect 
mysql_connect("SQL server""username""password") or die("Unable to connect");
$db mysql_select_db("Clients"$connect);
$options "";

$sql "SELECT * FROM Course_list WHERE enrl_StartDate > getdate() ORDER BY courseID";
$result mysql_query($sql);

while(
$row mysql_fetch_array($result)){
$course $row["Course_list"];
$options .="<OPTION VALUE=\"$course\">";
}
?>


Code:
Select the course:&nbsp;&nbsp;<input type="radio" name="group1">&nbsp;&nbsp;<select name="course">
<OPTION VALUE=0><?=$options?>
</select>


The error on my web browser:

Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'SQL server' in /var/www/page1.php on line 2
Unable to connect


We have a SQL server at office with username, password and Database name Clients and Table name Course_list.

How can I solve this error?

Guess the code part is right.

Help me!

Reply With Quote
  #8  
Old October 23rd, 2009, 12:52 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
the host you have is wrong. its supposed to be the location of the server with the database. if the database is on the same computer as the web server use localhost, if its on any other server, use the IP address.

Reply With Quote
  #9  
Old October 23rd, 2009, 01:32 PM
Naughty Naughty is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2009
Posts: 83 Naughty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 53 m 8 sec
Reputation Power: 1
Hey,

I was informed it's a MS SQL and not MySQL.

Should I use the PDO Drivers to connect to MS SQL server remotely?


I haven't worked with MS SQL but only MySQL, that's why used this code.

If MS SQL, what or how should I edit the code?

Reply With Quote
  #10  
Old October 23rd, 2009, 01:46 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
You can use either the MSSQL extension or the PDO extension. check out the pdo and MSSQL pages in the manual. pretty much any function that says mysql will have to be changed to its pdo/mssql equivalent depending on what you decide to use.

Reply With Quote
  #11  
Old October 23rd, 2009, 02:11 PM
Naughty Naughty is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2009
Posts: 83 Naughty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 53 m 8 sec
Reputation Power: 1
I'm using the mssql quires.

Once I edited and executed my code. I got below error:

Fatal error: Call to undefined function mssql_connect() in /var/www/page1.php on line 2

I messed up with php and apache thing on my windows. For now I'm working with Linux.

How can fix this error?

Reply With Quote
  #12  
Old October 23rd, 2009, 03:02 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
do you have the mssql extension installed?

Reply With Quote
  #13  
Old October 23rd, 2009, 03:12 PM
Naughty Naughty is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2009
Posts: 83 Naughty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 53 m 8 sec
Reputation Power: 1
I checked out my phpinfo, where I found only Mysql but not anything even related to mssql.

How to install mssql on my linux?

Is it a module or an installer like MySQL?

I have installed LAMP server through synaptic package manager.

Reply With Quote
  #14  
Old October 23rd, 2009, 03:16 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
check you php extensions directory to find the mssql.so extension file. if its there then you just need to modify the php.ini file in the extensions section to include that extension. if the file is not there, then you would need to download the extension and put it in the extensions folder then modify the php.ini file like above. on windows if there is an extension that I need I just go to php.net and download the non-installer zip version and it generally has all the php extensions then just copy over what I need. on linux I don't know if you need to use some package manager or if there is somewhere in the lamp setup that you can do it.

Reply With Quote
  #15  
Old October 23rd, 2009, 03:39 PM
Naughty Naughty is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2009
Posts: 83 Naughty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 53 m 8 sec
Reputation Power: 1
Well, I'll check with Linux guys for this issue.

Also, I'm trying to repair my php and apache2 on windows. When I edit my php.ini file and come to restart my apache, it would give me an error message "The operation failed" I don't know why.

This started happening when I extracted phpmyadmin to C:/apache2.2/htdocs/phpmyadmin.

Where my browser displayed error on http://localhost/phpmyadmin/index.php

Error:
my sql extension not found. Please check PHP ...

When I started to work on that issue, my applications got corrupted and started doing weird things like this

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > To populate drop-down on one page and display the contents on 2nd page


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek