Jump to content

explode


diokhan
 Share

Recommended Posts

boas,

eu tenho uma duvida, eu quero fazer no INSERT de um novo registo um explode, basicamente, o utilizador ao inserir 1.1.1.1 eu faço o explode e fica 1 1 1 1 separados e posso inserir cada um num campo da tabela, mas o 1.1.1.1 também vou inserir na tabela num outro campo. como e onde o devo fazer?

deixo aqui o código que tenho

ficheiro para introduzir os dados:

<?php
echo"
<table>
<h2 align=center>New Enzyme:</h2><hr>
  <form action='enzyme/insertEnzyme.php' method='POST'>
    <tr>
      <td>E.C.:</td>
      <td><input type=text name='ec' size='15'></td>
    </tr><tr>
      <td>Accepted Name:</td>
      <td><textarea name='acceptedName' rows='3' cols='50' style='width: 99%;'></textarea></td>
    </tr><tr>
      <td>Other Name:</td>
      <td><textarea name='otherName' rows='5' cols='50' style='width: 99%;'></textarea></td>
    </tr><tr>
      <td>Systematic Name:</td>
      <td><textarea name='systematicName' rows='5' cols='50' style='width: 99%;'></textarea></td>
    </tr><tr>
      <td>Comments:</td>
      <td><textarea name='comments' rows='5' cols='50' style='width: 99%;'></textarea></td>
    </tr><tr>
      <td colspan='2' align=center><hr>
        <input type='submit' value='New Enzyme'>
        <input type='reset' value='Clear'>
      </td>
    </tr>
 </form>
</table>";
?>

ficheiro que valida os ficheiros antes de inserir:

<?php
require_once ('../functions.php');

$reg = new Enzyme;

$reg->SetAcceptedName($_POST['acceptedName']);
$reg->SetOtherName($_POST['otherName']);
$reg->SetSystematicName($_POST['systematicName']);
$reg->SetEC($_POST['ec']);
$reg->SetComments(nl2br($_POST['comments']));

$ec = $_POST['ec'];
echo $ec;
echo "<br>";
$pieces = explode(".", $ec);
echo $pieces[0];
echo "<br>";
echo $pieces[1];
echo "<br>";
echo $pieces[2];
echo "<br>";
echo $pieces[3];

/*$error = $reg->newEnzyme();

if(!empty($error['2']))
{
	echo $error['2'];
}
header ('Location: ../restrito.php?opcao=view_enzyme');*/
?>

função que insere na tabela os dados:

function newEnzyme()
	{
		$stmt= $this->dbh->prepare("INSERT INTO ENTRY 
		(accepted_name, other_names, sys_name, ec_num, comments)
		VALUES (:acceptedName, :otherName, :systematicName, :ec, :comments)");
		$stmt->bindParam(':acceptedName', $this->AcceptedName);
		$stmt->bindParam(':otherName', $this->OtherName);
		$stmt->bindParam(':systematicName', $this->SystematicName);
		$stmt->bindParam(':ec', $this->EC);
		$stmt->bindParam(':comments', $this->Comments);
		$stmt->execute();
		$arr = array();
		$arr = $stmt->errorInfo();
		return $arr;
	}

eu pensei que o mais correcto seria fazer no ficheiro que valida os dados antes de inserir, mas não estou a ver como o devo fazer ?

se alguém puder dar uma ajuda ou umas indicações de como fazer agradecia  😄

...Join the dark side...and get a free cookie...

Link to comment
Share on other sites

solução encontrada.

fica aqui o código caso alguém precise

<?php
require_once ('../functions.php');

$ec = $_POST['ec'];
$pieces = explode(".", $ec);

$reg = new Enzyme;

$reg->SetAcceptedName($_POST['acceptedName']);
$reg->SetOtherName($_POST['otherName']);
$reg->SetSystematicName($_POST['systematicName']);
$reg->SetEC($_POST['ec']);
$reg->SetComments(nl2br($_POST['comments']));
$reg->SetClass($pieces[0]);
$reg->SetSubClass($pieces[1]);
$reg->SetSubSubClass($pieces[2]);
$reg->SetSerial($pieces[3]);

$error = $reg->newEnzyme();

if(!empty($error['2']))
{
	echo $error['2'];
}
header ('Location: ../restrito.php?opcao=view_enzyme');
?>

se alguém achar que posso melhorar algo, aceito opiniões 😄

...Join the dark side...and get a free cookie...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.