0

I have two files, csform.php and process.php. Csform.php is the main page with the form that a user will enter in the data and hit submit which then I have process.php and the sql connection and I want that data the user entered into the form to be inserted into the sql server database. But when submit is hit the data that is entered into the form is not inserted, the data in line 13 of the process.php file is inserted. What am I doing wrong, is doesn't seem like I have a connection between the two files. Here is the coding I currently have:

csform.php:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CSLog</title>
</head>
<h1> Customer Service Form </h1>
<form method="post" action="process.php"> 
<table width="300" border="0">
<tr>
<td> Forte ID:</td>
<td><select id="forteid" input name="forteid">                  
                <option value="user1">user1</option>
                <option value="user2">user2</option>
                <option value="user3">user3</option>
                <option value="user4">user4</option>                   
    </select></td>
 </tr>
 <tr>
 <td> Disposition</td>
 <td><select id="disposition" input name="disposition">                 
                <option value="Save">--Save--</option>
                <option value="Sale">--Sale--</option>
                <option value="LOC">--LOC--</option>                   
    </select> </td>
</tr>
</table>
<br />
<hr />        
<br /> 
<br /> 
<table width="400" border="0">
<tr>
<td>App Number:</td>
<td></td>
<td><input type="text" name="appnumber"></td>
</tr>
<tr>
<td>Finance Number:</td>
<td></td>
<td><input type="text" name = "Finance_Num"></td>
</tr>
<tr>
<td>Number Payments:</td>
<td></td>
<td><input type="text" name = "num_payments"></td>
</tr>
<tr>
<td>Ach or CC:</td>
<td></td>
<td><input type="text" name = "ach_cc"></td>
</tr>
<tr>
<td>Date:</td>
<td></td>
<td><input type="text" name = "date"></td>
</tr>
</table>
<br />
Notes: 
<br />
<textarea input name="text" id="notes" cols="45" rows="5"></textarea>
</fieldset>
<br />
<br /> 
<hr />
<br />
<br />            
<input type="submit" name="formSubmit" value="Submit">  <input type="Reset"        name="formReset" value="Reset"> 
</form> 
</head>
<body>
</body>
</html>

And then the process.php:

<?php
$serverName = 'SRB-Nick_Desktop\SQLEXPRESS';
$connectionInfo = array('Database'=>'cslogs', 'UID'=>'cslogslogin', 'PWD'=>'123456');
$connection = sqlsrv_connect($serverName, $connectionInfo);

if( $connection === false )
{
 echo "Connection could not be established.\n";
 die( print_r( sqlsrv_errors(), true));
}

$tsql = "INSERT INTO logs(ForteID, disposition, appnumber, Finance_Num, num_payments,   ach_cc, date, notes) VALUES (?,?,?,?,?,?,?,?)";
$parameters = array( "forteid", "LOC", "NCXXXXXXX4", "SRB-000004", "0", "cc", "2012-11-01", "gave LOC instructions");
$stmt = sqlsrv_query($connection, $tsql, $parameters);
if( $stmt === false ){
echo "Statement could not be executed.\n";
 die( print_r( sqlsrv_errors(), true));
} else {
echo "Rows affected: ".sqlsrv_rows_affected( $stmt )."\n";
}
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $connection);
?>

Hopefully someone is able to help me or steer me in the right direction on what I am doing wrong.

0

2 Answers 2

2

csform.php

In csform.php, the <select>'s do not need the word input:

Change

<select id="forteid" input name="forteid">

To

<select id="forteid" name="forteid">

process.php

In process.php, you need to use the passed variables using $_POST[variable_name]. You are POSTing to process.php, yet not using anything from $_POST.

You can use print_r($_POST); at the top of process.php to see what variables are being passed:

Sign up to request clarification or add additional context in comments.

5 Comments

When I do that I get a bunch of errors: Notice: Use of undefined constant ForteID - assumed 'ForteID' in C:\wamp\www\cslogs\process.php on line 13 Notice: Undefined index: ForteID in C:\wamp\www\cslogs\process.php on line 13 Notice: Use of undefined constant disposition - assumed 'disposition' in C:\wamp\www\cslogs\process.php on line 13 and more, one for each of the fields.
Those are called notices. If you have access to php.ini, you can change the error_reporting setting. Otherwise, you put error_reporting(E_ALL ^ E_NOTICE); at the top of process.php. You can read the manual on the various error levels.
I am not sure what I am supposed to do with the part with the print_r($_POST);
@ncurran217 That will simply output the values of the variables being POSTed to process.php. It's only for your reference.
Ok I put the print_r($_POST); at the top of my php file and I got this: Array ( [forteid] => user2 [disposition] => Sale [appnumber] => asdf [Finance_Num] => asdf [num_payments] => 2 [ach_cc] => cc [date] => 11/02/12 [text] => asdfasdfasdf [formSubmit] => Submit ) exactly what I put in the form.
0

To build on @njk's answer you would also need to change line 13 to accept the parameters so you would do something like this:

$parameters = array($_POST[forteid], $_POST[disposition], $_POST[appnumber], $_POST[Finance_Num], $_POST[num_payments], $_POST[ach_cc], $_POST[date], $_POST[notes]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.