Jump to content

[SOLVED] problem with inserting data in mysql database


aldm

Recommended Posts

I'm building one application for book salary in PHP. I have a HTML form with code:

<html>

<head>

<title>Nova knjiga</title>

</head>

<body>

<h1>Unos nove knjge</h1>

<br><br>

<form action="unos.php" method="POST">

ISBN:     

<input name="id" type="text">

<br><br>

Autor:     

<input name="autor" type="text">

<br><br>

Naziv:     

<input name="naziv" type="text">

<br><br>

Cijena:     

<input name="cij" type="text">

<br><br><br>

<input type="reset" value="Ponovni unos">     

<input type="submit" value="Unesi">

</form>

</body>

Code of unos.php file:

<?php

$id=$HTTP_POST_VARS["id"];

$autor=$HTTP_POST_VARS["autor"];

$naziv=$HTTP_POST_VARS["naziv"];

$cij=$HTTP_POST_VARS["cij"];

if(!$id || !$autor || !$naziv || !$cij){

echo 'Niste unijeli sve podatke';

echo '<br>Pokusajte ponovo';

exit;

}

@ $db=mysql_connect('localhost', 'root','');

if(!$db){

echo 'Greska prilikom prikljucenja na bazu';

echo 'Pokusajte ponovo';

exit;

}

mysql_select_db('knjige_db', $db);

$id=addslashes($id);

$autor=addslashes($autor);

$naziv=addslashes($naziv);

$cij=addslashes($cij);

$ubaci="insert into knjige values(".$id.",".$autor.",".$naziv.",".$cij.")";

mysql_query($ubaci);

mysql_close($db);

echo 'Knjiga uspjesno dodana';

?>

When I fill the field and click yes, there is no new record in database.

Why??? :(

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.