SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict Mainer82's Avatar
    Join Date
    Aug 2003
    Location
    Maine, USA
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MSSQL form conversion from MySQL to MSSQL

    I have a form that I use on MySQL/PHP and need to convert it to MSSQL/PHP. This is the area that I'm struggling with, what am I doing wrong?
    No error, when I submit the form it just reloads, not submitting any data to the DB.

    PHP Code:
    <?php
                
    if (isset($_POST['Vendor_ID'])) { //Check for a field that is mandatory to do the inserted
                
    $Vendor_ID sqlsrv_escape_string($_POST['Vendor_ID']);
                
    $ProductName_ID sqlsrv_escape_string($_POST['ProductName_ID']);
                
    $version sqlsrv_escape_string($_POST['version']);
                
    $serial sqlsrv_escape_string($_POST['serial']);
                
    $ProductKey sqlsrv_escape_string($_POST['ProductKey']);
                
    $Department_ID sqlsrv_escape_string($_POST['Department_ID']);
                
    $ownername sqlsrv_escape_string($_POST['ownername']);
                
    $Computer sqlsrv_escape_string($_POST['Computer']);
                
    $Comments sqlsrv_escape_string($_POST['Comments']);
                
    $Acquired sqlsrv_escape_string($_POST['Acquired']);
                
    $Retired sqlsrv_escape_string($_POST['Retired']);
            
    $sql "INSERT INTO dbo.KeyList_detail (
                    Vendor_ID,
                    ProductName_ID,
                    version,
                    serial,
                    ProductKey,
                    Department_ID,
                    Owner,
                    Computer,
                    Comments,        
                    Acquired,
                    Retired)
                        VALUES(
                        
    $Vendor_ID,
                        
    $ProductName_ID,
                        
    $version,
                        
    $serial,
                        
    $ProductKey,
                        
    $Department_ID,
                        
    $Owner,
                        
    $Computer,
                        
    $Comments,                    
                        
    $Acquired,
                        
    $Retired)";
            
    sqlsrv_query($con,$sql);
            if (
    sqlsrv_query($con$sql)) {
                echo 
    '<strong><em>Your data has been submitted</em></strong><br /><br />';
                    } else {
                echo 
    '<p>Error adding submitted info: ' sqlsrv_error(). '</p>';
            }
            }
            
    ?>
            
            <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    Get to know the man behind the screen

  2. #2
    SitePoint Addict Mainer82's Avatar
    Join Date
    Aug 2003
    Location
    Maine, USA
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this in the wrong section?
    Get to know the man behind the screen

  3. #3
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,223
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    First off, you are calling the INSERT statement twice, so that's not good. Second, look into http://php.net/manual/en/function.ms...st-message.php, and Last, try putting a var_dump($sql); before your sqlsrv_query and paste that into SSMS to ensure it works there first.

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,223
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    As a second thought, I bet the var_dump copy and paste into SSMS will fail, because you don't have single quotes around a few of your columns in the INSERT query that look to be strings. My guess, is that is your issue.

  5. #5
    SitePoint Addict Mainer82's Avatar
    Join Date
    Aug 2003
    Location
    Maine, USA
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I added the ' quotes and the same thing is happening.
    Get to know the man behind the screen

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,223
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    What was the output of your var_dump($sql) call and were you able to copy and paste that query into SSMS and verify it runs?


Bookmarks

Posting Permissions

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