Foros del Web » Programando para Internet » Javascript »

Problema con un Script

Estas en el tema de Problema con un Script en el foro de Javascript en Foros del Web. Hola de antemano saludos, tengo un problema en un proyecto de la uni, tengo un formulario en php que al meterle 3 números me los ...
  #1 (permalink)  
Antiguo 01/08/2012, 23:40
 
Fecha de Ingreso: julio-2012
Mensajes: 3
Antigüedad: 11 años, 9 meses
Puntos: 0
Problema con un Script

Hola de antemano saludos, tengo un problema en un proyecto de la uni, tengo un formulario en php que al meterle 3 números me los debe permutar (solo me mostrara las 6 opciones principales de la ´permuta) y mostrar en un textarea y a la vez guardarlos en la base de datos, les pongo los códigos ´para que le echen un vistazo.....

la verdad que al apretar el boton solo realiza el proceso de permuta pero no melo guarda ala base de datos...



permute.js

/*
* permute.js 1.0 - Permutation calculator
* Copyright 2007 Scriptar.com, All Rights Reserved.
* Author: Scriptar ([email protected])
* Date: 2007-07-19 11:00:00 -0800 (Thu, 19 Jul 2007)
* Description: The intent of this permutation generator is to
* describe in simple terms how to change the order or arrangment of
* the characters in a string... in other words, it's a teaching tool.
* It employs a "hold-one-character-constant-while-rearranging-the-remaining-characters-using-a-recursive-function"
* technique. This is by no means the "best" or "fastest" way of calculating
* permutations (*is* there a best way?). It's sorta fast, but JavaScript
* code is not well known for setting speed records. To understand the algorithm,
* one should be familiar with looping, arrays, pushing, popping, and recursion.
* If you can say, "I haven't had 'arrays' yet", well -- I haven't had a raise in
* a while either... so go pick up a book or take a Computer Science class
* (like CS161) and when you're done this'll all make more sense.
*/

//permArr: Global array which holds the list of permutations
//usedChars: Global utility array which holds a list of "currently-in-use" characters

var permArr = [], usedChars = [];
function permute(input) {
//convert input into a char array (one element for each character)
var i, ch, chars = input.split("");
for (i = 0; i < chars.length; i++) {
//get and remove character at index "i" from char array
ch = chars.splice(i, 1);
//add removed character to the end of used characters
usedChars.push(ch);
//when there are no more characters left in char array to add, add used chars to list of permutations
if (chars.length == 0) permArr[permArr.length] = usedChars.join("");
//send characters (minus the removed one from above) from char array to be permuted
permute(chars.join(""));
//add removed character back into char array in original position
chars.splice(i, 0, ch);
//remove the last character used off the end of used characters array
usedChars.pop();
}
}

function calcPerms(str2permute, display, txtArea, delimiter) {
if (delimiter == "\\n") delimiter = "\n";
var doIt = false;
var strLen = str2permute.length;

if (strLen == 0) {
//can't permute zero-length string
}else if(strLen >= 10) {
alert("It would take too long and use too much memory to calculate the permutations of a " + strLen + "-character string using JavaScript.\nPlease use a different method.");
}else if(strLen > 5) {
doIt = confirm("This may take a while.\nAre you sure you want to continue?");
}else
doIt = true;

if(doIt) {
if (display) txtArea.value = "Please wait...";
permArr = [];
permute(str2permute.toString());
if (display) {
txtArea.value = permArr.join(delimiter);
permArr = [];
}
}
}
  #2 (permalink)  
Antiguo 01/08/2012, 23:46
 
Fecha de Ingreso: julio-2012
Mensajes: 3
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Problema con un Script

y este es el formulario del php
permutas.php

<?php require_once('../Connections/loto_vicma.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO permuta (id_cod, loteria, str, perms, opcion, hora, monto) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id_cod'], "int"),
GetSQLValueString($_POST['loteria'], "text"),
GetSQLValueString($_POST['str'], "int"),
GetSQLValueString($_POST['perms'], "int"),
GetSQLValueString($_POST['opcion'], "text"),
GetSQLValueString($_POST['hora'], "int"),
GetSQLValueString($_POST['monto'], "int"));

mysql_select_db($database_loto_vicma, $loto_vicma);
$Result1 = mysql_query($insertSQL, $loto_vicma) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO permuta (id_cod, loteria, str, perms, opcion, hora, monto) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id_cod'], "int"),
GetSQLValueString($_POST['loteria'], "text"),
GetSQLValueString($_POST['str'], "int"),
GetSQLValueString($_POST['perms'], "int"),
GetSQLValueString($_POST['opcion'], "text"),
GetSQLValueString($_POST['hora'], "text"),
GetSQLValueString($_POST['monto'] * 6, "int"));

