<?php
$username = "******";
$password = "*****";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
$selected = mysql_select_db("www",$dbh)
or die("Could not select first_test");
if (mysql_query("insert into people values('4','$name1','$post1')")) {
print "successfully inserted record";
}
else {
print "Failed to insert record";
}
mysql_close($dbh);
mysql_close($dbh);
?>
<?php
$username = "morrowasted";
$password = "*******";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("www",$dbh)
or die("Could not select first_test");
$result = mysql_query("SELECT id, name,post FROM people");
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo "<div style='background:black;font:10pt;color:white'>";
echo "<center>";
print " Name:".$row{'name'}." <br>Comment:
".$row{'post'}."<br><br>";
echo "</center>";
print "</div>";
}
mysql_close($dbh);
?>
<html>
<title> Post Comment </title>
</head>
<body bgcolor=black>
<form action="test.php" method="get">
Name: <input type="text" name="name1" value="Enter Username"><br>
Comment: <input type="text" name="post1" value="comment" size="20"><br>
<input type="submit" value="Post">
</form>
everything works except im getting my "Failed to insert record" error (its not inserting it).
mysql_query("insert into people values('4','$name1','$post1')");
if(!$result){echo mysql_error();}
if($result){
print "successfully inserted record";
}
else {
print "Failed to insert record";
}
try that and see what you getwhy are you closing the mysql connection twice?
<?php
$username = "******";
$password = "*****";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
if($dbh) { print "Connected to MySQL<br>"; } else { print "error" exit(); }
$selected = mysql_select_db("www",$dbh) or die("Could not select first_test");
$connect = mysql_query("insert into people values('4','$name1','$post1')");
if ($connect) {
print "successfully inserted record";
}
else {
print "Failed to insert record";
}
mysql_close($dbh);
?>PHP:
--------------------------------------------------------------------------------
mysql_query("insert into people values('4','$name1','$post1')");
if(!$result){echo mysql_error();}
if($result){
print "successfully inserted record";
}
else {
print "Failed to insert record";
}
--------------------------------------------------------------------------------
try that and see what you get
dont ask me why, but it works now... thanks.
oh, and the double close wasnt actually in my notepad code, just a copy and paste mistake.Remember to NEVER EVER trust any user input, in any way. Even if you set char limits in the INPUT tag, always check the length of the data, and even if you make two checkboxes that can only be of value "1" or "2", check that they really are "1" or "2", and always add those darn slashes. People with malicious intents are not stopped by any limits, you must check for yourself that the data you receive is valid. Not checking user input is one of the most common security flaws on the net today. Lazy programmers.. But I understand it, it ain't a whole lot of fun to validate user input, but it ain't fun to have someone abusing your system either.
$username = "******";
$password = "*****";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
$selected = mysql_select_db("www",$dbh)
or die("Could not select first_test");
if (mysql_query("insert into people values('4','$name1','$post1')")) {
print "successfully inserted record";
}
else {
print "Failed to insert record";
}
mysql_close($dbh);
mysql_close($dbh);
?>
<?php
$username = "morrowasted";
$password = "*******";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("www",$dbh)
or die("Could not select first_test");
$result = mysql_query("SELECT id, name,post FROM people");
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo "<div style='background:black;font:10pt;color:white'>";
echo "<center>";
print " Name:".$row{'name'}." <br>Comment:
".$row{'post'}."<br><br>";
echo "</center>";
print "</div>";
}
mysql_close($dbh);
?>
<html>
<title> Post Comment </title>
</head>
<body bgcolor=black>
<form action="test.php" method="get">
Name: <input type="text" name="name1" value="Enter Username"><br>
Comment: <input type="text" name="post1" value="comment" size="20"><br>
<input type="submit" value="Post">
</form>
everything works except im getting my "Failed to insert record" error (its not inserting it).
mysql_query("insert into people values('4','$name1','$post1')");
if(!$result){echo mysql_error();}
if($result){
print "successfully inserted record";
}
else {
print "Failed to insert record";
}
try that and see what you getwhy are you closing the mysql connection twice?
<?php
$username = "******";
$password = "*****";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
if($dbh) { print "Connected to MySQL<br>"; } else { print "error" exit(); }
$selected = mysql_select_db("www",$dbh) or die("Could not select first_test");
$connect = mysql_query("insert into people values('4','$name1','$post1')");
if ($connect) {
print "successfully inserted record";
}
else {
print "Failed to insert record";
}
mysql_close($dbh);
?>PHP:
--------------------------------------------------------------------------------
mysql_query("insert into people values('4','$name1','$post1')");
if(!$result){echo mysql_error();}
if($result){
print "successfully inserted record";
}
else {
print "Failed to insert record";
}
--------------------------------------------------------------------------------
try that and see what you get
dont ask me why, but it works now... thanks.
oh, and the double close wasnt actually in my notepad code, just a copy and paste mistake.Remember to NEVER EVER trust any user input, in any way. Even if you set char limits in the INPUT tag, always check the length of the data, and even if you make two checkboxes that can only be of value "1" or "2", check that they really are "1" or "2", and always add those darn slashes. People with malicious intents are not stopped by any limits, you must check for yourself that the data you receive is valid. Not checking user input is one of the most common security flaws on the net today. Lazy programmers.. But I understand it, it ain't a whole lot of fun to validate user input, but it ain't fun to have someone abusing your system either.