Location: PHPKode > projects > PHPOLL php - mysql poll system > connetti_db.php
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; 

/*

This file is part of PHPOLL.

    PHPOLL is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    PHPOLL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with PHPOLL; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<script type="text/javascript" language="JavaScript">
<!--
function checkempty(theform) {
	
	var returnval=true; //by default, allow form submission
	
	for (i=0; i<theform.elements.length; i++){
		
		if (theform.elements[i].type=="text" || theform.elements[i].type=="textarea") {
			
			if (theform.elements[i].value=="") {
				
				alert("devi riempire tutti i campi!"); //alert error message
				returnval=false; //disallow form submission
				break; //end loop. No need to continue.
			}
		}
	}
	
return returnval;

}
//-->

</script>

<title>PHPOLL - connetti db</title>
<link rel="stylesheet" href="css/homepage_layout.css" title="homepage layout" />
</head>
<body>

<?php

if (isset ($_GET['language'])) { 
	$language=(int)$_GET['language'];
}

else {
	$language=1;
}

if ($language==0) {

  die ("Try a different way!");

}
	
?>

<div class="corpo">

<img src="img/poll_logo.jpg" alt="phpoll logo" />
<img src="main_img/phpoll_char.gif" alt="phpoll" />

<br />

<a href="connetti_db.php?language=1"><img src="img/ita.jpg" alt="italiano" /></a>
<a href="connetti_db.php?language=2"><img src="img/eng.jpg" alt="english" /></a>

<br />

<div class="menu">

<?php

if ($language==1) {

print "<a href=\"index.php?language=".$language."\">home</a>";
print "<div class=\"menu_attuale\">connetti al database</div>";
print "<a href=\"info.php?language=".$language."\">info</a>";

}

else if ($language==2) {
	
print "<a href=\"index.php?language=".$language."\">home</a>";
print "<div class=\"menu_attuale\">connect to database</div>";
print "<a href=\"info.php?language=".$language."\">info</a>";	
	
}

?>

</div>

<div class="forms">

<?php

if (!isset($_POST['submit_connetti_db'])) {

print "<form onSubmit=\"return checkempty(this);\" action=\"connetti_db.php?language=".$language."\" method=\"post\" name=\"form_compila_db\">";

print "<table>";
print "<tr>";
print "<td>";
print "HOST: ";
print "</td>";
print "<td>";
print "<input type=\"text\" name=\"host\" size=\"40\" />";
print "</td>";
print "</tr>";
print "<tr>";
print "<td>";
print "USER: ";
print "</td>";
print "<td>";
print "<input type=\"text\" name=\"user\" size=\"40\" />";
print "</td>";
print "</tr>";
print "<tr>";
print "<td>";
print "PASSWORD: ";
print "</td>";
print "<td>";
print "<input type=\"password\" name=\"password\" size=\"40\" />";
print "</td>";
print "</tr>";

print "<tr><td></td></tr>";
print "<tr><td>";

if ($language==1) {

print "<input type=\"submit\" name=\"submit_connetti_db\" value=\"connetti\" />";

}

else if ($language==2) {
	
print "<input type=\"submit\" name=\"submit_connetti_db\" value=\"connect\" />";
	
}

print "</td></tr>";

print "</table>";



print "</form>";

}

else {
	
	$host = $_POST['host'];
	$user = $_POST['user'];
	$password = $_POST['password'];
	
	// assegno le variabili di connessione
	$db = mysql_connect ($host, $user, $password);
	
	if ($db) {
		
	$lista_db = mysql_list_dbs ($db);

	print "<form onSubmit=\"return checkempty(this);\" action=\"crea_db.php\" method=\"post\" name=\"form_crea_db\">";
	
	print "<table>";
	
	print "<tr>";
	
	if ($language==1) {
	
		print "<td>Seleziona il db dove creare le tabelle per PHPOLL </td>";
	
	}
	
	else if ($language==2) {
		
		print "<td>Select the db where to create the PHPOLL tables </td>";
		
	}
	
	print "<td>";
    print "<select name=\"database\">"; 
	
	while ($riga = mysql_fetch_object($lista_db)) {
		
		print "<option>";
   		print $riga->Database;
   		print "</option>";
   		
	}
	
	print "</select>";
	print "</td>";
	print "</tr>";
	
	print "<tr>";
	
	if ($language==1) {
	
		print "<td>inserisci il nome del POLL che intendi creare: </td>";
	
	}
	
	else if ($language==2) {
		
		print "<td>please choose the name for your POLL system: </td>";
		
	}
	
	print "<td>";
	print "<input type=\"text\" name=\"prepoll\" size=\"40\" />";
	
	print "</td>";
	print "</tr>";
	
	print "</table>";
	
	print "<input type=\"hidden\" name=\"host\" value=\"".$host."\" />";
	print "<input type=\"hidden\" name=\"user\" value=\"".$user."\" />";
	print "<input type=\"hidden\" name=\"password\" value=\"".$password."\" />";
	
	if ($language==1) {
	
		print "<input type=\"submit\" name=\"submit_crea_db\" value=\"crea\" />";
		
	}
	
	else if ($language==2) {
		
		print "<input type=\"submit\" name=\"submit_crea_db\" value=\"create\" />";
		
	}
	
	print "</form>";

	mysql_close ($db);
	
}

else {
	
	print "<p>Errore nella connessione</p>";
	print "<a href=\"index.php\">torna alla pagina principale</a>";
	
}
	
}




?>

</div>

</div>
</body>
</html>
Return current item: PHPOLL php - mysql poll system