0

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Data Store</title>
</head>
<body>

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="sample"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// get data that sent from form
//$topic=$_POST;
$name=$_POST;
$password=$_POST;

//$datetime=date("d/m/y h:i:s"); //create date time

$sql="INSERT INTO $tbl_name(name, password)VALUES('$name', '$password')";
$result=mysql_query($sql);

if($result){
echo "Successful<BR>";
echo "<a href=dataview.php>View your topic</a>";
}
else {
echo "ERROR";
}
mysql_close();
?>
</body>
</html>

2
Contributors
4
Replies
8
Views
7 Years
Discussion Span
Last Post by whiteyoh
0

try adding echo to your query, also add the "or die" to your results variable just below the query

0

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="sample"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
// OREDER BY id DESC is order result by descending
$result=mysql_query($sql);
?>
<table width="300" border="1">
<tr>
<td>Id</td>
<td>Name </td>
<td>Password</td>
</tr>
<?php
while($row=mysql_fetch_array($result)){ // Start looping table row
?>
<tr bgcolor="red">
<td style="color:#000; height:25px; font-size:25px;"><? echo $row;?></td>
<td style="color:#000; height:25px; font-size:25px;"><? echo $row; ?></td>
<td style="color:#000; height:25px; font-size:25px;"><? echo $row; ?></td>
</tr>
<?php
// Exit looping and close connection
}
mysql_close();
?>
</table>
</body>
</html>

0

Above code is my data view page and its still not working Please help sort out the problem
It will be helpful

0

you havent followed my suggestion. add echo before your sql statements and or die to the same

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.