cleary1981 Posted July 21, 2008 Share Posted July 21, 2008 Can anyone tell me where i have went wrong here? when I submit the database isn't updated. <form id=addCompany action="addCompany.php" method="POST"> <label for="accno">Account Number</label> <input type = "text" value = "" name = "accno" id = "accno"></br> <label for="compName">Company Name</label> <input type = "text" value = "" name = "compName" id = "compName"></br> <label for="contact">Contact Name</label> <input type = "text" value = "" name = "contact" id = "contact"></br> <label for="add1">Address</label> <input type = "text" value = "" name = "add1" id = "add1"></br> <input type = "text" value = "" name = "add2" id = "add2"></br> <label for="town">Town/City</label> <input type = "text" value = "" name = "town" id = "town"></br> <label for="county">County</label> <input type = "text" value = "" name = "county" id = "county"></br> <label for="pcode">Post Code</label> <input type = "text" value = "" name = "pcode" id = "pcode"></br> <label for="tel">Telephone No.</label> <input type = "text" value = "" name = "tel" id = "tel"></br> <input type = "submit" value = "Submit"> <?php if($_POST['submit']) { require "config.php"; // database connection details //convert all the posts to variables: $accno = $_POST['accno']; $compName = $_POST['compName']; $contact = $_POST['contact']; $add1 = $_POST['add1']; $add2 = $_POST['add2']; $town = $_POST['town']; $county = $_POST['county']; $pcode = $_POST['pcode']; $tel = $_POST['tel']; //Insert the values into the correct database with the right fields $result=MYSQL_QUERY("INSERT INTO company VALUES ('$accno', '$compName', '$contact', '$add1', '$add2', '$town', '$county', '$pcode', '$tel')"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/115813-solved-using-post-to-update-mysql-db/ Share on other sites More sharing options...
samshel Posted July 21, 2008 Share Posted July 21, 2008 //Insert the values into the correct database with the right fields $result = mysql_query("INSERT INTO company VALUES ('$accno', '$compName', '$contact', '$add1', '$add2', '$town', '$county', '$pcode', '$tel')") or die (mysql_error()); try this. Quote Link to comment https://forums.phpfreaks.com/topic/115813-solved-using-post-to-update-mysql-db/#findComment-595370 Share on other sites More sharing options...
cleary1981 Posted July 21, 2008 Author Share Posted July 21, 2008 tried that. It didnt make anydifference. Quote Link to comment https://forums.phpfreaks.com/topic/115813-solved-using-post-to-update-mysql-db/#findComment-595372 Share on other sites More sharing options...
samshel Posted July 21, 2008 Share Posted July 21, 2008 <input type = "submit" value = "Submit" name="submit"> Quote Link to comment https://forums.phpfreaks.com/topic/115813-solved-using-post-to-update-mysql-db/#findComment-595373 Share on other sites More sharing options...
cleary1981 Posted July 21, 2008 Author Share Posted July 21, 2008 that didnt work either. Quote Link to comment https://forums.phpfreaks.com/topic/115813-solved-using-post-to-update-mysql-db/#findComment-595376 Share on other sites More sharing options...
samshel Posted July 21, 2008 Share Posted July 21, 2008 <?php //try debugging here.... var_dump($_POST); if($_POST['submit']) { require "config.php"; // database connection details //convert all the posts to variables: $accno = $_POST['accno']; $compName = $_POST['compName']; $contact = $_POST['contact']; $add1 = $_POST['add1']; $add2 = $_POST['add2']; $town = $_POST['town']; $county = $_POST['county']; $pcode = $_POST['pcode']; $tel = $_POST['tel']; //Insert the values into the correct database with the right fields $result=MYSQL_QUERY("INSERT INTO company VALUES ('$accno', '$compName', '$contact', '$add1', '$add2', '$town', '$county', '$pcode', '$tel')"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/115813-solved-using-post-to-update-mysql-db/#findComment-595379 Share on other sites More sharing options...
ignace Posted July 21, 2008 Share Posted July 21, 2008 are you working with multiple database connections? cause if anyone would care to read a manual they would notice that mysql_query() actually have 2 parameters, so try adding the db connection resource (optional is only to be used when you in no way are able to write the parameter): $query = "INSERT INTO .."; $result = mysql_query($query, $dbConnection); if (!$result) die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/115813-solved-using-post-to-update-mysql-db/#findComment-595380 Share on other sites More sharing options...
cleary1981 Posted July 21, 2008 Author Share Posted July 21, 2008 What do you mean multiple database connections? I am querying one table in one db. I have seen examples of mysql_query used in this way. Quote Link to comment https://forums.phpfreaks.com/topic/115813-solved-using-post-to-update-mysql-db/#findComment-595385 Share on other sites More sharing options...
cleary1981 Posted July 21, 2008 Author Share Posted July 21, 2008 is there a better way of doing this? Quote Link to comment https://forums.phpfreaks.com/topic/115813-solved-using-post-to-update-mysql-db/#findComment-595386 Share on other sites More sharing options...
samshel Posted July 21, 2008 Share Posted July 21, 2008 the way is correct, make sure the execution goes in the if($_POST['submit']) condition... and then print debug statements inside the condition. Quote Link to comment https://forums.phpfreaks.com/topic/115813-solved-using-post-to-update-mysql-db/#findComment-595387 Share on other sites More sharing options...
cleary1981 Posted July 21, 2008 Author Share Posted July 21, 2008 the output to that is array(9) { ["accno"]=> string(4) "uhuh" ["compName"]=> string(4) "uhuh" ["contact"]=> string(4) "uhuh" ["add1"]=> string(4) "uhuh" ["add2"]=> string(4) "uhuh" ["town"]=> string(4) "uhuh" ["county"]=> string(4) "uhuh" ["pcode"]=> string(4) "uhuh" ["tel"]=> string(4) "uhuh" } Quote Link to comment https://forums.phpfreaks.com/topic/115813-solved-using-post-to-update-mysql-db/#findComment-595388 Share on other sites More sharing options...
samshel Posted July 21, 2008 Share Posted July 21, 2008 as you can see the value of 'submit' is not being passed here..so if you name the button as "submit" it should come here and the code in the if condition should be executed... Quote Link to comment https://forums.phpfreaks.com/topic/115813-solved-using-post-to-update-mysql-db/#findComment-595391 Share on other sites More sharing options...
cleary1981 Posted July 21, 2008 Author Share Posted July 21, 2008 yeah that worked had left " out of the code. Quote Link to comment https://forums.phpfreaks.com/topic/115813-solved-using-post-to-update-mysql-db/#findComment-595394 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.