php - Using post in define -
<?php $rootdir = "digiadmin"; //leave if no folder define("config","true"); // database config // define('db_host', $_server['server_name']); define("db_user", $_post['db_user']); define("db_pass", $_post['db_password']); define("db_name", $_post['db_name']);
i have form ask database name
, username
, password
. when click on submit button show me error. have defined config , made function checking config true or false. using post username, password , database name. doing in correct way?
ok, based on comments i'd try answer question.
this should php script db.php (the mysql_* methods deprecated, that's story day keep simple):
<?php define('db_host', $_server['server_name']); define("db_user", $_post['db_user']); define("db_pass", $_post['db_password']); define("db_name", $_post['db_name']); $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 ("can't use db: " . mysql_error()); } ?>
and might html page index.html:
<form action="db.php" method="post"> user: <input type="text" name="db_user"><br> pass: <input type="text" name="db_password"><br> db: <input type="text" name="db_name"><br> <input type="submit" value="submit"> </form>
according question, errors somewhere, db.php die corresponding message. if so, can try this:
<?php $link = mysql_connect("host", "user", "password"); if (!$link) { die('could not connect: ' . mysql_error()); } $db_selected = mysql_select_db("db", $link); if (!$db_selected) { die ("can't use db: " . mysql_error()); } ?>
which means not using posted variables strings know work.
if second script fails, data (user, password and/or database) incorrect. if second script succeeds, there may wrong form post.
Comments
Post a Comment