Welcome to WebmasterWorld Guest from 54.160.163.163

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

insert into mysql problem

     

spirit

8:59 pm on Nov 29, 2002 (gmt 0)

5+ Year Member



This one is tooooo simple form me to understand ;)

The problem is..
when I insert some text in form field and press the submit button I recieve a message from -insert.php - "record added", but when I look in - tasteTable - only (auto_increment) "id" field has changed but there is no text in -testField- that I put in form field.

......why?

tnx!

insert_form.html code:

<html>
<head>
<title>Insert Form</title>
</head>
<body>
<form action="insert.php" METHOD="post">
<p>text to add:<br>
<input type=text name="testfield" size=30 value="">
<p><input type="submit" name="submit" value="Insert Record"><p>
</form>
</body>
</html>
-------------------
insert.php code:

<?
$conn = mysql_connect("localhost", "myusername", "mypass");
mysql_select_db("contactDB",$conn);
$sql = "INSERT INTO testTable values ('', '$testField')";
if (mysql_query($sql, $conn)) {
echo "record added!";
} else {
echo "something went wrong";
}
?>

Birdman

9:59 pm on Nov 29, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World!
Try removing the value="" out of the input tag.

Birdman

mavherick

10:11 pm on Nov 29, 2002 (gmt 0)

10+ Year Member



You might want to change $testField by $testfield in your insert.php

I'm not sure but if i remember well, it's case sensitive.

mavherick

jatar_k

10:17 pm on Nov 29, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



good eye mavherick,

That will also only work if register_globals is on, otherwise you will have to do $HTTP_POST_VARS["testfield"] or $_POST["testfield"], depending on your version of php.

lars stecken

9:15 am on Nov 30, 2002 (gmt 0)

10+ Year Member



You should switch your error reporting to E_ALL in the php.ini. This makes it easy to spot those minor mistakes since PHP will trow out a Notice saying that one of your variables is not defined!
Don't forget to switch it back on your production site, though!
lars

spirit

9:45 pm on Nov 30, 2002 (gmt 0)

5+ Year Member



>You might want to change $testField by $testfield in your >insert.php
>I'm not sure but if i remember well, it's case sensitive.

>mavherick

yes, that was the problem...thanx! :)
so..now I can put the content of that form into mysql,
is there any chance to send that content with an email,
directly from that page?
tnx!

jatar_k

9:51 pm on Nov 30, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Of course,

[php.net...]

spirit

10:26 pm on Nov 30, 2002 (gmt 0)

5+ Year Member



that was fast :)..thank you.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month