I've been trying to post an image along with a text for some time and I can not. When I click on the button to register, it only registers the text, but the image does not register. see my code:
File inserts:
<?php
$conect = mysql_connect('mysql.hostinger.com.br','u728177807_post','cristaleye');
$db = mysql_select_db('u728177807_post');
?>
<!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=iso-8859-1" />
<title>Documento sem título</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
Título: <input type="text" name="titulo"/><br /><br />
<input type="file" name="imagem" value="imagem" />
Texto: <textarea name="texto" cols="30" rows="10"></textarea><br /><br />
<input type="hidden" name="acao" value="cad" />
<input type="submit" value="cadastrar" />
</form>
<?php
if(isset($_POST['acao']) && $_POST['acao'] == 'cad'){
$titulo = $_POST['titulo'];
$imagem = $_POST['imagem'];
$texto = $_POST['texto'];
if(empty($titulo) || empty($texto)){
echo '<script>alert("Preencha todos os campos!");</script>';
}else{
$inserir = mysql_query("INSERT INTO postagens (titulo, imagem, texto) VALUES ('$titulo','$imagem','$texto')");
echo '<script>alert("Cadastrado com sucesso!");</script>';
}}
?>
</body>
</html>
file posts:
<!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=iso-8859-1" />
<title>Documento sem título</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="corpo">
<?php
$seleciona = mysql_query("SELECT * FROM postagens ORDER BY id DESC");
$conta = mysql_num_rows($seleciona);
if($conta <= 0){
echo "Não há nenhum dado no banco!";
}else{
while($ln = mysql_fetch_array($seleciona)){
$titulo = $ln['titulo'];
$conteudo = $ln['texto'];
$imagem = $ln['imagem'];
?>
<div id="post">
<h1><?php echo $titulo; ?></h1>
<img src="images/<?php echo $imagem; ?>" width="450" height="280" border="0" />
<p><?php echo $conteudo; ?></p>
</div><br /><br />
<?php }} ?>
</div>
</body>
</html>
I type the text and put the image in the insere.php but only register the text in the posts.php