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-18-2012, 02:23 PM   PM User | #46
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 thought it was already POST. How do I change it, sir?
willscarlet is offline   Reply With Quote
Old 12-18-2012, 02:32 PM   PM User | #47
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 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
Add method="post" attribute to the form element.
Fou-Lu is offline   Reply With Quote
Old 12-18-2012, 02:42 PM   PM User | #48
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'm an idiot, I forgot that I had goten rid of that. now in submit, it is throwing this out on a solid white page:

Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -57 [code] => -57 [2] => String keys are not allowed in parameters arrays. [message] => String keys are not allowed in parameters arrays. ) )
willscarlet is offline   Reply With Quote
Old 12-18-2012, 02:52 PM   PM User | #49
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 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
Interesting choice of an error description. Not at all clear.
Try this: if (false === ($stmt = sqlsrv_query($conn, $sQry, array_values$aSubmitted)))) and see if that makes a difference. *Sounds* to me that it doesn't like associative arrays, which of course makes no sense.
Fou-Lu is offline   Reply With Quote
Old 12-18-2012, 02:58 PM   PM User | #50
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
That is throwing a generic 500 internal error.
Also tried taking the 4th ) away from the end. Same end result though.

Last edited by willscarlet; 12-18-2012 at 03:02 PM..
willscarlet is offline   Reply With Quote
Old 12-18-2012, 03:18 PM   PM User | #51
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 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 need the forth one. I was missing the opening here: array_values(
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
willscarlet (12-18-2012)
Old 12-18-2012, 08:18 PM   PM User | #52
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
Fantastic, this is working great so far. you guys are awesome. I promise after this project I am never messing with PHP and MsSQL again, going back to MySQL, maybe I wont have to bug you guys as much then anyways thanks a bunch. Ima go make a new post.

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'])) {
    
    
$aAllowed = array(    'StreetPrefix'
                        
'StreetName'
                        
'StreetSuffix'
                        
'StreetPostDir'
                        
'COMMUNITY',
                        
'LOWNUMBER',
                        
'HighNumber',
                        
'EOB',
                        
'ESN',
                        
'TELCO',
                        
'PostOffice',
                        
'ZONE',
                        
'MAP',
                        
'DateEntered',
                        
'DateUpdated',
                        
'Comment',
                        ); 
// all the allowed items.
function removeUnknowns(&$item$key, array $aAllowed)
{
    if (!
in_array($key$aAllowed))
    {
        
$item "";
    }
}

$aSubmitted $_POST;
array_walk($aSubmitted'removeUnknowns'$aAllowed);
$aSubmitted array_filter($aSubmitted);

$sFields implode('], ['array_keys($aSubmitted));
$sReplacement rtrim(str_repeat('?, 'count($aSubmitted)), ', ');
$sQry "INSERT INTO [MSAG] ([$sFields]) VALUES ($sReplacement)";

if (
false === ($stmt sqlsrv_query($conn$sQryarray_values($aSubmitted))))
{
    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 id="login" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method = "post" >

<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="Comment"> <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-18-2012, 08:44 PM   PM User | #53
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 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 can remove this since it's unused now:
PHP Code:
/**
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']; 

Fou-Lu is offline   Reply With Quote
Old 12-24-2012, 08:40 AM   PM User | #54
rajdeep01
New Coder

 
Join Date: Dec 2012
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
rajdeep01 can only hope to improve
To create 'examples' database on your MSSQL Server you should run the following script:
CREATE DATABASE examples;
USE examples;
CREATE TABLE cars(
id int UNIQUE NOT NULL,
name varchar(40),
year varchar(50),
PRIMARY KEY(id)
);

INSERT INTO cars VALUES(1,'Mercedes','2000');
INSERT INTO cars VALUES(2,'BMW','2004');
INSERT INTO cars VALUES(3,'Audi','2001');
rajdeep01 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 09:19 AM.


Advertisement
Log in to turn off these ads.