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 the 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
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
INSERT DATA
INSERT INTO
test.wall(id,message)
VALUES (
NULL , ‘Your First Message Here’
);
That All..