Good people have never had much interest in the back-end area, but for greater reasons I'm having to learn.
So far the basics I can already do, which are insert, delete, update, view the data using php / mysql.
Now I came across a problem that I could not do using the handouts, which is to register a story in a particular category.
I tried to do an INSERT followed by a SELECT but I did not succeed, because the matter does not change to id_cat, it gets to value "0" and not to the value "1" p>
If someone can give me an example of how INSERT + SELECT would look, I would be grateful.
Thank you in advance.
(Note: I'm not using OO ..., I'm doing the old form with mysql_, which is the easiest way to learn.)
<?php
if(isset($_POST['enviar'])) {
$id_cat = $_POST['cat_lancamentos'];
$titulo = $_POST['titulo'];
$original = $_POST['original'];
$capa = $_FILES["capa"] ["name"];
$lancamento = $_POST['lancamento'];
$genero = $_POST['genero'];
$diretor = $_POST['diretor'];
$sinopse = $_POST['sinopse'];
$midia = $_POST['video'];
$caminho_img = "../capas/";
if(move_uploaded_file($_FILES["capa"]["tmp_name"],$caminho_img."/".$capa)) {
$mysql_path = $caminho_img."/".$capa;
$sql=mysql_query("INSERT INTO lancamentos VALUES('', '$id_cat', '$titulo', '$original', '$capa', '$diretor', '$lancamento', '$genero', '$midia', '', '', '$sinopse')");
echo "INSERT INTO lancamentos VALUES('', '$id_cat', '$titulo', '$original', '$capa', '$diretor', '$lancamento', '$genero', '$midia', '', '', '$sinopse')";
if($sql)
{
header("location: lancamentos-gerenciar.php");
}
}
}
?>
<form method="post" action="" enctype="multipart/form-data">
<pedido>
<botaoexcluir><a href="#"><font color="red">Cancelar</font></a></botaoexcluir> <botaoadicionar><input type="submit" name="enviar" value="Cadastrar"></botaoadicionar>
<capa><img id="uploadPreview" width="152px" height="214px" /> </capa>
<campopedido><strong>Titulo:</strong> <input type="text" name="titulo" id="titulo" size="50"></campopedido>
<campopedido><strong>Titulo Original:</strong> <input type="text" name="original" id="original" size="40"></campopedido>
<campopedido><strong>Lançamento:</strong> <input type="text" name="lancamento" id="lancamento" size="40"></textarea></campopedido>
<campopedido><strong>Genero:</strong> <input type="text" name="genero" id="genero" size="40"></campopedido>
<campopedido><strong>Categoria:</strong>
<select name="cat_lancamentos" size="1" id="cat_lancamentos">
<option value="">Selecionar</option>
<?php
$sql = "SELECT * FROM cat_lancamentos";
$resultado = mysql_query($sql) or die('Erro ao selecionar a categoria: ' .mysql_error());
while($linhas = mysql_fetch_array($resultado))
{
$selected = ($linhas['nome'] == $_POST['cat_lancamentos'])?'selected':'';
?>
<option value="<?php echo $linhas['nome']; ?>" <?php echo $selected; ?>>
<?php echo $linhas['nome']; ?>
</option>
<?php
}
?>
</select>
</campopedido>
<campopedido><strong>Dirigido por:</strong> <input type="text" name="diretor" id="diretor" size="40"></campopedido>
<campopedido><strong>Selecionar capa:</strong> <input id="uploadImage" type="file" name="capa" onchange="PreviewImage();" /></campopedido>
<sinopse>
<strong>Sinopse</strong><br />
<textarea name="sinopse" id="sinopse" size="85" cols="40" rows="5" style="width:620px; height:80px; margin-top:10px;"></textarea>
</sinopse>
</pedido>
<titulo> Midia</titulo>
<pedido>
<codigo>
<p>Codigo de adicição de midia</p>
<textarea name="video" id="video" size="85" cols="40" rows="5" style="width:600px; height:120px; margin-top:-20px;margin-bottom:10px;">
</textarea>
</codigo>
</pedido>
</form>
My MySQL tables
CREATE TABLE 'cat_lancamentos' (
'id' int(10) unsigned NOT NULL AUTO_INCREMENT,
'nome' varchar(255) NOT NULL default '',
PRIMARY KEY ('id')
) ENGINE=MyISAM CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE 'lancamentos' (
'id' int(10) unsigned NOT NULL AUTO_INCREMENT,
'id_cat' bigint(20) NOT NULL,
'titulo' varchar(255) NOT NULL,
'original' varchar(255) NOT NULL,
'capa' varchar(100) NOT NULL,
'diretor' varchar(50) NOT NULL,
'lancamento' varchar(50) NOT NULL,
'genero' varchar(255) NOT NULL,
'midia' varchar(255) NOT NULL,
'temporada' varchar(50) NOT NULL,
'episodios' varchar(20) NOT NULL,
'sinopse' text NOT NULL,
PRIMARY KEY ('id')
) ENGINE=MyISAM CHARSET=utf8 AUTO_INCREMENT=1 ;