先mysql_connect()到mysql再做mysql_query()的相关操作。
新市网站建设公司创新互联,新市网站设计制作,有大型网站制作公司丰富经验。已为新市成百上千家提供企业网站建设服务。企业网站搭建\成都外贸网站制作要多少钱,请找那个售后服务好的新市做网站的公司定做!
====================================================================
?php
$server = "localhost";
$username = "root";
$password = "";
$database = "myabc";
$ranks = array(
1="newbie",
2="new member",
3="member",
4="high member",
5="very high member",
6="supreme member",
7="ultra member",
8="godlike member",
9="god member",
10="low god",
11="medium god",
12="high god",
13="very high god",
14="supreme god",
15="ultra god",
16="perfect"
);
$couldNotOpenDatabase = "Could not open databaseBR\n please check your settings in config.php";
$couldNotConnectMysql="Could not connect Mysql!";
$conn=mysql_connect($server,$username,$password) or die ($couldNotConnectMysql);
if (mysql_select_db($database,$conn))
{//数据库存在,做相应操作
}
else
{//数据库不存在,创建一个,并做相应操作
$query = "CREATE DATABASE $database";
$result = mysql_query($query);
mysql_select_db($database,$conn)or die ($couldNotOpenDatabase);
}
?
PHP连接数据库之PHP连接MYSQL数据库代码
?php
$mysql_server_name='localhost';
//改成自己的mysql数据库服务器
$mysql_username='root';
//改成自己的mysql数据库用户名
$mysql_password='12345678';
//改成自己的mysql数据库密码
$mysql_database='mycounter';
//改成自己的mysql数据库名
$conn=mysql_connect($mysql_server_name,
$mysql_username,$mysql_password,
$mysql_database);
$sql='CREATE DATABASE mycounter
DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
';
mysql_query($sql);
$sql='CREATE TABLE `counter`
(`id` INT(255) UNSIGNED NOT NULL
AUTO_INCREMENT ,`count` INT(255)
UNSIGNED NOT NULL DEFAULT 0,PRIMARY KEY
( `id` ) ) TYPE = innodb;';
mysql_select_db($mysql_database,$conn);
$result=mysql_query($sql);
//echo $sql;
mysql_close($conn);
echo "Hello!数据库mycounter已经成功建立!";
?
PHP连接数据库之PHP连接ACCESS数据库代码方法
?
$conn = new com("ADODB.Connection");
$connstr = "DRIVER={Microsoft
Access Driver (*.mdb)};
DBQ=". realpath("data/db.mdb");
$conn-Open($connstr);
$rs = new com("ADODB.RecordSet");
$rs-Open("select *
from szd_t",$conn,1,1);
while(! $rs-eof) {
$f = $rs-Fields(1);
echo $f-value;
$rs-MoveNext();
}
?
数据库的设计本人认为可以这样,提交表单应该再设置一个隐藏域,储存题目ID,例如
" name="an_id"
处理页面可以使用将获取到的答案数组
$_POST['itm']进行遍历,用循环$value查找question,可以使用函数strpos(),该函数如果返回数字,则是正确答案,如果返回false,则是错误答案
if(isset($_POST['an_id'])){
$an_id = $_POST['an_id'];
$qus_sql = "select `question` from `vote_answer` where id = $an_id";
$query = mysql_query($qus_sql);
while($row = mysql_fetch_row($query)){
$question = $row[0];
}
$user_question = $_POST['itm'];
foreach($user_question as $value){
if(strpos($question,$value){
echo '正确答案';
}else{
echo '错误答案';
}
}
}全手写代码,有错误请百度HI我!