Please help me to see why a piece of database management code is invalid.

Source: Internet
Author: User
Please help me see why a piece of database management code is invalid & lt ;? Php $ dbcon & nbsp; = & nbsp; mysql_connect ("localhost", "×××", "××××"); if (! $ Dbcon) {& nbsp; & nb, please help me see why a piece of database management code is invalid
 $dbcon = mysql_connect("localhost","××××","×××××");
if(!$dbcon)
{
    die('could not connect: ' . mysql_error());
}
echo "mysql connected\n";
mysql_query("CREATE DATABASE soap_calc",$dbcon);
mysql_select_db("soap_calc",$dbcon);
$sql = "CREATE TABLE oils
(
ID int NOT NULL AUTO_INCREMENT,
CN_Name varchar(15),
EN_Name varchar(30),
SAP decimal(5,3),
SAP_NaOH decimal(5,3),
Non_Sapon decimal(5,3),
Iodine decimal(10,3),
PRIMARY KEY (ID)
)";
mysql_query($sql,$dbcon);

//read items from file
$file = fopen("oiltable", "r");
while(!feof($file))
{
    fscanf($file,"%s %s %s %s %s \n",$CNN,$ENN,$NAOH,$KOH,$INS);
    mysql_query("INSERT INTO oils (CN_Name,EN_Name,SAP,SAP_NaOH)
                 VALUES ('$CNN','$ENN','$KOH','$NAOH')");
}
mysql_close($dbcon);
echo "db finished\n";
?>


I put this. php file under the/var/www directory and execute it in the browser.
Echo "mysql connected \ n"; and echo "db finished \ n"; are all executed.
However, I used phpmyadmin to view the database and found that no soap_calc database was created.
I was just getting started with PHP. please give me some advice. thank you. Share with php mysql:
------ Solution --------------------
Reference:
Print_r (mysql_query ("create database soap_calc", $ dbcon); [/coder]

Check if there are any mistakes


[Code = php] print_r (mysql_query ("create database soap_calc", $ dbcon ));

The mouse cursor is always on the laptop keyboard. it's wrong. check this section.
------ Solution --------------------
Mysql_query ("create database soap_calc", $ dbcon) or die (mysql_error ());
Look, it is estimated that there is no permission

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.