homepage Welcome to WebmasterWorld Guest from 54.166.255.168
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
insert into mysql problem
spirit

5+ Year Member



 
Msg#: 1027 posted 8:59 pm on Nov 29, 2002 (gmt 0)

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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 1027 posted 9:59 pm on Nov 29, 2002 (gmt 0)

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

Birdman

mavherick

10+ Year Member



 
Msg#: 1027 posted 10:11 pm on Nov 29, 2002 (gmt 0)

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

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



 
Msg#: 1027 posted 10:17 pm on Nov 29, 2002 (gmt 0)

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

10+ Year Member



 
Msg#: 1027 posted 9:15 am on Nov 30, 2002 (gmt 0)

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

5+ Year Member



 
Msg#: 1027 posted 9:45 pm on Nov 30, 2002 (gmt 0)

>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

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



 
Msg#: 1027 posted 9:51 pm on Nov 30, 2002 (gmt 0)

Of course,

[php.net...]

spirit

5+ Year Member



 
Msg#: 1027 posted 10:26 pm on Nov 30, 2002 (gmt 0)

that was fast :)..thank you.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved