Database
Posted: Sun May 19, 2002 10:29 pm
Hello guys,new to PHP and trying to create a database but no luck..below are the sample script I created :
This is the html script that will invoke this phpp script :
** the "password.php includes all the username,password,databasename($DBName),and the host.
When I make the selection from the html script,the php files will execute and show me unable to select database error.Can you guys assist me what I have done wrong in the scripts?
thanks
Code: Select all
<?php
require("password.php");
if($Category == "windows"){
retrieve($Windows);
}
else if($Category == "linux"){
retrieve($Linux);
}
else{
retrieve($General);
}
function retrieve($Table){
$Tablename = $Table;
mysql_connect(localhost,$User,$Password);
@mysql_select_db($DBName) or die( "Unable to select database");
$query="SELECT * FROM $Tablename";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
print("<b><center>Database Output</center></b><br><br>");
$i=0;
while ($i<$num){
$question=mysql_result($result,$i,"question");
$answer=mysql_result($result,$i,"answer");
print("<TR> ALIGN=CENTER VALIGN=TOP>\n");
print("<TD ALIGN=CENTER VALIGN=TOP>$question</TD>\n");
print("<TD ALIGN=CENTER VALIGN=TOP>$answer</TD>\n");
print("</TR>\n");
++$i;
}
}
?>Code: Select all
<body bgcolor="#FFFFFF" text="#000000">
<form method="post" action="fetchdata2.php">
<select name="Category">
<option value=windows>Windows</option>
<option value=linux>Linux</option>
<option value=general>General</option>
</select>
<input type="submit" name="Submit" value="Submit">
</form>
</body>When I make the selection from the html script,the php files will execute and show me unable to select database error.Can you guys assist me what I have done wrong in the scripts?
thanks