Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.