mysql_select_db($database_loto_vicma, $loto_vicma);
$Result1 = mysql_query($insertSQL, $loto_vicma) or die(mysql_error());
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO permuta (id_cod, loteria, str, perms, opcion, hora, monto) VALUES (%s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id_cod'], "int"),
GetSQLValueString($_POST['loteria'], "text"),
GetSQLValueString($_POST['str'], "int"),
GetSQLValueString($_POST['perms'], "int"),
GetSQLValueString($_POST['opcion'], "text"),
GetSQLValueString($_POST['hora'], "text"),
GetSQLValueString($_POST['monto'], "int"));

mysql_select_db($database_loto_vicma, $loto_vicma);
$Result1 = mysql_query($insertSQL, $loto_vicma) or die(mysql_error());
}

mysql_select_db($database_loto_vicma, $loto_vicma);
$query_Recordset1 = "SELECT MAX(id) AS id FROM cod_loteria";
$Recordset1 = mysql_query($query_Recordset1, $loto_vicma) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>
<script type="text/javascript" src="js/permute.js"></script>

<script type="text/javascript" src="js/validarNum.js"></script>
<body style="background:url(Css/fondo.jpg) no-repeat; width:auto; height:auto">
<form method="POST" action="<?php echo $editFormAction; ?>" name="form1" onsubmit="calcPerms(this.str.value, true, this.perms, this.delimiter.value); return false;">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right" style="color:#FFFFFF; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; font-size:16px;">Loteria:</td>
<td><select name="loteria" value="" >
<option value="">-</option>
<option value="leo A">Leon A</option>
<option value="leo B">Leon B</option>
<option value="zam">Zamarano</option>
<option value="cor A">Coro A</option>
<option value="cor B">Coro B</option>
<option value="nuet A">Nuestro Triple A</option>
<option value="nuet B">Nuestro Triple B</option>
<option value="tript A">Triple Tachira A</option>
<option value="tript B">Triple Tachira B</option>
<option value="zul A">Zulia A</option>
<option value="zul B">Zulia B</option>
<option value="chan A">Chance A</option>
<option value="chan B">Chance B</option>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right" style="color:#FFFFFF; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; font-size:16px;">Numero:</td>
<td><input type="text" name="str" value="" size="15" maxlength="9" title="Type your string to permute here and then press Enter or Return." /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right" style="color:#FFFFFF; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; font-size:16px;">Jugada:</td>
<td><textarea type="text" name="perms" rows="4" cols="20" wrap="soft" readonly="readonly" size="32"/></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right" style="color:#FFFFFF; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; font-size:16px;">Hora:</td>
<td><select name="hora" value="" >
<option value="">-</option>
<option value="12:00 m">12:00 PM</option>
<option value="12:30 pm">12:30 PM</option>
<option value="12:45 pm">12:45 PM</option>
<option value="1:00 pm">1:00 PM</option>
<option value="4:00 pm">4:00 PM</option>
<option value="4:30 pm">4:30 PM</option>
<option value="4:45 pm">4:45 PM</option>
<option value="5:00 pm">5:00 PM</option>
<option value="7:00 pm">7:00 PM</option>
<option value="7:30 pm">7:30 PM</option>
<option value="7:45 pm">7:45 PM</option>
<option value="8:00 pm">8:00 PM</option>
<option value="9:00 pm">9:00 PM</option>
</select></td>
</tr>

<tr valign="baseline">
<td nowrap="nowrap" align="right" style="color:#FFFFFF; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; font-size:16px;">Monto:</td>
<td><input type="text" name="monto" value="" size="15" onkeypress="return soloLetras(event)" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right" style="color:#FFFFFF; font-family:'Palatino Linotype', 'Book Antiqua', Palatino, serif; font-size:16px;">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">&nbsp;</td>
<td><input type="submit" value="Calculate Permutations" /></td>
</tr>
</table>
<input type="hidden" name="id_cod" value="<?php echo $row_Recordset1['id']; ?>" />
<input type="hidden" name="opcion" value="Permuta" />
<input type="hidden" name="delimiter" value=", " size="4" title="Use \n for newline (one permutation per line)" />

<input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Etiquetas: formulario, input, js, php, botones
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:16.