View Full Version : The $_POST function and apostrophes.

06-29-2007, 11:09 PM
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:

$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'];

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>.');

$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);

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!


06-29-2007, 11:26 PM
$dbhost = "'$db_host'";
$dbuser = "'$db_user'";
$dbpass = "'$db_pass'";
$dbname = "'$db_name'";
$dbpre = "'$db_prefix'";