Pls help to resolve php contact form

Discussion in 'PHP' started by smartsaki, Oct 17, 2011.

  1. #1
    Hello friends,

    I'm new to php programming. I know less than nothing. I designed html page in which i want contact form which will be used to send the information to the given email ID.

    I done the php script part by the help of material and online tutorials. but when i upload the files to the server, I'm getting error like this,

    Access denied for user 'root'@'Localhost' to database 'form'

    when i asked this to my hosting provider, they asked me to provide my database connecting settings in my mysql connection string that i'm using in my code. But quite frankly i don't know what that does mean.

    I'm really in a tight position to upload the file to the server.

    Here are my codes. Can anyone really help me to how to fix this issue?

    config.php

    <?php
        $host = 'Localhost';
        $user = 'root';
        $pass = '';
        $dbname = 'form';
    
        $conn = mysql_connect($host,$user,$pass) or die(mysql_error());
        $selectdb = mysql_select_db($dbname,$conn) or die(mysql_error());
        ?>
    PHP:

    function1.php

    <?php
        require_once 'config.php';
        session_start();
    
    
        if(isset($_REQUEST['process']))
    
        {
    
        $name=$_REQUEST['name'];
        $email=$_REQUEST['email'];
        $mobile=$_REQUEST['mobile'];
        $mess=$_REQUEST['message'];
    
    
            $to="sak1@gmail.com";
            $to="cap90@gmail.com";
             $subject = "Contact Us";
              $message="<html><head><title></title></head><body><center></center><br /><table border='0' cellpadding='5' cellspacing='5' align='center'><tr><td> Name: </td><td>".$name."</td></tr>  <tr><td> Email: </td><td>".$email."</td></tr> <tr><td> Mobile : </td><td>".$mobile."</td></tr>   <tr><td> Message : </td><td>".$mess."</td></tr></table></body></html>";
             
             $headers  = "MIME-Version: 1.0" . "\r\n";
             $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
             $headers .= "From: ".'calltuktuk.com'." <from_address@your_domain.com>\r\n";
           $headers .= "Reply-To: ".'calltuktuk.com'." <to_address@your_domain.com>\r\n";
             
           @mail($to, $subject, $message, $headers);
           
              header('Location: index.php?true');exit;   
            }
           
        /*Contact form*/
        function myform($vars)
        {   
           $name= $vars['name'];
           $email=$vars['email'];
           $mobile = $vars['mobile'];
           $message = $vars['message'];
    
            $selqry = "SELECT * FROM contact_form";
            $rsqry = mysql_query($selqry)or die(mysql_error()) ;
            $cnt = mysql_num_rows($rsqry);
            
                             $insert = "INSERT INTO contact_form(name,email,mobile,message) VALUES('$name','$email','$mobile','$message')";
                          $rscourse=mysql_query($insert) or die (mysql_error());
                          $lastid = mysql_insert_id();
                          
                          header('Location:index.php?true');exit;
                    }
                 ?>
    PHP:
    Thanks in advance.

    Regards,
    Sam
     
    smartsaki, Oct 17, 2011 IP
  2. mrmuggles

    mrmuggles Greenhorn

    Messages:
    58
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #2
    Do you have access to PhpMyAdmin?
    Do you know how to access or create a database for your Website?
    Do you have access to cpanel or something like a panel that your hosting company provided for you?

    Basically, you're trying to write in a Database on your server named "form" with "root" as the username and nothing as the password.
    You should provide the password of the user that you can use to access your database and I doubt that the user "root" has an empty password.
     
    mrmuggles, Oct 17, 2011 IP
  3. chanif.alfath

    chanif.alfath Active Member

    Messages:
    148
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    88
    #3
    hello friend,

    u can use your user name & pass when you connect to your cpanel..
    it should be an "admin" user, so it can access to all db on your mysql database..

    we can talk on my messenger if you still confuse..

    Thanks & Regards,
    Chanif Al-Fath
     
    chanif.alfath, Oct 17, 2011 IP
  4. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #4
    If you run this on a local setup like WAMP then it would work fine unless you changed the settings. All you need to do is go into your control panel, access PHPMyAdmin and retrieve the login details for the database you want.
     
    HuggyEssex, Oct 18, 2011 IP