Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 4 of 4 FirstFirst ... 234
Results 46 to 53 of 53

Thread: PHP / MsSQL

  1. #46
    New Coder
    Join Date
    Aug 2012
    Posts
    65
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I thought it was already POST. How do I change it, sir?

  2. #47
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Add method="post" attribute to the form element.

  3. #48
    New Coder
    Join Date
    Aug 2012
    Posts
    65
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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. ) )

  4. #49
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.

  5. #50
    New Coder
    Join Date
    Aug 2012
    Posts
    65
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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.

  6. #51
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You need the forth one. I was missing the opening here: array_values(

  7. Users who have thanked Fou-Lu for this post:

    willscarlet (12-18-2012)

  8. #52
    New Coder
    Join Date
    Aug 2012
    Posts
    65
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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>

  9. #53
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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']; 



 
Page 4 of 4 FirstFirst ... 234

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •