Link to home
Start Free TrialLog in
Avatar of Misty Corning
Misty Corning

asked on

Submitting a PHP form to SQL Server

Hello, when submitting my form, I get the following error:
Fatal error: Uncaught Error: Call to undefined function odbc_execute() in C:\xampp\htdocs\test\pagea.php:87 Stack trace: #0 {main} thrown in C:\xampp\htdocs\test\pagea.php on line 87

Thanks in advance!
pagea.php
Avatar of Robert Granlund
Robert Granlund
Flag of United States of America image

Can you please share pagea.php
Avatar of Misty Corning
Misty Corning

ASKER

Should be there now.  Thanks
In case you didn't get it:
pagea.php
bootstrap.css
Create a sample file that contains:

<?php phpinfo();

If you do not see the odbc extension loaded you will  need to load it in your php.ini for support.
ok, viewing it now.  What heading is it under?
In chrome click control F and search the page for: odbc
The documentation says that this line needs to be in the php.ini:
extension=php_odbc.dll
there are already drivers: odbc 11 for SQL Server and odbc 17 for SQL Server.  I'm running 7.1 on windows server 2012 r 2.  Which one do I need?

Do I add these to my php.ini as well?
Which one do I need in my connection string?
now it says expects parameter 1 to be resource, null given

$sql=odbc_exec($conn, "INSERT INTO SBLAND values ('$badgenumber','$officer',getdate(),'$gender','$race','$raceknownprior', '$reasonforstop','$location','$searchconducted','$reasonforsearch','$contraband','$descriptionofcontraband','$arrested', '$offensecharged','$arrestnumber','$forceused','$bodilyinjury','$verbalwarning','$writtencitation', '$citationnumber', '$writtenwarning','$warningnumber','$writtenfield')");
Avatar of Julian Hansen
That is because the $conn variable is not a valid connection. In your
include_once('connection.inc.php');

Open in new window

The connection to the database failed.

You need to setup error reporting around your DB Connection and
a) Check to see that a valid connection is made
b) If it fails report an error so you can see why.

For now you need to go back to your connection.inc.php file and see what connection parameters you are using and check that they are correct. Additionally, put some error output (odbc-errormsg so you can get some idea of what went wrong.
I did that.  In this file, it shows its connected.  Is this giving a false reading?
connection.inc.php
Firstly your connection.inc.php is not constructed correctly. It is constructed as if it were a page rather than a utility script you are including.
Included scripts don't have the <html> and body tags. In this case I would make it pure PHP - no html.

Secondly, the error you are getting suggests the connection failed - but that does not make sense because the die() statement in the connection.inc.php file should have caught that so unless there is something you have not shown us it does not make sense.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.