Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

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:
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  
Old August 4th, 2003, 04:09 PM
cmcdonld cmcdonld is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 cmcdonld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old August 4th, 2003, 04:56 PM
jaltiere jaltiere is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 55 jaltiere User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to jaltiere
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?

Reply With Quote
  #3  
Old August 4th, 2003, 05:46 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
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)

Reply With Quote
  #4  
Old August 5th, 2003, 05:47 PM
cmcdonld cmcdonld is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 cmcdonld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #5  
Old August 5th, 2003, 05:48 PM
cmcdonld cmcdonld is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 cmcdonld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Urgent: PHP Form posting data to SQL Server DB

My typo: username and password are not necessary...

Reply With Quote
  #6  
Old August 5th, 2003, 07:03 PM
cmcdonld cmcdonld is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 cmcdonld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #7  
Old August 5th, 2003, 07:24 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Urgent: PHP Form posting data to SQL Server DB

have you installed the MSSQL Extensions?

Reply With Quote
  #8  
Old August 5th, 2003, 07:33 PM
cmcdonld cmcdonld is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 cmcdonld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #9  
Old August 5th, 2003, 07:42 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
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!!

Reply With Quote
  #10  
Old August 5th, 2003, 07:43 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
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.

Reply With Quote
  #11  
Old August 5th, 2003, 07:49 PM
cmcdonld cmcdonld is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 cmcdonld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Urgent: PHP Form posting data to SQL Server DB

Thanks so much, I'll check it out!

Reply With Quote
  #12  
Old August 5th, 2003, 07:58 PM
cmcdonld cmcdonld is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 cmcdonld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #13  
Old August 5th, 2003, 08:41 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
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!!!

Reply With Quote
  #14  
Old August 6th, 2003, 04:08 PM
cmcdonld cmcdonld is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 cmcdonld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #15  
Old August 6th, 2003, 05:07 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
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.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Urgent: PHP Form posting data to SQL Server DB


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


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