Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-17-2012, 03:36 PM   PM User | #16
idalatob
Regular Coder

 
Join Date: Sep 2007
Location: Grahamstown, South Africa
Posts: 237
Thanks: 6
Thanked 17 Times in 17 Posts
idalatob is on a distinguished road
Fou-Lu doesnt take kindly to mistakes. :-P
idalatob is offline   Reply With Quote
Old 12-17-2012, 03:40 PM   PM User | #17
idalatob
Regular Coder

 
Join Date: Sep 2007
Location: Grahamstown, South Africa
Posts: 237
Thanks: 6
Thanked 17 Times in 17 Posts
idalatob is on a distinguished road
PHP Code:
<?php     
/** 
First thing, we create a function that will make your data safe! 
**/ 
function mssql_escape($data) { 
    if(
is_numeric($data)) 
        return 
$data
    
$unpacked unpack('H*hex'$data); 
    return 
'0x' $unpacked['hex']; 


if (isset(
$_POST['LOWNUMBER'])) {
    
//now we loop through the post data and sanitize it! 
    
foreach ($_POST as $key=>$value) { 
        
$_POST[$key] = mssql_escape($value); 
    } 
    
    
//now we build the query! 
    
$strSQL "INSERT INTO MSAG ";   
    
$strSQL .="(StreetName) ";   
    
$strSQL .="VALUES ";   
    
$strSQL .= "({$_POST['StreetName']})"
    
    
//now we insert it 
    
mssql_query($strSQL);
}
?>

<?php include 'includes/head/head_main.php'?> 

<div id = "top_content"> 
<body> 

<?php include 'includes/header/header_main.php'?> 

<h1>Add New Record</h1> 

<div id = "enter_record"> 

</center> 
<div id = "modify"> 



?> 

<form action="" method="post" enctype="multipart/form-data"> 

<table> 
<tr> 
<td>Pre Dir:    <br><input type="text" name="StreetPrefix"> <br></td> 
<td>Street:     <br><input type="text" name="StreetName"> <br></td> 
<td>Suffix:     <br><input type="text" name="StreetSuffix"> <br></td> 
<td>Post Dir:     <br><input type="text" name="StreetPostDir"> <br></td> 
<td>Community:     <br><input type="text" name="COMMUNITY"> <br></td> 
</tr></table> 
<br> 

<table>  
<tr> 
<td>Low:    <br><input type="text" name="LOWNUMBER"> <br></td> 
<td>High:    <br><input type="text" name="HighNumber"> <br></td> 
<td>EOB:    <br><input type="text" name="EOB"> <br></td> 
<td>ESN:    <br><input type="text" name="ESN"> <br></td> 
</tr> 
</table> 
<br> 

<table>  
<tr> 
<td>Telco:    <br><input type="text" name="TELCO"> <br></td> 
<td>ZIP:    <br><input type="text" name="PostOffice"> <br></td> 
<td>Zone:    <br><input type="text" name="ZONE"> <br></td> 
<td>Map:    <br><input type="text" name="MAP"> <br></td> 
</tr> 
</table> 
<br> 

<table> 
<tr> 
<td>Entered:    <br><input type="text" name="DateEntered"> <br></td> 
<td>Modified:    <br><input type="text" name="DateUpdated"> <br></td> 
</tr> 
</table> 
<br> 

<table> 
<tr> 
<td>Comments:    <br><input type="text" name="Commments"> <br></td> 
</tr> 
</table> 
<br> 
</div> 

<input type="submit" align = "left" name="submit" value="Submit"/> 
</table> 

</form> 
<br>     

</div>
idalatob is offline   Reply With Quote
Old 12-17-2012, 03:47 PM   PM User | #18
willscarlet
New Coder

 
Join Date: Aug 2012
Posts: 65
Thanks: 5
Thanked 0 Times in 0 Posts
willscarlet is an unknown quantity at this point
The form shows up fine on this one, however, on submit, it thows an internal 500 error. I turned on error reporting, but that didnt help at all:

PHP Code:
<?php

ini_set
('error_reporting'E_ALL);


   
/** 
First thing, we create a function that will make your data safe! 
**/ 
function mssql_escape($data) { 
    if(
is_numeric($data)) 
        return 
$data
    
$unpacked unpack('H*hex'$data); 
    return 
'0x' $unpacked['hex']; 


if (isset(
$_POST['LOWNUMBER'])) {
    
//now we loop through the post data and sanitize it! 
    
foreach ($_POST as $key=>$value) { 
        
$_POST[$key] = mssql_escape($value); 
    } 
    
    
//now we build the query! 
    
$strSQL "INSERT INTO MSAG ";   
    
$strSQL .="(StreetName) ";   
    
$strSQL .="VALUES ";   
    
$strSQL .= "({$_POST['StreetName']})"
    
    
//now we insert it 
    
mssql_query($strSQL);
}
?>

<?php include 'includes/head/head_main.php'?> 

<div id = "top_content"> 
<body> 

<?php include 'includes/header/header_main.php'?> 

<h1>Add New Record</h1> 

<div id = "enter_record"> 

</center> 
<div id = "modify"> 



<form action="" method="post" enctype="multipart/form-data"> 

<table> 
<tr> 
<td>Pre Dir:    <br><input type="text" name="StreetPrefix"> <br></td> 
<td>Street:     <br><input type="text" name="StreetName"> <br></td> 
<td>Suffix:     <br><input type="text" name="StreetSuffix"> <br></td> 
<td>Post Dir:     <br><input type="text" name="StreetPostDir"> <br></td> 
<td>Community:     <br><input type="text" name="COMMUNITY"> <br></td> 
</tr></table> 
<br> 

<table>  
<tr> 
<td>Low:    <br><input type="text" name="LOWNUMBER"> <br></td> 
<td>High:    <br><input type="text" name="HighNumber"> <br></td> 
<td>EOB:    <br><input type="text" name="EOB"> <br></td> 
<td>ESN:    <br><input type="text" name="ESN"> <br></td> 
</tr> 
</table> 
<br> 

<table>  
<tr> 
<td>Telco:    <br><input type="text" name="TELCO"> <br></td> 
<td>ZIP:    <br><input type="text" name="PostOffice"> <br></td> 
<td>Zone:    <br><input type="text" name="ZONE"> <br></td> 
<td>Map:    <br><input type="text" name="MAP"> <br></td> 
</tr> 
</table> 
<br> 

<table> 
<tr> 
<td>Entered:    <br><input type="text" name="DateEntered"> <br></td> 
<td>Modified:    <br><input type="text" name="DateUpdated"> <br></td> 
</tr> 
</table> 
<br> 

<table> 
<tr> 
<td>Comments:    <br><input type="text" name="Commments"> <br></td> 
</tr> 
</table> 
<br> 
</div> 

<input type="submit" align = "left" name="submit" value="Submit"/> 
</table> 

</form> 
<br>     

</div>
Also, when this code is fixed, up and running, is there a place I can post it so that others can reference it should they be new and have this problem?
willscarlet is offline   Reply With Quote
Old 12-17-2012, 03:52 PM   PM User | #19
idalatob
Regular Coder

 
Join Date: Sep 2007
Location: Grahamstown, South Africa
Posts: 237
Thanks: 6
Thanked 17 Times in 17 Posts
idalatob is on a distinguished road
Dont forget to actually connect to the database. Also, setting display errors might also help eg:

//show errors
PHP Code:

ini_set
("display_errors""on"); 
//connect to mssql database
PHP Code:

$server 
'KALLESPC\SQLEXPRESS';

// Connect to MSSQL
$link mssql_connect($server'sa''phpfi');

if (!
$link) {
    die(
'Something went wrong while connecting to MSSQL');
}

//Select DB 
$dbn 'dbName'
mssql_select_db($dbn); 

Last edited by idalatob; 12-17-2012 at 03:55 PM..
idalatob is offline   Reply With Quote
Old 12-17-2012, 03:56 PM   PM User | #20
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by idalatob View Post
Fou-Lu doesnt take kindly to mistakes. :-P
wrath++
Please note as well that mssql package is not available for PHP5.3+.
Fou-Lu is offline   Reply With Quote
Old 12-17-2012, 03:57 PM   PM User | #21
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,513
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by idalatob View Post
Fou-Lu doesnt take kindly to mistakes. :-P
Thats because he's a bl**dy good coder who knows his stuff. The better you become at coding the less tolerant you become with mistakes.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 12-17-2012, 03:59 PM   PM User | #22
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by tangoforce View Post
Thats because he's a bl**dy good coder who knows his stuff. The better you become at coding the less tolerant you become with mistakes.
That's right! I'm [practically] perfect hehehe
One day I'll actually start programming again. My skills are becoming a bit antiquated over the past few years.
Fou-Lu is offline   Reply With Quote
Old 12-17-2012, 03:59 PM   PM User | #23
willscarlet
New Coder

 
Join Date: Aug 2012
Posts: 65
Thanks: 5
Thanked 0 Times in 0 Posts
willscarlet is an unknown quantity at this point
okay, now it shows the error being thrown:
Fatal error: Call to undefined function mssql_query() in C:\Inetpub\wwwroot\msag\enter.php on line 28

PHP Code:
<?php
include 'includes/db/connect.php';
ini_set("display_errors""on");

/**
First thing, we create a function that will make your data safe! 
**/ 
function mssql_escape($data) { 
    if(
is_numeric($data)) 
        return 
$data
    
$unpacked unpack('H*hex'$data); 
    return 
'0x' $unpacked['hex']; 


if (isset(
$_POST['LOWNUMBER'])) {
    
//now we loop through the post data and sanitize it! 
    
foreach ($_POST as $key=>$value) { 
        
$_POST[$key] = mssql_escape($value); 
    } 
    
    
//now we build the query! 
    
$strSQL "INSERT INTO MSAG ";   
    
$strSQL .="(StreetName) ";   
    
$strSQL .="VALUES ";   
    
$strSQL .= "({$_POST['StreetName']})"
    
    
//now we insert it 
    
mssql_query($strSQL);
}
?>

<?php include 'includes/head/head_main.php'?> 

<div id = "top_content"> 
<body> 

<?php include 'includes/header/header_main.php'?> 

<h1>Add New Record</h1> 

<div id = "enter_record"> 

</center> 
<div id = "modify"> 



<form action="" method="post" enctype="multipart/form-data"> 

<table> 
<tr> 
<td>Pre Dir:    <br><input type="text" name="StreetPrefix"> <br></td> 
<td>Street:     <br><input type="text" name="StreetName"> <br></td> 
<td>Suffix:     <br><input type="text" name="StreetSuffix"> <br></td> 
<td>Post Dir:     <br><input type="text" name="StreetPostDir"> <br></td> 
<td>Community:     <br><input type="text" name="COMMUNITY"> <br></td> 
</tr></table> 
<br> 

<table>  
<tr> 
<td>Low:    <br><input type="text" name="LOWNUMBER"> <br></td> 
<td>High:    <br><input type="text" name="HighNumber"> <br></td> 
<td>EOB:    <br><input type="text" name="EOB"> <br></td> 
<td>ESN:    <br><input type="text" name="ESN"> <br></td> 
</tr> 
</table> 
<br> 

<table>  
<tr> 
<td>Telco:    <br><input type="text" name="TELCO"> <br></td> 
<td>ZIP:    <br><input type="text" name="PostOffice"> <br></td> 
<td>Zone:    <br><input type="text" name="ZONE"> <br></td> 
<td>Map:    <br><input type="text" name="MAP"> <br></td> 
</tr> 
</table> 
<br> 

<table> 
<tr> 
<td>Entered:    <br><input type="text" name="DateEntered"> <br></td> 
<td>Modified:    <br><input type="text" name="DateUpdated"> <br></td> 
</tr> 
</table> 
<br> 

<table> 
<tr> 
<td>Comments:    <br><input type="text" name="Commments"> <br></td> 
</tr> 
</table> 
<br> 
</div> 

<input type="submit" align = "left" name="submit" value="Submit"/> 
</table> 

</form> 
<br>     

</div>
P.S. You were correct that I forgot to include my connection.

Also, I know this may be outside of this forums scope, but, Is PHP the best way to manipulate a database like this?
willscarlet is offline   Reply With Quote
Old 12-17-2012, 04:02 PM   PM User | #24
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You'll need to use the SQLSrv or PDO packages. The mssql isn't available on 5.3+, which appears to likely be the case here (or its just disabled).

You can use any language that's capable of external resource to manipulate a database. If you are looking for ease of use, then with SQLServer it would be easiest done using C# or VB.
Fou-Lu is offline   Reply With Quote
Old 12-17-2012, 04:04 PM   PM User | #25
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
Quote:
Originally Posted by tangoforce View Post
Thats because he's a bl**dy good coder who knows his stuff. The better you become at coding the less tolerant you become with mistakes.
So true i feel really bad about giving out wrong info like that, honestly i should be thanking willscarlet because i leaned today that there is such a thing as MsSQL, its the first i have heard of it and again i am so sorry. I have only dealt with MySql and i had terrible tunnel vision on this one. When i saw MsSQL i thought it was a typo on his part. Again sorry lol.. .

Here is something i hope Fou-Lu and the rest of us will chuckle about, for the longest time (i dont know why) but until recently (a few weeks ago) i always thought Fou-Lu was a female lmao...
durangod is offline   Reply With Quote
Old 12-17-2012, 04:17 PM   PM User | #26
willscarlet
New Coder

 
Join Date: Aug 2012
Posts: 65
Thanks: 5
Thanked 0 Times in 0 Posts
willscarlet is an unknown quantity at this point
Fou, you are correct again. I remember having this issue in the very beggining when I started this project. I had to convert all the MySQL to sqlsrv for the most part. I did so, and had to add my $conn, variable to the query as well to clear a new error that arose. The new code now shows up, on the screen, when I hit submit, it refreshes the page (clearing the form data fields) but still is not inserting it into the database for some reason.

code:
PHP Code:
<?php
include 'includes/db/connect.php';
ini_set("display_errors""on");

/**
First thing, we create a function that will make your data safe! 
**/ 
function mssql_escape($data) { 
    if(
is_numeric($data)) 
        return 
$data
    
$unpacked unpack('H*hex'$data); 
    return 
'0x' $unpacked['hex']; 


if (isset(
$_POST['LOWNUMBER'])) {
    
//now we loop through the post data and sanitize it! 
    
foreach ($_POST as $key=>$value) { 
        
$_POST[$key] = mssql_escape($value); 
    } 
    
    
//now we build the query! 
    
$strSQL "INSERT INTO MSAG ";   
    
$strSQL .="(StreetName) ";   
    
$strSQL .="VALUES ";   
    
$strSQL .= "({$_POST['StreetName']})"
    
    
//now we insert it 
    
sqlsrv_query($conn$strSQL);
}
?>

<?php include 'includes/head/head_main.php'?> 

<div id = "top_content"> 
<body> 

<?php include 'includes/header/header_main.php'?> 

<h1>Add New Record</h1> 

<div id = "enter_record"> 

</center> 
<div id = "modify"> 



<form action="" method="post" enctype="multipart/form-data"> 

<table> 
<tr> 
<td>Pre Dir:    <br><input type="text" name="StreetPrefix"> <br></td> 
<td>Street:     <br><input type="text" name="StreetName"> <br></td> 
<td>Suffix:     <br><input type="text" name="StreetSuffix"> <br></td> 
<td>Post Dir:     <br><input type="text" name="StreetPostDir"> <br></td> 
<td>Community:     <br><input type="text" name="COMMUNITY"> <br></td> 
</tr></table> 
<br> 

<table>  
<tr> 
<td>Low:    <br><input type="text" name="LOWNUMBER"> <br></td> 
<td>High:    <br><input type="text" name="HighNumber"> <br></td> 
<td>EOB:    <br><input type="text" name="EOB"> <br></td> 
<td>ESN:    <br><input type="text" name="ESN"> <br></td> 
</tr> 
</table> 
<br> 

<table>  
<tr> 
<td>Telco:    <br><input type="text" name="TELCO"> <br></td> 
<td>ZIP:    <br><input type="text" name="PostOffice"> <br></td> 
<td>Zone:    <br><input type="text" name="ZONE"> <br></td> 
<td>Map:    <br><input type="text" name="MAP"> <br></td> 
</tr> 
</table> 
<br> 

<table> 
<tr> 
<td>Entered:    <br><input type="text" name="DateEntered"> <br></td> 
<td>Modified:    <br><input type="text" name="DateUpdated"> <br></td> 
</tr> 
</table> 
<br> 

<table> 
<tr> 
<td>Comments:    <br><input type="text" name="Commments"> <br></td> 
</tr> 
</table> 
<br> 
</div> 

<input type="submit" align = "left" name="submit" value="Submit"/> 
</table> 

</form> 
<br>     

</div>
willscarlet is offline   Reply With Quote
Old 12-17-2012, 04:20 PM   PM User | #27
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
If you insert it as a flat sql string, you need to provide the proper datatypes: $strSQL .= "({$_POST['StreetName']})"; . Assuming that street name is a string, you need to change that into $strSQL .= "('{$_POST['StreetName']}')"; (although you will need to execute an escape sequence on it such as the one provided by idalatob). Personally I'd use the parameter's for the statement.
You can verify that this is a datatype issue by executing the sqlsrv_query with an or die(print_r(sqlsrv_error(), true)); and inspecting the error.

Edit:
Quote:
Originally Posted by durangod View Post
Here is something i hope Fou-Lu and the rest of us will chuckle about, for the longest time (i dont know why) but until recently (a few weeks ago) i always thought Fou-Lu was a female lmao...
rofls
Fou-Lu is offline   Reply With Quote
Old 12-17-2012, 04:30 PM   PM User | #28
willscarlet
New Coder

 
Join Date: Aug 2012
Posts: 65
Thanks: 5
Thanked 0 Times in 0 Posts
willscarlet is an unknown quantity at this point
I thank you for taking the time to continue to help me figure this out, however, I fear I may be a tad too simple minded. Im am very confused about your last post sir. Im sure it was worded properly, I just dont quite understand. Yes sir, StreetName is a string, I am assuming that the fields that are not strings I would simply need to take the ' out of it? I did change my code to what i believe you said to, and the results are still the same (Page just refreshes, nothign added to the DB):

PHP Code:
<?php
include 'includes/db/connect.php';
ini_set("display_errors""on");

/**
First thing, we create a function that will make your data safe! 
**/ 
function mssql_escape($data) { 
    if(
is_numeric($data)) 
        return 
$data
    
$unpacked unpack('H*hex'$data); 
    return 
'0x' $unpacked['hex']; 


if (isset(
$_POST['LOWNUMBER'])) {
    
//now we loop through the post data and sanitize it! 
    
foreach ($_POST as $key=>$value) { 
        
$_POST[$key] = mssql_escape($value); 
    } 
    
    
//now we build the query! 
    
$strSQL "INSERT INTO MSAG ";   
    
$strSQL .="(StreetName) ";   
    
$strSQL .="VALUES ";   
    
$strSQL .= "('{$_POST['StreetName']}')";
    
    
//now we insert it 
    
sqlsrv_query($conn$strSQL) or die(print_r(sqlsrv_error(), true));
}
?>

<?php include 'includes/head/head_main.php'?> 

<div id = "top_content"> 
<body> 

<?php include 'includes/header/header_main.php'?> 

<h1>Add New Record</h1> 

<div id = "enter_record"> 

</center> 
<div id = "modify"> 



<form action="" method="post" enctype="multipart/form-data"> 

<table> 
<tr> 
<td>Pre Dir:    <br><input type="text" name="StreetPrefix"> <br></td> 
<td>Street:     <br><input type="text" name="StreetName"> <br></td> 
<td>Suffix:     <br><input type="text" name="StreetSuffix"> <br></td> 
<td>Post Dir:     <br><input type="text" name="StreetPostDir"> <br></td> 
<td>Community:     <br><input type="text" name="COMMUNITY"> <br></td> 
</tr></table> 
<br> 

<table>  
<tr> 
<td>Low:    <br><input type="text" name="LOWNUMBER"> <br></td> 
<td>High:    <br><input type="text" name="HighNumber"> <br></td> 
<td>EOB:    <br><input type="text" name="EOB"> <br></td> 
<td>ESN:    <br><input type="text" name="ESN"> <br></td> 
</tr> 
</table> 
<br> 

<table>  
<tr> 
<td>Telco:    <br><input type="text" name="TELCO"> <br></td> 
<td>ZIP:    <br><input type="text" name="PostOffice"> <br></td> 
<td>Zone:    <br><input type="text" name="ZONE"> <br></td> 
<td>Map:    <br><input type="text" name="MAP"> <br></td> 
</tr> 
</table> 
<br> 

<table> 
<tr> 
<td>Entered:    <br><input type="text" name="DateEntered"> <br></td> 
<td>Modified:    <br><input type="text" name="DateUpdated"> <br></td> 
</tr> 
</table> 
<br> 

<table> 
<tr> 
<td>Comments:    <br><input type="text" name="Commments"> <br></td> 
</tr> 
</table> 
<br> 
</div> 

<input type="submit" align = "left" name="submit" value="Submit"/> 
</table> 

</form> 
<br>     

</div>

Last edited by willscarlet; 12-17-2012 at 04:34 PM..
willscarlet is offline   Reply With Quote
Old 12-17-2012, 05:25 PM   PM User | #29
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
No error tossed against the sqlsrv_error?
Just looking at it I'd have to guess that the record itself cannot consist of just the StreetName. I can't tell for sure, but I would presume that you have more fields that are required for the insertion point, but I'd also expect that the sqlsrv_error would indicate that. Since it does not, it lends weight to the issue being that $_POST['LOWNUMBER'] isn't set. Looks to me that it is though. Make sure you are executing this script from scratch, not just refreshing and sending the same data.

I'm not 100% sure that the quotes are required actually. This is a hex string going in, so it may want it as a number. But if that were the case you'd be limited to 32/64 bit in length as well, so that wouldn't make sense. I'd expect it would also throw an error in the die call.
Wait I think I found it here. The error is actually sqlsrv_errors() with an 's' at the end. Make sure you open the error reporting up with error_reporting(E_ALL); that should have thrown an undefined function error.
Fou-Lu is offline   Reply With Quote
Old 12-17-2012, 05:51 PM   PM User | #30
willscarlet
New Coder

 
Join Date: Aug 2012
Posts: 65
Thanks: 5
Thanked 0 Times in 0 Posts
willscarlet is an unknown quantity at this point
I turned on the errors and all, but still not recieving an error, Page is still simply refreshing itself:

In my isset, what is the purpose of having LOWNUMBER in that spot? I tried replacing it with StreetName, but still the same results.

PHP Code:
<?php
include 'includes/db/connect.php';

error_reporting(E_ALL); 
ini_set("display_errors""on");

/**
First thing, we create a function that will make your data safe! 
**/ 
function mssql_escape($data) { 
    if(
is_numeric($data)) 
        return 
$data
    
$unpacked unpack('H*hex'$data); 
    return 
'0x' $unpacked['hex']; 


if (isset(
$_POST['LOWNUMBER'])) {
    
//now we loop through the post data and sanitize it! 
    
foreach ($_POST as $key=>$value) { 
        
$_POST[$key] = mssql_escape($value); 
    } 
    
    
//now we build the query! 
    
$strSQL "INSERT INTO MSAG ";   
    
$strSQL .="(StreetName) ";   
    
$strSQL .="VALUES ";   
    
$strSQL .= "('{$_POST['StreetName']}')";
    
    
//now we insert it 
    
sqlsrv_query($conn$strSQL) or die(print_r(sqlsrv_errors(), true));
}
?>

<?php include 'includes/head/head_main.php'?> 

<div id = "top_content"> 
<body> 

<?php include 'includes/header/header_main.php'?> 

<h1>Add New Record</h1> 

<div id = "enter_record"> 

</center> 
<div id = "modify"> 



<form action="" method="post" enctype="multipart/form-data"> 

<table> 
<tr> 
<td>Pre Dir:    <br><input type="text" name="StreetPrefix"> <br></td> 
<td>Street:     <br><input type="text" name="StreetName"> <br></td> 
<td>Suffix:     <br><input type="text" name="StreetSuffix"> <br></td> 
<td>Post Dir:     <br><input type="text" name="StreetPostDir"> <br></td> 
<td>Community:     <br><input type="text" name="COMMUNITY"> <br></td> 
</tr></table> 
<br> 

<table>  
<tr> 
<td>Low:    <br><input type="text" name="LOWNUMBER"> <br></td> 
<td>High:    <br><input type="text" name="HighNumber"> <br></td> 
<td>EOB:    <br><input type="text" name="EOB"> <br></td> 
<td>ESN:    <br><input type="text" name="ESN"> <br></td> 
</tr> 
</table> 
<br> 

<table>  
<tr> 
<td>Telco:    <br><input type="text" name="TELCO"> <br></td> 
<td>ZIP:    <br><input type="text" name="PostOffice"> <br></td> 
<td>Zone:    <br><input type="text" name="ZONE"> <br></td> 
<td>Map:    <br><input type="text" name="MAP"> <br></td> 
</tr> 
</table> 
<br> 

<table> 
<tr> 
<td>Entered:    <br><input type="text" name="DateEntered"> <br></td> 
<td>Modified:    <br><input type="text" name="DateUpdated"> <br></td> 
</tr> 
</table> 
<br> 

<table> 
<tr> 
<td>Comments:    <br><input type="text" name="Commments"> <br></td> 
</tr> 
</table> 
<br> 
</div> 

<input type="submit" align = "left" name="submit" value="Submit"/> 
</table> 

</form> 
<br>     

</div>
willscarlet is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:03 AM.


Advertisement
Log in to turn off these ads.