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";
}
?>