Jump to content

PHP problem with mysql INSERT INTO


Bravat

Recommended Posts

I have problem with this code. It does absolutely nothing. When INSERT is over it should redirect to index.php but it does nothing. There is no error, when the submit is clicked the page just refresh itself and because of echo function it write all the values. What seems to be the problem (I going slightly mad :D )

 

<?php require_once("public/includes/session.php"); ?>
<?php require_once("public/includes/connection.php"); ?>
<?php require_once("public/includes/functions.php"); ?>
<?php	include_once("public/includes/form_functions.php");
	   include_once("public/includes/header.php");


if (isset($_POST['submit'])) { // Form has been submitted.
	$errors = array();


	$required_fields = array('nik', 'lozinka', 'ime', 'prezime', 'adresa', 'grad', 'postanskiBroj', 'fiskni', 'moblini', 'email');
	$errors = array_merge($errors, check_required_fields($required_fields, $_POST));
	$username = trim(mysql_prep($_POST['nik']));
	$password = trim(mysql_prep($_POST['lozinka']));
	$hashed_password = sha1($password);
	$ime = trim(mysql_prep($_POST['ime']));
	$prezime = trim(mysql_prep($_POST['prezime']));
	$adresa = trim(mysql_prep($_POST['adresa']));
	$grad = trim(mysql_prep($_POST['grad']));
	$postanskiBroj = trim(mysql_prep($_POST['postanskiBroj']));
	$fiskni = trim(mysql_prep($_POST['fiksni']));
	$moblini = trim(mysql_prep($_POST['mobilni']));
	$email = trim(mysql_prep($_POST['email']));

	echo $username . $hashed_password . $ime . $prezime . $adresa . $grad . $postanskiBroj . $fiskni . $moblini . $email;

	if ( empty($errors) ) {
		$query = " INSERT INTO `gume`.`korisnik` (`id`, `korisnicko_ime`, `lozinka`, `ime`, `prezime`, `adresa`, `grad`, `postanskiBroj`, `fiksni_telefon`, `mobilni_telefon`, `email`)
						  VALUES
						  (NULL, '$username', '$hashed_password', '$ime', '$prezime', '$adresa', '$grad', '$postanskiBroj', '$fiskni, $moblini', '$email' )";
		$result = mysql_query($query, $connection) or die(mysql_error);
		if ($result) {
			redirect_to("index.php");
		} else {
			$message = "The user could not be created.";
			$message .= "<br />" . mysql_error();
		}
	} else {
		if (count($errors) == 1) {
			$message = "There was 1 error in the form.";
		} else {
			$message = "There were " . count($errors) . " errors in the form.";
		}
	}
} else { // Form has not been submitted.
	$username = "";
	$password = "";
}
?>

<div id="telo">
   <div id="kreiranjeNaloga">
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<script src="SpryAssets/SpryValidationPassword.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationConfirm.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationPassword.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationConfirm.css" rel="stylesheet" type="text/css" />
<p>Polja sa * su obavezna</p>
<form action="new_user.php" method="post">
  <span id="sprytextfield1">
  <label>Korisnicko ime: </label>
  <input type="text" name="nik" id="nik"  size="40" value=""/>
  *<span class="textfieldMinCharsMsg">Korisnicko ime ne moze imati manje od 5 karaktera</span><span class="textfieldMaxCharsMsg">Korisnicko ime moze imati najvise 30 karaktera.</span></span><br />
  <span id="sprypassword1">
  <label>Lozinka:</label>
    <input type="password" name="lozinka" id="lozinka"  size="40" value=""/>
  *<span class="passwordMinCharsMsg">Sifra mora sadrzati najmanje 5 karaktera.</span><span class="passwordMaxCharsMsg">Sifra moze imati najvise 30 karaktera.</span></span> 

  <br />
  <span id="spryconfirm1">
  <label>Potvrdite lozinku:</label>
    <input type="password" name="password1" id="password1" size="40" value=""/>
  
  <span class="confirmRequiredMsg">*</span>Obe lozinke moraju da budu iste.</span>
  <br />
  <span id="sprytextfield2">
  <label>Ime:</label>
    <input type="text" name="ime" id="ime" size="40" value=""/>
  
  *
  </span>
  <br />
  <span id="sprytextfield3">
  <label>Prezima</label>
    <input type="text" name="prezime" id="prezime"size="40" value="" />
  *</span>
  <br />
  <span id="sprytextfield4">
  <label>Adresa:</label>
    <input type="text" name="adresa" id="adresa" size="40" value=""/>
    *
  
  </span>
  <br />
  <span id="sprytextfield7">
  <label>Grad:</label>
    <input type="text" name="grad" id="grad" size="40" value="" />
    *
  
  </span> <br />
  
  </span><span id="sprytextfield9">
  <label>Postanski Broj: </label>
    <input type="text" name="postanskiBroj" id="postanskiBroj" size="10" value=""/>
    *

  <span class="textfieldInvalidFormatMsg">Postanski broj nije pravilno upisan.</span></span><br />
  <span id="sprytextfield5">
  <label>Broj fiksnog telefona: </label>
  <input type="text" name="fiksni" id="Broj fiksnog telefona" size="40" value="" />
  *<span class="textfieldInvalidFormatMsg">Broj telefona nije pravilno upisan</span></span>
  <br />
  <span id="sprytextfield6">
  <label>Broj mobilnog telefona: </label>
  <input type="text" name="mobilni" id="mobilni" size="40" value=""  />
