douyan6742 2016-05-22 18:19
浏览 22

无法连接到mySQL数据库

Im new to coding and am unable to connect to the database i have created and i really cannot move further because i need to access that in order to add , display and manipulate data . could someone please help me understand what it is i am doing wrong ? ????? my php and html form are given below . i have created a database with a table but information doesnt get added to it .

<form id="details" action="Seller.php" method="post">
<div class="textdiv">

Enter the title for the advertisemennt  
<input type="text" id="adtitle"></input><br/>
Sellers name
<input type="text" id="sellersname"> </input><br/>
Email id
<input type="text" id="email"></input><br/>
Enter A brief description of the necessary details for the product
<textarea  rows="10" cols="30" id="description"></textarea><br/>
<br/>
Choose a category
<select name="product">
<option value="Electronics">Electronics</option>
<option value="Cars">Cars</option>
<option value="pets">pets</option>
<option value="furniture">furniture</option>
<option value="appliances">appliances</option>
<option value="books">books</option>
<option value="other">other</option>
</select>
<br/>
<br/>
Enter your mobile number 

<input type="text" id="phone number"> </input> <br/> <br/>

your phone number will be kept private .<br/> <br/>
Selling price 
<input type="text" id="base"></input><br>
Cutoff price ( the price below which you will not sell )
<input type="text" id="cutoff"></input><br>
</form></div>
<?php
define (DB_NAME,'seller');
define (DB_USER,'root');
define (DB_PASSWORD,'');
define (DB_HOST,'localhost');

$link = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
if (!$link)
{die('Could not connect: '.mysql_error());}

$db_selected = mysql_select_db(DB_NAME,$link);

if(!$db_selected){die('Cant use '.DB_NAME.':'.mysql_error();}

echo'SUCESS';
$value = $_POST['adtitle'];
$value2 = $_POST['sellersname'];
$value3 = $_POST['email'];
$value4 = $_POST['description'];
$value5 = $_POST['category'];
$value6 = $_POST['phone number'];
$value7 = $_POST['base'];
$value8 = $_POST['cutoff'];

$sql ="INSERT INTO seller (adtitle,sellersname,email,description,category,phone number,base,cutoff) VALUES('$value',$value2,$value3,$value4,$value5,$value6,$value7,$value8)";


mysql_close();

?>

</div>
  • 写回答

1条回答 默认 最新

  • doujiao3998 2016-05-22 18:49
    关注

    Try this code for connecting to mysql database.

    $serverName = "localhost";
    $userName = "root";
    $password = "";
    $database = "seller";
    
    $db = new mysqli( $serverName, $userName, $password, $database );
    
    if ( $db -> connect_errno ) {
        echo "Failed to connect to MySQL: (" . $db -> connect_errno . ") " . $db -> connect_error;
    } else {
        echo "You are connected to your database. <br><br>";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化