Error trying to register data in the database (mysql) via PHP

1

I'm trying to insert some data into the database via php, but this is returning me error, apparently this is connecting, I can not find an error actually do not know much about php, I've been following tutorial on the internet, p>

$(function(){

		 		var atual_fs, next_fs
		 		var formulario = $('form[name=formulario]');

		 		$('.btn-next1').on('click',function (evento) {

		 			if ($('select , .range').valid()) {
			 			atual_fs = $(this).parent().parent().parent();
			 			next_fs = $(this).parent().parent().parent().next();

			 			atual_fs.hide(500);
			 			next_fs.show(500);				
		 			}else {
		 			}
		 			evento.preventDefault();

		 		});

		 		$('.btn-next').on('click',function (evento){

		 			var array = formulario.serializeArray();

		 			$.each(array, function(i, val){
		 				console.log($.param(array));
		 			});

		 			if ($('#name , #email , #telefone').valid()) {
		 				$.ajax({
		 					method: 'post',
		 					url: 'cadastrar.php',
		 					data: {cadastrar: 'sim', campos: array},
		 					dataType: 'json',
		 					beforeSend: function(){
		 						$('#formulario').html('<div class="aguarde"><p> Aguarde estamos requisitando os planos!</p></div>')
		 					},
		 					success: function(valor){
		 						if(valor.erro == 'sim'){
		 							$('#formulario').html('<div class="erros"><p>'+valor.getErro+'</p></div>');
		 						}else{
		 							$('#formulario').html('<div class="ok"><p>'+valor.msg+'</p></div>');
		 						}
		 					}
		 				});

		 			}else {
		 				
		 			}
		 			evento.preventDefault();

		 		});

		});
<?php 

	sleep(2);
	include_once 'config.php';

	if(isset($_POST['cadastrar']) && $_POST['cadastrar'] == 'sim'):

		$novos_campos = array();
		$campos_post = $_POST['campos'];
		foreach($campos_post as $indice => $valor){
			$novos_campos[$valor['name']] = $valor['value'];
		}

		if(!strstr($novos_campos['email'], '@')){
			$respostas['erro'] = 'sim';
			$respostas['getErro'] = 'E-mail Invalido.';		
		}else{
			$respostas['erro'] = 'nao';
			$inserir_banco = $pdo->prepare("INSERT INTO 'lead' SET nome = ?, email = ?, telefone = ?, desejo = ?, valor = ?, valores = ?");
			$inserir_sql = array(
				$novos_campos['name'],
				$novos_campos['email'],
				$novos_campos['telefone'],
				$novos_campos['desejo'],
				$novos_campos['valor'],
				$novos_campos['valores']
			);
			if($inserir_banco->execute($array_sql)){
				$respostas['erro'] = 'nao';
				$respostas['msg'] = 'Cliente Cadastrado';
			}else{
				$respostas['erro'] = 'sim';
				$respostas['getErro'] = 'Erro ao cadastrar.';	
			}
		}

		echo json_encode($respostas);
	endif;
 ?>

config.php

<?php $pdo = new PDO('mysql:host=localhost;dbname=simulador','usuario','senha'); ?>
    
asked by anonymous 29.08.2016 / 16:05

1 answer

2

Switch:

$inserir_banco->execute($array_sql);

By:

$inserir_banco->execute($inserir_sql);

I do not know if you noticed but $array_sql was not assigned anywhere in your code snippet.

    
29.08.2016 / 17:04