papillonstudios Posted July 29, 2009 Share Posted July 29, 2009 I am trying to connect to a databse but it's not, I am storing my Database settings in constants. I ahve echo my database name constant(DB_NAME) and it prints the right name on the page but yet it wont connect heres my code. <?php include ('defs.php'); if (!defined('error_check')) die('You Cannot Access This Page From This Location'); //If the form hasn't been submitted, show it. if (!isset($_POST['post'])) { ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <input type="hidden" value="1" name="post" /> <input type="hidden" value="2.0.2" name="version" /> <table width="75%"> <? echo DB_NAME; ?> <tr><td>Sitename </td><td><input type="text" class="input" name="sitename" /></td></tr> <tr><td>Site URL </td><td><input type="text" class="input" name="siteurl" /></td></tr> <tr><td>Site Description </td><td><p><textarea name="textarea" cols="40" rows="10" class="input" name="sitedesc"></textarea></p></td></tr> <tr><td><input type="submit" class="input" name="submit" value="Continue ->" /></td></tr> </table> </form> <?php } //Or else it has been submitted... else { //Get information from the forms secure it all. $version = secure($_POST['version']); $sitename= secure($_POST['sitename']); $siteurl = secure($_POST['siteurl']); $sitedesc = secure($_POST['sitedesc']); $host= secure(DB_HOST); $db = secure(DB_NAME); $dbuser = secure(DB_USER); $dbpass = secure(DB_PASSWORD); $connect = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if (!connect) { die('Could not connect: ' . mysql_error()); } $select = mysql_select_db(DB_NAME); if (!$select) { die('Could not Select: ' . mysql_error()); } $info = "INSERT INTO `info` (`version`, `sitename`, `siteurl`, `sitedesc`) VALUES ('2.0.2', '$sitename', '$siteurl', '$sitedesc'); "; mysql_query($info) or die ('Couldn\'t insert Data' . mysql_error()); echo 'Click the link to go to Step 3 ' .anchor ('index.php?step=step3', 'Continue ->'); } ?> Link to comment https://forums.phpfreaks.com/topic/167972-solved-database-not-connecting/ Share on other sites More sharing options...
waynew Posted July 29, 2009 Share Posted July 29, 2009 $connect = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or trigger_error(mysql_error()); Try that and post back whatever error pops up. Link to comment https://forums.phpfreaks.com/topic/167972-solved-database-not-connecting/#findComment-885970 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.