Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder stevenmw's Avatar
    Join Date
    Jun 2007
    Location
    OK
    Posts
    497
    Thanks
    27
    Thanked 31 Times in 31 Posts

    The $_POST function and apostrophes.

    I writing an installer script, and the first part creates the file containing the database information then writes the info into the file.

    I have my installer ordered is so after the form is submitted with the database information it checks to make sure the install file can connect to the database. This is where my problem is. I want to submit the $db_host and then it be surrounded by apostrophes on each side. (example: 'hostname') Since the script checks the connection right away I can't simply put the apostrophes in the host_name field. So I'm guessing my only choice is in the third piece of code I've supplied below. How would i go about surrounding the host name in apostrophes using the $dbhost variable in the thid piece of coding I've provided?

    Here are specific sections of the script to help understand my question:
    PHP Code:
    if($_POST['adddb']){ 
    $db_host $_POST['db_host'];
    $db_name $_POST['db_name'];
    $db_user $_POST['db_user'];
    $db_pass $_POST['db_pass'];
    $db_prefix $_POST['db_prefix']; 
    PHP Code:
    mysql_connect($db_host,$db_user,$db_pass) or die('There was an error connecting to the database, please make sure you have your details correct.<br>
    <a href="install.php?x=1">Go back</a>.'
    );
    mysql_select_db($db_name) or die('There was an error selecting the database, please make sure your details are correct.<br>
    <a href="install.php?x=1">Go back</a>.'
    ); 
    PHP Code:
    $open = fopen('include/config.php', 'a');
    $sqldata = '<? 
    $dbhost 
    '.$db_host.';
    $dbuser '.$db_user.';
    $dbpass '.$db_pass.';
    $dbname '.$db_name.';
    $dbpre '.$db_prefix.';
    ?>';
    fwrite($open, $sqldata);
    fclose($open);
    I understand this thread is long, and not described well enough for the thread's length. But if anyone could make some sense of it, and help I would appreciate it!

    Thanks,

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,618
    Thanks
    0
    Thanked 645 Times in 635 Posts
    $dbhost = "'$db_host'";
    $dbuser = "'$db_user'";
    $dbpass = "'$db_pass'";
    $dbname = "'$db_name'";
    $dbpre = "'$db_prefix'";
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •