registering php data in database SQL server 2008

0

I have a question ... I do not know if I'm putting the code correctly, I'm a beginner in php and I need a help ... I already managed to do the form that I have to write to MySql ... but now I'm messing around in a SQL Server and I can not get it to write the data ... I do not know if something is missing ... I do not know ... but I needed a help ... come on ...

conex.php

<?
$con = mssql_connect("000.000.000.00,1111", "user", "senha");
mssql_select_db("BANCO",$con);
?>

This is the connection I'm making ... until there's no problem ...

This is the file that writes:

grava.php

<?php require_once('Connections/conex.php'); ?>
<?php
$CPF =                       $_POST['CPF'];
...
$TITULO_3 =                  $_POST['TITULO_3'];

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "cpf-form")) {
  $insertSQL = sprintf("INSERT INTO BASE_EY (
  CPF,
  ...
  TITULO_3) VALUES (
  $CPF,
  ...
  $TITULO_3)");

  $insertGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>

and this is the form ...

form.php

<form action="testego.php" id="camposform" method="post" name="cpf-form" target="_self">
      <div class="medium-8 columns">
        <label for="NOME">Nome<span class="red-red">*</span></label>
        <input name="NOME" id="NOME" value="" type="text" required="required">
      </div>
      <div class="medium-4 columns">
        <label for="SEXO">Sexo<span class="red-red">*</span></label>
        <select name="SEXO" id="SEXO" value="" required="required">
          <option selected="selected" disabled="disable">-- Selecione --</option>
          <option>MASCULINO</option>
          <option>FEMININO</option>
        </select>
      </div>

...

      <div class="medium-2 columns">
        <label for="ANO_GRADUACAO">Ano da Graduação<span class="red-red">*</span></label>
        <input name="ANO_GRADUACAO" id="ANO_GRADUACAO" value="" type="text" required="required">
      </div>
      <div class="div-fix"><input type="submit" class="button medium-4 columns clearfix"></div>
       <input type="hidden" name="MM_insert" value="cpf-form" />
    </form>

No error appears the code goes straight as if everything is ok ... but when I check the bank ... NOTHING ... I do not know where I'm going wrong ... does anyone give me a light ?? Plz: D

-------------------------------------------- ------- V-Edited-V ----------------------------------------------- ----

I made some changes in code. according to the instructions ... but it did not work very well ... it happened the same thing jumps straight as if it had registered but n registration ... Cod is like this ...

Connection file

conex.php

<?
$con = mssql_connect("000.000.000.00,5033", "user", "senha");
mssql_select_db("banco",$con);
if( $con === false )
      { die( FormatErrors( sqlsrv_errors() ) ); }
?>

cadastra.php

<?php require_once('Connections/conex.php'); ?>
<?php
$CPF =                       $_POST['CPF'];
...
$TITULO_3 =                  $_POST['TITULO_3']; //crm 02 OBS

  $insertSQL = mssql_execute("INSERT INTO BASE_EY (
  CPF,
  ...
  TITULO_3) VALUES (
  $CPF,
  ...
  $TITULO_3)");

  $insertGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header("Location: $insertGoTo");
mssql_free_result($insertSQL)
?>

Any more light around? rsrs

    
asked by anonymous 29.07.2014 / 00:35

2 answers

1

Your code was missing the mssql_query () function that is responsible for running the Query. To resolve this line:

mssql_query('INSERT INTO ....') or die(mssql_get_last_message());

When working with the database functions (mssql_, mysql_, pg_, etc.), remember to call the function that displays the error in the case mssql_get_last_message () , in new projects preferred to PDO or sqlsrv

    
29.07.2014 / 19:22
1

To insert data into SQLSRV, it is more annoying than MySQL.

Here is an example of how SQLSRV should be used:

$sql = "INSERT INTO [RDO].[dbo].[funcionarios] (usuario, email, senha) VALUES (?,?,?)";

$params = array($nome, $email, $senha);

$stmt = @sqlsrv_query( $conn, $sql, $params);
    
30.09.2014 / 14:09