|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
Urgent: PHP Form posting data to SQL Server DB
Please help. I am not familiar enought with PHP and SQL to figure out why it will not write to the SQL Server. According to all the books I have the code is correct--I am missing something important.
I have a form page which on submit sends the data to a PHP page which is supposed to write the data to the DB. This is the code on the accept page: <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <?php $db_name = "paraprof"; $table_name = "paraprof"; $connection = mssql_connect("", "", "") or die("Could not connect to database."); $db = mssql_select_db($db_name,$connection) or die("Could not connect to database."); $sql = "INSERT INTO $table_name(DistrictName, TotalDistrict, q1, q2, q3a, q3b, q3c, q3d) VALUES ('$DistrictName' , '$TotalDistrict' , '$q1' , '$q2' , '$q3a' , '$q3b' ,'$q3c' , '$q3d')"; $result = mssql_query($sql, $connection) or die("Could not execute query."); mssql_close($connection); ?> </head> <body> <p>Thank you. The information has been accepted.</p> </body> </html> I just don't know what I am missing. |
|
#2
|
|||
|
|||
|
RE: Urgent: PHP Form posting data to SQL Server DB
What happens when you try to submit the form? Are you able to connect to the database?
The mssql_connect function takes the parameters servername, username and password, are you filling them out correctly? |
|
#3
|
|||
|
|||
|
RE: Urgent: PHP Form posting data to SQL Server DB
Do you get any errors? If not, check to see of registar globals is set to off in the php.ini file (it is off by default in newer versions of php) that would require you to use $_GET['variable_name'] or $_POST['variable_name'] depending on what method you are using when submitting your form (get or post)
|
|
#4
|
|||
|
|||
|
RE: Urgent: PHP Form posting data to SQL Server DB
I added the server name to the connection string and am still receiving a connection error; username and password are necessary for this form -- do I still have to add something in these areas? Example:
<?php $connection = mssql_connect("myservname", "username", "password") or die("Could not connect to database."); ?> this is what I have now: <?php $connection = mssql_connect("myservname", "", "") or die("Could not connect to database."); ?> This is a new install of PHP on a SQL server 2000, I wonder if something is not set correctly, any suggestions? |
|
#5
|
|||
|
|||
|
RE: Urgent: PHP Form posting data to SQL Server DB
My typo: username and password are not necessary...
|
|
#6
|
|||
|
|||
|
RE: Urgent: PHP Form posting data to SQL Server DB
This is the error message I receive:
"Fatal error: Call to undefined function: mssql_connect()in ..." Any suggestions? |
|
#7
|
|||
|
|||
|
RE: Urgent: PHP Form posting data to SQL Server DB
have you installed the MSSQL Extensions?
|
|
#8
|
|||
|
|||
|
RE: Urgent: PHP Form posting data to SQL Server DB
I'll have to check with the server guy. On a SQL Server 2000 using ISS wouldn't those automatically be loaded?
|
|
#9
|
|||
|
|||
|
RE: Urgent: PHP Form posting data to SQL Server DB
No, You need to modify the php.ini file to use the specific dll that controls those functions. If you look at the Manual under Microsoft SQL Server functions, it explains what needs to be done. In a nutshell , you need to make sure that the file: php_mssql.dll is in the extension directory specified in the php.ini file then you need to add the following line to the php.ini file
extension=php_mssql.dll And you either need The SQL Client (or server) installed on the box that PHP is running on. If you can't install either of those you will need at least the file ntwdblib.dll loaded into the system32 folder. The MSSQL extensions will not work without it. Hope that helps!! |
|
#10
|
|||
|
|||
|
RE: Urgent: PHP Form posting data to SQL Server DB
When I refer to the 'Manual" in my previous post, I am referring to the PHP Manual not the MSSQL Manual.
|
|
#11
|
|||
|
|||
|
RE: Urgent: PHP Form posting data to SQL Server DB
Thanks so much, I'll check it out!
|
|
#12
|
|||
|
|||
|
RE: Urgent: PHP Form posting data to SQL Server DB
One more question: I found this info on a thread dated in April, I responded but wasn't sure if you would see it--the thread being dated so far back and all.
This is the suggestion:----------------------------------------------- <? $company_name = $_POST["company_name"]; //connect to db $query = "SELECT * from table WHERE company_name = "$company_name";"; $result = mysql_query($query); $row = mysql_fetch_object($result); //get all the vars ($var = $row->var;) ?> All that you have to do is name the input fields the same var as what you are pulling from the db. Then when the company is selected, and the page is reposted to itself, it will load the info. Hope that is what you meant. ------------------------------------------------------------- My question (forgive me, it might be stupid): Can I pull data from a table within a DB and insert the pulled data along with new data into a different table within that same DB? It seems I read someplace that you should never write to a DB that you are pulling info from, but I wanted to dould check this with you guys for your input. |
|
#13
|
|||
|
|||
|
RE: Urgent: PHP Form posting data to SQL Server DB
You can pretty much do anything you need/want to do. I have never heard of not writting to the db you are reading from. Go Crazy!!!
|
|
#14
|
|||
|
|||
|
RE: Urgent: PHP Form posting data to SQL Server DB
(PHP 4, SQL Server 2000, Windows 2000)
I am receiving this message: "Warning: mssql_connect(): message: Login failed for user 'myPass'. Reason: Not associated with a trusted SQL Server connection. (severity 14)" Any suggestions? |
|
#15
|
|||
|
|||
|
RE: Urgent: PHP Form posting data to SQL Server DB
That is indicating a SQL Server login error, check that the username and password are valid for the db you are trying to access.
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Urgent: PHP Form posting data to SQL Server DB |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|