nicedad Posted September 12, 2015 Share Posted September 12, 2015 Hello buddies, I'm trying to create a form through wich one can add entries into DB. unfortunately, it works only with the first two text fields (Name, Geburtstag) and when I add additional field (Kontaktdetails) It won't work , when I get rid of the last one it functions greate. even though the code seems to me ok.what's the issue here. thanks in advance here is the insert.php <table width="300" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td><form name="form1" method="post" action="insert_ac.php"> <table width="100%" border="0" cellspacing="1" cellpadding="3"> <tr> <td colspan="3"><strong>Insert Data Into mySQL Database </strong></td> </tr> <tr> <td width="71">Name</td> <td width="6">:</td> <td width="301"><input name="name" type="text" id="name"></td> </tr> <tr> <td width="71">Geburtstag</td> <td width="6">:</td> <td width="301"><input name="Geburtstag" type="text" id="Geburtstag"></td> </tr> <tr> <td width="71">Kontakdetails</td> <td width="6">:</td> <td width="301"><input name="kont" type="text" id="kont"></td> </tr> <tr> <td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form> </td> </tr> </table> insert_ac.php <?php error_reporting(0); $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test_db"; $tbl_name="worker3"; // Table name mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $name=$_POST['name']; $geburtstag=$_POST['Geburtstag']; $kontakdetails=$_POST['kont']; $sql="INSERT INTO $tbl_name(name, Geburtstag, kont) VALUES('$name', '$geburtstag', '$kontakdetails')"; $result=mysql_query($sql); if($result){ echo "Successful"; echo "<BR>"; echo "<a href='insert.php'>Back to main page</a>"; } else { echo "ERROR"; } ?> <?php mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
.josh Posted September 12, 2015 Share Posted September 12, 2015 At face value the code above looks okay. If it's working without the 3rd field, my first guess is you don't have a column named "kont" in your database table (e.g. it doesn't exist, not spelled the same, etc.) or maybe it's not the right field type (e.g. you made it a date or int type and it's supposed to be text, or maybe you set it to be a certain length e.g. varchar(10) but attempting to put a 20 char value into it). Do you have error reporting turned on? Are you getting an error(s)? Quote Link to comment Share on other sites More sharing options...
nicedad Posted September 12, 2015 Author Share Posted September 12, 2015 Hi joch, you ware right, the name of a column war different. It took me the entire day. thanks a lot. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 12, 2015 Share Posted September 12, 2015 Had you checked for errors you could have saved yourself a day. if($result){ echo "Successful"; echo "<BR>"; echo "<a href='insert.php'>Back to main page</a>"; } else { die (mysql_error()); } Quote Link to comment Share on other sites More sharing options...
nicedad Posted September 13, 2015 Author Share Posted September 13, 2015 Barand, soved the issue. thanks a lot. Quote Link to comment 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.