[fixed]simple post not working
Posted: Mon Sep 11, 2006 11:12 am
ok...i was having trouble before with database retrieval so i decided to go through take a different route....however this time also i ran into a couple of problems....the program works very simply...wite some text into a text box hit insert and theoretically it adds that text to the database in a field called testField....after you add it you run the php code below to show it but this is all a 3 part process i will post all 3 parts
First the html
short enogh eh?...now the part that actually will add our string to the database right(once again theoretically speaking)
now comes the grand finaley...all your hard work will now show up...or so we hope
but it doesent....why...is their a tiny something ive left out anywhere....here is whats really killing me...i set the ID to auto increment and it shows up fine...but the string that you add when you hit insert on our html page does not even appear in the database....the testField is just blank....why is that?
edited
another wierd thing is if you ran this
testField will show "some value" so that means the problem will have to be with the way im posting it right....but what am i doing incorrectly?
First the html
Code: Select all
<html>
<head>
<title>Insert Form</title>
</head>
<body>
<form action="insert_modified.php" method="post">
<p>text to add:<br>
<input type="text" name="test field" size="30">
<p><input type="submit" name="submit" value="Insert Record"></p></p>
</form>
</body>
</html>Code: Select all
<?php
// open the connection
$conn = mysql_connect("somehost", "a user", "somepass");
// database in use
mysql_select_db("testDB",$conn);
// create the SQL statement
$sql = "INSERT INTO testTable values ('', '$_POST[testField]')";
//execute the SQL statement
if (mysql_query($sql, $conn)){
echo "record added!";
}else {
echo "something went wrong";
}
?>now comes the grand finaley...all your hard work will now show up...or so we hope
Code: Select all
<?php
// open the connection
$conn = mysql_connect("somehost", "a user", "somepass");
// database in use
mysql_select_db("testDB",$conn);
// create the SQL statement
$sql = "SELECT * FROM testTable";
//execute the SQL statement
$result= mysql_query($sql,$conn) or die(mysql_error());
// go through each row and display the result
while($newArray = mysql_fetch_array($result)){
// give a name to the fields
$id = $newArray['id'];
$testField = $newArray['testField'];
// echo the results on screen
echo "the ID is $id and the text is $testField<br>";
}
?>edited
another wierd thing is if you ran this
Code: Select all
<?php
// open the connection
$conn = mysql_connect("somehost", "a user", "somepass");
// database in use
mysql_select_db("testDB",$conn);
// create the SQL statement
$sql = "INSERT INTO testTable values ('', 'some value')";
//execute the SQL statement
if (mysql_query($sql, $conn)){
echo "record added!";
}else {
echo "something went wrong";
}
?>