sid0972 Posted December 31, 2012 Share Posted December 31, 2012 hey, newbie here i am writing a code to insert some values in database, it actually worked in the afternoon, but when i started the system in the night it magically stopped working. First, i am taking the value in a text box, then forwarding it to a file to be stored in a variable, then calling a function (which is in yet another file) which stores the values in the database. the code is here text box <form action="add.php" method="post"> <center><input type="text" name="abc" size="9" maxlength="9"> <br><br> <input type="submit" value="Save"> to hold "abc" in a variable $abc=$_POST['abc']; add_abc($abc); to insert it in a database <?php session_start(); require_once('db_fns.php'); function add_abc($abc) { $valid_user = $_SESSION['valid_user']; $conn = db_connect(); if ($result && ($result->num_rows>0)) { throw new Exception('already exists.'); } if (!$conn->query("insert into scores (username,abc) values ('".$valid_user."', '".$abc."')")) { throw new Exception('could not be inserted.'); } else { echo "successful";} return true; can anyone please tell me whats wrong here?? Quote Link to comment https://forums.phpfreaks.com/topic/272551-cant-insert-values-in-database-wrong-code/ Share on other sites More sharing options...
sid0972 Posted December 31, 2012 Author Share Posted December 31, 2012 (edited) and these are the error i get on file abc.php PHP Notice: Undefined index: abc in /var/www/work/fns/add_oc_middle.php on line 5 PHP Notice: Undefined index: valid_user in /var/www/work/fns/add.php on line 13 PHP Notice: Undefined variable: result in /var/www/work/fns/add_oc_middle.php on line 16 PHP Fatal error: Uncaught exception 'Exception' with message 'Score could not be inserted.' in /var/www/work/fns/add_oc_middle.php:22 Stack trace: #0 /var/www/work/fns/add_oc_middle.php(7): add_abc(NULL) #1 {main} thrown in /var/www/work/fns/add.php on line 22 Edited December 31, 2012 by sid0972 Quote Link to comment https://forums.phpfreaks.com/topic/272551-cant-insert-values-in-database-wrong-code/#findComment-1402396 Share on other sites More sharing options...
sid0972 Posted January 1, 2013 Author Share Posted January 1, 2013 can anyone please tell me whats wrong with my code??? Quote Link to comment https://forums.phpfreaks.com/topic/272551-cant-insert-values-in-database-wrong-code/#findComment-1402562 Share on other sites More sharing options...
Jessica Posted January 1, 2013 Share Posted January 1, 2013 Sounds like the form isn't being posted. You need to do some debugging on your own, especially since you have only shown us snippets of the code. Walk through it and check the values at every step you can find, until you find it doesn't match your assumptions. Quote Link to comment https://forums.phpfreaks.com/topic/272551-cant-insert-values-in-database-wrong-code/#findComment-1402563 Share on other sites More sharing options...
sid0972 Posted January 14, 2013 Author Share Posted January 14, 2013 (edited) i tried but to no avail if you want i can post the whole code here itself... tried to google also, nothing came up Edited January 14, 2013 by sid0972 Quote Link to comment https://forums.phpfreaks.com/topic/272551-cant-insert-values-in-database-wrong-code/#findComment-1405575 Share on other sites More sharing options...
sid0972 Posted January 19, 2013 Author Share Posted January 19, 2013 well i found the solution.... i studied the basics of php and mysql thoroughly this time and got through it Quote Link to comment https://forums.phpfreaks.com/topic/272551-cant-insert-values-in-database-wrong-code/#findComment-1406977 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.