*<span class="textfieldInvalidFormatMsg">Broj telefona nije pravilno upisan</span></span><br />
  <span id="sprytextfield10">
  <label>Email:</label>
  <input type="text" name="email" id="email" size="40" value="" />
  *<span class="textfieldInvalidFormatMsg">Email adresa nija pravilno upisana.</span></span><br />
  <input name="submit" type="submit" id="submit" value="Kreiraj korisnika" />
</form> 

  </div>
</div>
<?php include("public/includes/footer.php"); ?>

 

Link to comment
Share on other sites

Well this is the header:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="stylesheets/public.css" rel="stylesheet"/>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div id="wrapper">
    <div id="header">
    <div id="headerWrapper">
    <div id="slikaHeader">
    <?php 
		$query = "SELECT slika FROM prodavnica";
		$result = mysql_query($query);
		$row = mysql_fetch_array($result);
?>
    <a href="index.php"><img src="<?php echo $row['slika'];?>"  /></a>
    </div> <!--Kraj na slikaHeader id-->
    <div id="loginHeader">
    <form action="login_public.php" method="post">
    <label>Korisnicko ime:</label>
    <input name="korisnicko_ime" type="text" />
    <br />
    <label>Lozinka:</label>
    <input name="lozinka" type="password" /> 
    <br />
    <label><a href="new_user.php">Kreiraj novog korisnika</a></label>
    <input type="submit" name="submit" value="Prijava"  style="float:right" />    
    </form>
    
    </div>
    </div>  <!--Kraj na headerWrapper id-->
    </div>  <!--Kraj na header id-->

 

connection.php

is just conn definition, and other includes are with out html.

 

I will try something. Hope it will work.

 

Link to comment
Share on other sites

None of the data is inserted. This is redirect_to function:

	function redirect_to( $location = NULL ) {
	if ($location != NULL) {
		header("Location: {$location}");
		exit;
	}
}

Also tried to move header.php after INSERT part. still won't work.

 

Link to comment
Share on other sites

I will bet that  your problem is here

 

$query = " INSERT INTO `gume`.`korisnik` (`id`, `korisnicko_ime`, `lozinka`, `ime`, `prezime`, `adresa`, `grad`, `postanskiBroj`, `fiksni_telefon`, `mobilni_telefon`, `email`)
						  VALUES
						  (NULL, '$username', '$hashed_password', '$ime', '$prezime', '$adresa', '$grad', '$postanskiBroj', '$fiskni, $moblini', '$email' )";

....

 

look here:

'$fiskni, $moblini'

 

that should make your INSERT to fail.... and because in your next line

$result = mysql_query($query, $connection) or die(mysql_error);

you are using the mysql_error() function incorrectly... the script just die... no error message at all

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.