Jump to content
nicedad

problem with the text fields

Recommended Posts

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();
?>

Share this post


Link to post
Share on other sites

 

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)?

Share this post


Link to post
Share on other sites

Hi joch,

you ware right, the name of a column war different. It took me the entire day.

 

thanks a lot.

Share this post


Link to post
Share on other sites

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());
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.