Page 1 of 1

Redirect after mysql insert

Posted: 20 Aug 2016, 21:30
by mluci12
Please help me! I have this code but don't redirect to submit2.WHY?

Code: Select all

<!DOCTYPE html>
<?php
require('layout-submit1.php');
header('Content-type: text/html; charset=utf-8');
session_start();

$mesaj = '';  

  if(isset($_POST['an']) && strlen($_POST['an'])>0) $s = $_POST['an']; {
  // Se filtreaza datele pt. eliminare posibile spatii exterioare si tag-uri
  $_POST = array_map("trim", $_POST);
  $_POST = array_map("strip_tags", $_POST);

  // Se verifica daca "magic_quotes_gpc()" este setat ON
  // Daca e ON, se aplica stripslashes() pentru a nu se adauga de 2 ori '\' cand va fi aplicat "mysql_real_escape_string()"
  if(get_magic_quotes_gpc()) { $_POST = array_map("stripslashes", $_POST); }

\
  
  // Verifica daca adresa de e-mail scrisa corespunde formatului unei adrese de e-mail
 
   if(isset($_POST['an']) && strlen($_POST['an'])>0) $s = $_POST['an'];
  else $eroare[] = 'Select type';

  // Verifica daca a fost selectata o valoare pt. 'studii'
  if(strlen($_POST['manufacturer'])>0) $ma = $_POST['manufacturer'];
  else $eroare[] = 'Selectati servicii';

  // Verifica daca a fost bifat buton pt. 'stare civila'
  

  // Daca nu exista nici un mesaj de eroare, filreaza datele cu mysql_real_escape_string() si le adauga in baza de date
  // Altfel, in cazul vreunei erori, adauga in variabila $mesaj
  if (!isset($eroare)) {
    include('conn.php');         // Include fisierul pt. conectare-selectare baza de dat

    // Se aplica functia de filtrare mysql_real_escape_string()
    
       $marca = $_POST['manufacturer'];
        $locuri = $_POST['locuri'];
         $an = $_POST['an'];
  
    // Acum se adauga mai in siguranta aceste date in MySQL
    $sql = "INSERT INTO `anunt1` (`marca` ,`locuri`, `an`  ) VALUES ('$marca', '$locuri',  '$an' )";
  if (mysql_query($sql, $conn)) {
 header('Location: autobelgia.ro/submit2.html/');
  
  }
    else $mesaj = '<font color="red">Datele nu au putut fi adaugate '. mysql_error(). '</font>';

  mysql_close($conn);
  }
  else $mesaj = '<font color="red">'. implode('<br />', $eroare). '</font>';
}

echo $mesaj;
?>


	
							<div class="col-lg-9 col-md-8 col-sm-7 col-xs-6">
						<div class="b-submit__main">
							<header class="s-headerSubmit s-lineDownLeft wow zoomInUp" data-wow-delay="0.5s">
								<h2 class="">Adauga detaliile vehiculului</h2>
							</header>
							<form class="s-submit clearfix" action="" method="POST">
								<div class="row">
									<div class="col-md-6 col-xs-12">
										<div class="b-submit__main-element wow zoomInUp" data-wow-delay="0.5s">
											<label>Marca <span>*</span></label>
											<div class='s-relative'>
												<select name="manufacturer" id="manufacturer" class="m-select">
													<option value="">Selecteaza</option>
												</select>
												<span class="fa fa-caret-down"></span>
											</div>
										</div>
										<div class="b-submit__main-element wow zoomInUp" data-wow-delay="0.5s">
											<label>Anul fabricatiei<span>*</span></label>
											<div class='s-relative'>
												<select class="m-select" name="an" id="an">
													<option value="0" selected="selected">An min</option>
											<option value="2016">2016</option>
											<option value="2015">2015</option>
											<option value="2014">2014</option>
											<option value="2013">2013</option>
											<option value="2012">2012</option>
														<option value="2011">2011</option>
										<option value="2010">2010</option>
										<option value="2009">2009</option>
												<option value="2008">2008</option>
													<option value="2007">2007</option>
												<option value="2006">2006</option>
																<option value="2005">2005</option>
											<option value="2004">2004</option>
											<option value="2003">2003</option>
										<option value="2002">2002</option>
									<option value="2001">2001</option>
										<option value="2000">2000</option>
									<option value="1999">1999</option>
												</select>
												<span class="fa fa-caret-down"></span>
											</div>
										</div>
										<div class="b-submit__main-element wow zoomInUp" data-wow-delay="0.5s">
											<label>Numar de locuri <span>*</span></label>
											<div class='s-relative'>
												<select class="m-select" name="locuri" id"locuri">
													<option value="oricare">oricare</option>
													<option value="2">2</option>
													<option value="3">3</option>
													<option value="4">4</option>
													<option value="5">5</option>
													<option value="6">6</option>
													<option value="7">7</option>
													<option value="altele">Altele</option>
												</select>
												<span class="fa fa-caret-down"></span>
											</div>
										</div>
										<div class="b-submit__main-element wow zoomInUp" data-wow-delay="0.5s">
											<label>Numar viteze <span>*</span></label>
											<div class='s-relative'>
												<select class="m-select" name="select4">
													<option value="5">5</option>
													<option value="6">6</option>
												</select>
												<span class="fa fa-caret-down"></span>
											</div>
										</div>
										<div class="b-submit__main-element wow zoomInUp" data-wow-delay="0.5s">
											<label>Transmisie <span>*</span></label>
											<div class='s-relative'>
												<select class="m-select" name="select5">
													<option value="0">Selecteaza</option>
													<option value="oricare">Oricare</option>
													<option value="fata">Fata</option>
													<option value="spate">Spate</option>
													<option value="4x4(automat)">4x4(automat)</option>
													<option value="4x4(manual)">4x4(manual)</option>

												</select>

Redirect after mysql insert

Posted: 21 Aug 2016, 05:23
by Admin
Hello,
The code mysql_query($sql, $conn) is incorrect. Maybe the script it uses MySQLi; in this case you should put: $conn->query($sql).
Also, delete the: mysql_close($conn); because it generate error if the mysql connection is with mysqli.