Groen Posted December 17, 2010 Share Posted December 17, 2010 I first created it on my computer and tested it locally and everything worked but now I have uploaded it to a webserver and changed everything according to what I need to like the connection and password. those required details in mysql_connect("host","user","password") that has been changed to what they should be but it won't allow me to add data from input fields in the data base. It does not give an error or anything just a blank say example I have this html form <form action="test.php" enctype="multipart/form-data" method="post"> <input type="text" name="datatoAdd"> <input type="submit"> </form> and on the page test.php I have $con = mysql_connect("host","user","password"); mysql_select_db("database", $con); mysql_query("INSERT INTO table (fields) VALUES ('values')"); mysql_close($con); then there is no data added to the database I also checked if it actually connects it does. I also can't view data that I manually added to the table with phpMyAdmin. Quote Link to comment https://forums.phpfreaks.com/topic/222004-does-not-insert-data-into-table/ Share on other sites More sharing options...
shlumph Posted December 17, 2010 Share Posted December 17, 2010 Make sure PHP errors are turned on and change your code to: $con = mysql_connect("host","user","password") or die(mysql_error()); mysql_select_db("database", $con) or die(mysql_error()); mysql_query("INSERT INTO table (fields) VALUES ('values')") or die(mysql_error()); And then let us know what the errors are. At glance, it looks like multiple things are wrong, so we gotta go through them one by one. Quote Link to comment https://forums.phpfreaks.com/topic/222004-does-not-insert-data-into-table/#findComment-1148766 Share on other sites More sharing options...
Groen Posted December 17, 2010 Author Share Posted December 17, 2010 Ok Let me give you the code I use I only copied the sql part the others are just declaring the variables. but this as it is here work when I test it offline on the server I have on my computer but not on the webserver I use. $con = mysql_connect("host","user","password");if (!$con) { echo "The server is currently down try again later!"; } mysql_select_db("database", $con); $cExists = mysql_query("SELECT * FROM club"); //Here I check if the given data is not yet entered in the table $Continue = true; while ($row = mysql_fetch_array($cExists)) { if (strtolower($row["cName"]) == strtolower($cName)) { $Continue = false; break; } } mysql_close($con); //Here it adds the data if the given data does not exists if ($Continue == false) { incomplete(); } else if ($Continue == true) { $con = mysql_connect("host","user","password");if (!$con) { echo "The server is currently down try again later!"; } mysql_select_db("database", $con); mysql_query("INSERT INTO club (mName, mEmail, mNumber, Password, cName, cNumber, cType, cCity, cSuburb, cStreet, cGPS) VALUES ('". $mName ."', '". $mEmail ."', '". $mNumber ."', '". $mPassword ."', '". $cName ."', '". $cNumber ."', '". $cType ."', '". $cCity ."', '". $cSuburb ."', '". $cStreet ."', '". $cGPS ."')"); mysql_close($con); } I do not know can it be file permissions that need to be set? Here is the website check it out then you will see what I mean. www.wheretoclub.co.cc/list.php Try and list something then to login in it does not want you to. Quote Link to comment https://forums.phpfreaks.com/topic/222004-does-not-insert-data-into-table/#findComment-1148790 Share on other sites More sharing options...
shlumph Posted December 17, 2010 Share Posted December 17, 2010 Maybe the database schema is different. It's hard to tell without seeing the errors Quote Link to comment https://forums.phpfreaks.com/topic/222004-does-not-insert-data-into-table/#findComment-1148807 Share on other sites More sharing options...
Groen Posted December 18, 2010 Author Share Posted December 18, 2010 Hello again my script now adds the data but I have a problem with the login part here is the script but what it does it just "skips" a part <?php //echo $_POST["cName"]; $con = mysql_connect("host","user","password"); if(!mysql_select_db("database", $con)) { echo mysql_error(); } $cDetails = mysql_query("SELECT * FROM club WHERE cName = \"". $_POST["cName"] ."\" "); while($row = mysql_fetch_array($cDetails)) { //Here it seems to skip or something eventhough the data entered that needs no be checked is correct! if ($row['Password'] == $_POST["mPassword"]) { setcookie("user",$_POST["cName"],time()+3600); echo "<script type='text/javascript' language='javascript'> location.replace('manage.php'); </script>"; } //Even if I enter the correct data it keeps on doing this part! else { echo "<script type='text/javascript' language='javascript'> alert('You have entered incorrect details!'); location.replace('login.php'); </script>"; } } mysql_close($con); ?> Mod edit: . . . tags added. Quote Link to comment https://forums.phpfreaks.com/topic/222004-does-not-insert-data-into-table/#findComment-1148953 Share on other sites More sharing options...
shlumph Posted December 20, 2010 Share Posted December 20, 2010 Hello again my script now adds the data Great! What was wrong? I have a problem with the login part here is the script but what it does it just "skips" a part Which part does it skip? What data are you inputting and what is the expected result? Quote Link to comment https://forums.phpfreaks.com/topic/222004-does-not-insert-data-into-table/#findComment-1149408 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.