| | |
Creating a dynamic query using MSSQL and PHP
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2007
Posts: 6
Reputation:
Solved Threads: 0
I'm a bit of a beginning to PHP, so I hope that this question isn't too terribly simple. I'm trying to write a flexible query that will use data from an HTML form to create a SELECT statement for a MSSQL database. I've tried writing a sample query, but I can't seem to get any data out of the database.
Here's my code:
Thanks for the help!
David
Here's my code:
PHP Syntax (Toggle Plain Text)
from sqlmain.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <form action="ms_sql.php" method="get" name="main"> <input name="name" type="text"> <input name="submit" type="submit" value="Submit"> </form> </body> </html> from ms_sql.php $host ='mssql.library.univ.edu'; $user = 'LIB_webuser'; $pass ='######'; $db = 'LIB'; //Open connection $connection = mssql_connect($host, $user, $pass) or die("Unable to connect"); //Select database mssql_select_db($db) or die("Unable to select database"); //Create query //$query = "SELECT * FROM dbo.dbd"; $name = $_POST['name']; $query = "SELECT $name FROM bdb"; // Execute query $result = mssql_query($query); while($row = mssql_fetch_array($result)){ echo $row['netid']; echo "<br />"; //free result set memory mssql_free_result($result); //close connection mssql_close($connection);
Thanks for the help!
David
![]() |
Similar Threads
- Compile PHP (PHP)
- Dynamic query string (Search Engine Optimization)
- mssql_fetch_array or mssql_query is stripping out a space in PHP (PHP)
- Creating a login page in PHP (PHP)
- MSSQL and ASP Query (ASP.NET)
- Googles php and MySQL preferences (Search Engine Optimization)
- php adodb library connect remote mysql (PHP)
- Dynamic Next/Prev Buttons in PHP/MySQL (MySQL)
- Enabling MSSQL Function in the PHP.ini (PHP)
Other Threads in the PHP Forum
- Previous Thread: Problem with creating scheduling program
- Next Thread: Question
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube





