I have the following piece of code to create a database...
$dname = $_POST['dname'];
$duser = $_POST['duser'];
$dhost = $_POST['dhost'];
$dpass = $_POST['dpass'];
$db = new mysql();
if(!isset($dname) || !isset($duser) || !isset($dhost) || !isset($dpass))
{
$this->error['database'][] = 'One of the fields was not filled in. All of them are required';
}
if(strlen($dname) > 10)
{
$this->error['database'][] = 'The database name is too long. We don\'t recommend it to be greater then 10';
}
$errors = count($this->error['database']);
if($errors > 0)
{
$db->select_db($dname, $duser, $dhost, $dpass);
$sql = 'CREATE DATABASE '. $dname;
$process = mysql_query($sql) or die(mysql_error());
mysql_close();
if($process)
{
echo <<<EOD
<p>The database was created successfully.<br />
<a href="install.php?page=config">Continue on to the next stage of the installation</a></p>
EOD;
}
}
else
{
echo "<ol>";
foreach($this->error['database'] as $value) // Line 44
{
echo "<li>{$value}</li>\n";
}
echo "</ol>";
}
- $dname = $_POST['dname'];
- $duser = $_POST['duser'];
- $dhost = $_POST['dhost'];
- $dpass = $_POST['dpass'];
-
- $db = new mysql();
-
- if(!isset($dname) || !isset($duser) || !isset($dhost) || !isset($dpass))
- {
- $this->error['database'][] = 'One of the fields was not filled in. All of them are required';
- }
-
- if(strlen($dname) > 10)
- {
- $this->error['database'][] = 'The database name is too long. We don\'t recommend it to be greater then 10';
- }
-
- $errors = count($this->error['database']);
-
- if($errors > 0)
- {
- $db->select_db($dname, $duser, $dhost, $dpass);
- $sql = 'CREATE DATABASE '. $dname;
- $process = mysql_query($sql) or die(mysql_error());
- mysql_close();
- if($process)
- {
- echo <<<EOD
- <p>The database was created successfully.<br />
- <a href="install.php?page=config">Continue on to the next stage of the installation</a></p>
- EOD;
- }
- }
- else
- {
- echo "<ol>";
- foreach($this->error['database'] as $value) // Line 44
- {
- echo "<li>{$value}</li>\n";
- }
- echo "</ol>";
- }
(It's included into a class so I know about the $this->error; thing... it works), the problem with this is that apparently, I'm using the foreach loop wrong. Here is the error that I'm getting.
Warning: Invalid argument supplied for foreach() in C:\wamp\www\boxed\Boxed\install\stages\p_database.php on line 44
I've tried removing the $this->error['database'] and simply using it as a simple array in the process, but it still gives me that error.
I'm out of ideas at the moment. Any help towards the solution to this problem would be greatly appreciated. Thanks in advance
[EDIT:] It actually could be the $this->error['database'][]. Because I tried to print it, and the array are not set...
"Bring forth therefore fruits meet for repentance:" Matthew 3:8