开发者

Setting up a mysql database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 8 years ago.

Improve this question

I need a database for this:

<?php

if (isset($_POST['addcontentbox'])) {
    // Connection to Database
    include('config.php');

    // no Query Injection
    $message = mysql_real_escape_string($_POST['addcontentbox']);
    $sql = 'INSERT INTO wall (message) VALUES( "' . $message . '")';
    mysql_query($sql);

    echo $message;
} else {
    echo '0';
}

this is the config file:

/* Database config */
$db_host        = 'my host goes here';
$db_user        = 'the user name is here';
$db_pass        = 'my password goes here';
$db_database    = 'the datbase name is here'; 
/* End config */

$link = mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection');
mysql_select_db($db_database,$link);

Where I need help is on creating t开发者_StackOverflow中文版he database. It looks so easy in myphp admin, but I just have no idea of what I'm doing. Since the table on the above codes will be "wall", does that means the name has to be that as well? I also don't know if I have to create a table (the "message" one) or if when the script is running it will do that.

I tried setting one up already, but it just doesn't save any data. I made sure all the database connection parameters were correct ( the name, pw, user..) and still was not saving any data. I'm not getting any mysql errors from the server, it just all looks like is running fine, only that no data is saved. Can anyone help me with this?


Well, if I understood what you are looking for ... follow how to create a table and insert data on it.

On line command do the follow

CREATE database test | mysql -u your_user -p your_pwd

or by script -> echo "CREATE database test" | mysql -u your_user -p your_pwd --> http://dev.mysql.com/doc/refman/5.1/en/create-database.html

CREATE TABLE `test`.`wall` (
`id` INT( 6 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`message` VARCHAR( 255 ) NOT NULL
) ENGINE = MYISAM ;

INSERT DATA

INSERT INTO test.wall ( id , message ) VALUES ( NULL , 'Your First Message Here' );

That All..


you are not getting any errors may be because you are not sending the post data. Try loading the config.php file only in the browser. If you have any errors while connecting, PHP will show it there.


if your $db_host value is not 'localhost', you should have to check your mysqld is allowing "remote access" to that mysql client IP.

Enabling Remote Access http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