Jump to content

[SOLVED] problem with inserting data in mysql database


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??? :(

 

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.