Jump to content

problem with the text fields


nicedad

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.