Forum Moderators: coopster
// check which button was clicked
// perform calculation
if ($_POST['Submit'])
{
$conn = mysql_connect("localhost","****","****") or
die("Could not connect: " . mysql_error());
//select the database
$db = mysql_select_db("data");
$Name = $_POST["Name"];
$Address = $_POST["Address"];
$SS = $_POST["SS#"];
$Birthday = $_POST["Birthday"];
$Birth_Place = $_POST["Birth_Place"];
$Comments = $_POST["Comments"];
//insert the values into the table
$result= MYSQL_QUERY("INSERT INTO users (Name, Address, SS#, Birthday, Birth_Place, Comments)".
"VALUES ('$Name', '$Address', '$SS#', '$Birthday', '$Birth_Place', '$Comments')");
echo "Your Query was succesfully stored in the database :)";
//print($_POST["Name"]);
mysql_close($conn);
}
else if ($_POST['Show All Records']) {
//displaying the database
//establish connection to mysql
$conn = mysql_connect("localhost","rus3439","rus34391") or
die("Could not connect: " . mysql_error());
echo "Connected";
//select the database
$db = mysql_select_db("data");
$sql = "SELECT * FROM `tablename`";
$result = mysql_query($sql) or die(mysql_error());
print($_POST["Name"]);
//grabbing all data from the table
while ($r = mysql_fetch_array($result))
{
//the format is $variable = $r["nameofmysqlcolumn"];
$Name=$r["Name"];
$Address=$r["Address"];
$SS=$r["SS#"];
$Birthday=$r["Birthday"];
$Birth_Place=$r["Birth_Place"];
$Comments=$r["Comments"];
//display the row
echo "Your Query was succesfully stored in the database :)";
echo "$Name <br> $Address <br> $SS# <br> $Birthday <br> $Birth_Place <br> $Comments <br>";
mysql_close($conn);
}
}
?>
[edited by: coopster at 3:40 pm (utc) on Aug. 21, 2004]
[edit reason] generalized username and password [/edit]
<?
//establish connection to mysql
// check which button was clicked
// perform calculation
if ($Submit)
{
$conn = mysql_connect("localhost","****","****") or
die("Could not connect: " . mysql_error());
//select the database
$db = mysql_select_db("data");
$Name = $_POST["Name"];
$Address = $_POST["Address"];
$SS = $_POST["SS#"];
$Birthday = $_POST["Birthday"];
$Birth_Place = $_POST["Birth_Place"];
$Comments = $_POST["Comments"];
//insert the values into the table
$result= MYSQL_QUERY("INSERT INTO users (Name, Address, SS#, Birthday, Birth_Place, Comments)".
"VALUES ('".$Name."','".$Address."','".$SS."','".$Birthday."','".$Birth_Place."','".$Comments."')");
echo "Your Query was succesfully stored in the database :)";
//print($_POST["Name"]);
mysql_close($conn);
}
if ($Show All Records) {
//displaying the database
//establish connection to mysql
$conn = mysql_connect("localhost","****","****") or die("Could not connect: " . mysql_error());
echo "Connected";
//select the database
$db = mysql_select_db("data");
$sql = "SELECT * FROM `tablename`";
$result = mysql_query($sql) or die(mysql_error());
$myrow = mysql_fetch_array($results);
print($_POST["Name"]);
//display the row
echo 'Your Query was succesfully stored in the database :)'
. ''.$myrow["Name"].' <br> '.$myrow["Address"].' <br> '.$myrow["SS"].' <br> '.$myrow["Birthday"].' <br> '.$myrow["Birth_Place"].' <br> '.$myrow["Comments"].' <br>';
mysql_close($conn);
}
?>
<form action="page4.php" method="post">
<P><STRONG>PLEASE ENTER THE FOLLOWING INFO BELOW::</STRONG></P>
<P><STRONG>Name:</STRONG>
<input type="text" name="Name" size="10"><br>
</P>
<P><STRONG>Address:</STRONG>
<input type="text" name="Address" size="10"><br>
</P>
<P><STRONG>SS#:</STRONG>
<input type="text" name="SS#" size="20"><br>
</P>
<P><STRONG>Birthday:</STRONG>
<input type="text" name="Birthday" size="10"><br>
</P>
<P><STRONG>Place Of Birth:</STRONG>
<input type="text" name="Birth_place" size="10"><br>
</P>
<P><STRONG>Comments:</STRONG>
<TEXTAREA NAME = "comments" ROWS = "4" cols = "20"></TEXTAREA>
</P>
<input type="submit" value="Submit" name="Submit">
<input type="submit" value="Show All Records" name="Show All Records">
</form>
thanks,
take a look at this thread
Basics of extracting data from MySQL using PHP [webmasterworld.com]