Código PHP:
session_start();
$aa=$_SESSION["a1"] = $_POST['a'];
$conexion = mysql_connect("localhost", "root","");
$bdpestu=mysql_select_db("prueba_estudiante", $conexion) or die("No me pude conectar a Prueba Estudiante ");
if (empty($_SESSION["a1"]))
{
print "Introduzca los Datos";
}
else
{
$aa=$_SESSION["a1"] = $_POST['a'];
$sql=mysql_query('SELECT * FROM prueba_estudiante.datos_estudiate');
print "<center><table border = '2'> \n";
print"<tr> \n";
print "<td>Codigo</td> \n";
print "<td>Nombre</td> \n";
print "<td>Apellido</td> \n";
print "<td>Email</td> \n";
print "<td>Ciudad</td> \n";
print "<td>Pais</td> \n";
print"</tr> \n";
while ($row = mysql_fetch_assoc($sql))
{
$codigo=$_SESSION["codigo"]=$row['Codigo'];
$nombre=$row['Nombre'];
$apellido=$row['Apellido'];
$email=$row['Email'];
$ciudad=$row['Ciudad'];
$pais=$row['Pais'];
print"<tr> \n";
print "<td>";
print $codigo;
print "</td>";
print "<td>";
print $nombre;
print "</td>";
print "<td>";
print $apellido;
print "</td>";
print "<td>";
print $email;
print "</td>";
print "<td>";
print $ciudad;
print "</td>";
print "<td>";
print $pais;
print "</td>";
print"<tr> \n";
}
print "</table> \n";
$bdmoodle=mysql_select_db("moodle", $conexion) or die("No me pude conectar a MOODLE");
mysql_data_seek($sql, 0);
while ($row = mysql_fetch_assoc($sql)) //Codigo Nuevo
{
$codigo=$_SESSION["codigo"];
$cac="INSERT INTO moodle.mdl_user (id , auth ,confirmed ,policyagreed ,deleted ,mnethostid ,username ,password ,idnumber ,firstname ,lastname ,email ,emailstop ,icq ,skype ,yahoo ,aim ,msn ,phone1 ,phone2 ,institution ,department ,address ,city ,country ,lang ,theme ,timezone ,firstaccess ,lastaccess ,lastlogin ,currentlogin ,lastip ,secret ,picture ,url ,description ,mailformat ,maildigest ,maildisplay ,htmleditor ,ajax ,autosubscribe ,trackforums ,timemodified ,trustbitmask ,imagealt ,screenreader) VALUES (NULL , 'manual', '1', '0', '0', '1', '".$row['Codigo']."', 'cf735486ada2306b54c26debafc8d5ac', '', '$nombre', '$apellido', '$email', '0', '', '', '', '', '', '', '', '', '', '', '$ciudad', '$pais', 'es_utf8', '', '99', '0', '0', '0', '0', '', '', '0', '', NULL , '1', '0', '2', '1', '1', '1', '0', '0', '0', NULL , '0')";
echo $cac;
mysql_query($cac) or die (mysql_error());
}
}