aldm Posted August 14, 2009 Share Posted August 14, 2009 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??? Link to comment https://forums.phpfreaks.com/topic/170292-solved-problem-with-inserting-data-in-mysql-database/ Share on other sites More sharing options...
mikesta707 Posted August 14, 2009 Share Posted August 14, 2009 try using $_POST[] instead of $HTTP_POST_VARS[] Link to comment https://forums.phpfreaks.com/topic/170292-solved-problem-with-inserting-data-in-mysql-database/#findComment-898283 Share on other sites More sharing options...
aldm Posted August 14, 2009 Author Share Posted August 14, 2009 Problem is solved by changing line $ubaci="insert into knjige values(".$id.",".$autor.",".$naziv.",".$cij.")"; with: $ubaci="insert into knjige values('$id','$autor','$naziv','$cij')"; Thank for help, anyway Link to comment https://forums.phpfreaks.com/topic/170292-solved-problem-with-inserting-data-in-mysql-database/#findComment-898293 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.