lucianosiqueirinha 0 Posted March 29 Report Share Posted March 29 (edited) Olá a todos os membros, eu estou novo em php, estou usando com Livro PHP orientado a Objetos do Pablo Dall'Oglio. Estou com problemas no codigo não roda, ------>codigo php<--- <?php if (!empty($_REQUEST['action'])) { $dsn = "host=localhost port=5432 dbname=livro user=postgres password="; $conn = pg_connect($dsn); if ($_REQUEST['action'] == 'edit') { $id = (int) $_GET['id']; $result = pg_query($conn, "SELECT * FROM pessoa WHERE id='{$id}'"); $pessoa = pg_fetch_assoc($result); } else if ($_REQUEST['action'] == 'save') { $pessoa = $_POST; if (empty($_POST['id'])) { $result = pg_query($conn, "SELECT max(id) as next FROM pessoa"); $next = (int) pg_fetch_assoc($result)['next'] +1; $sql = "INSERT INTO pessoa ( id, nome, endereco, bairro, telefone, email, id_cidade) VALUES ( '{$next}', ' {$pessoa['nome']}', '{$pessoa['endereco']}', '{$pessoa['bairro']}', '{$pessoa['telefone']}', '{$pessoa['email']}', '{$pessoa['id_cidade']}' )"; $result = pg_query($conn, $sql); } else { $sql = "UPDATE pessoa SET nome = '{$pessoa['nome']}', endereco = '{$pessoa['endereco']}', bairro = '{$pessoa['bairro']}', telefone = '{$pessoa['telefone']}', email = '{$pessoa['email']}', id_cidade = '{$pessoa['id_cidade']}' WHERE id = '{$pessoa['id']}'"; $result = pg_query($conn, $sql); } print ($result) ? 'Registro salvo com sucesso' : pg_last_error($conn); pg_close($conn); } } else { $pessoa = []; $pessoa['id'] = ''; $pessoa['nome'] = ''; $pessoa['endereco'] = ''; $pessoa['bairro'] = ''; $pessoa['telefone'] = ''; $pessoa['email'] = ''; $pessoa['id_cidade'] = ''; } require_once 'lista_combo_cidades.php'; $form = file_get_contents('Cadastro.html'); O Problema esta indicando aqui $form = str_replace('{id}', $pessoa['id'], $form); $form = str_replace('{nome}', $pessoa['nome'], $form); $form = str_replace('{endereco}', $pessoa['endereco'], $form); $form = str_replace('{bairro}', $pessoa['bairro'], $form); $form = str_replace('{telefone}', $pessoa['telefone'], $form); $form = str_replace('{email}', $pessoa['email'], $form); $form = str_replace('{id_cidade}', $pessoa['id_cidade'], $form); $form = str_replace('{cidades}', lista_combo_cidades( $pessoa['id_cidade'] ), $form); print $form; ?> -> Cadastro.html<- <html> <head> <meta charset="utf-8"> <title> Cadastro de pessoa </title> <link href="form.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <form enctype="multipart/form-data" method="post" action="pessoa_form.php?action=save"> <label>Código</label> <input name="id" readonly="1" type="text" value='{id}'> <label>Nome</label> <input name="nome" type="text" style="width: 50%" value="{nome}"> <label>Endereço</label> <input name="endereco" type="text"style="width: 50%" value="{endereco}"> <label>Bairro</label> <input name="bairro" type="text" style="width: 25%" value="{bairro}"> <label>Telefone</label> <input name="telefone" type="text" style="width: 25%" value="{telefone}"> <label>Email</label> <input name="email" type="text" style="width: 25%" value="{email}"> <label>Cidade</label> <select name="id_cidade" style="width: 25%"> '{cidades}' </select> <input type="submit"> </form> </body> </html> --> Navegador<- Warning: file_get_contents(Cadastro.html): Failed to open stream: No such file or directory in C:\Apache24\htdocs\pessoa_form.php on line 64 -> Pasta do windows onde roda localhost <- C:\Apache24\htdocs Alguém pode me ajudar? Edited March 29 by lucianosiqueirinha Quote Link to post Share on other sites
Question
lucianosiqueirinha 0
Olá a todos os membros, eu estou novo em php, estou usando com Livro PHP orientado a Objetos do Pablo Dall'Oglio. Estou com problemas no codigo não roda,
------>codigo php<---
<?php
if (!empty($_REQUEST['action']))
{
$dsn = "host=localhost port=5432 dbname=livro user=postgres password=";
$conn = pg_connect($dsn);
if ($_REQUEST['action'] == 'edit')
{
$id = (int) $_GET['id'];
$result = pg_query($conn, "SELECT * FROM pessoa WHERE id='{$id}'");
$pessoa = pg_fetch_assoc($result);
}
else if ($_REQUEST['action'] == 'save')
{
$pessoa = $_POST;
if (empty($_POST['id']))
{
$result = pg_query($conn, "SELECT max(id) as next FROM pessoa");
$next = (int) pg_fetch_assoc($result)['next'] +1;
$sql = "INSERT INTO pessoa (
id,
nome,
endereco,
bairro,
telefone,
email,
id_cidade)
VALUES (
'{$next}', '
{$pessoa['nome']}',
'{$pessoa['endereco']}',
'{$pessoa['bairro']}',
'{$pessoa['telefone']}',
'{$pessoa['email']}',
'{$pessoa['id_cidade']}'
)";
$result = pg_query($conn, $sql);
} else
{
$sql = "UPDATE pessoa SET
nome = '{$pessoa['nome']}',
endereco = '{$pessoa['endereco']}',
bairro = '{$pessoa['bairro']}',
telefone = '{$pessoa['telefone']}',
email = '{$pessoa['email']}',
id_cidade = '{$pessoa['id_cidade']}'
WHERE id = '{$pessoa['id']}'";
$result = pg_query($conn, $sql);
}
print ($result) ? 'Registro salvo com sucesso' : pg_last_error($conn);
pg_close($conn);
}
}
else
{
$pessoa = []; $pessoa['id'] = '';
$pessoa['nome'] = '';
$pessoa['endereco'] = '';
$pessoa['bairro'] = '';
$pessoa['telefone'] = '';
$pessoa['email'] = '';
$pessoa['id_cidade'] = '';
}
require_once 'lista_combo_cidades.php';
$form = file_get_contents('Cadastro.html'); O Problema esta indicando aqui
$form = str_replace('{id}', $pessoa['id'], $form);
$form = str_replace('{nome}', $pessoa['nome'], $form);
$form = str_replace('{endereco}', $pessoa['endereco'], $form);
$form = str_replace('{bairro}', $pessoa['bairro'], $form);
$form = str_replace('{telefone}', $pessoa['telefone'], $form);
$form = str_replace('{email}', $pessoa['email'], $form);
$form = str_replace('{id_cidade}', $pessoa['id_cidade'], $form);
$form = str_replace('{cidades}', lista_combo_cidades( $pessoa['id_cidade'] ), $form);
print $form;
?>
-> Cadastro.html<-
<html>
<head>
<meta charset="utf-8">
<title> Cadastro de pessoa </title>
<link href="form.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<form enctype="multipart/form-data" method="post" action="pessoa_form.php?action=save">
<label>Código</label>
<input name="id" readonly="1" type="text" value='{id}'>
<label>Nome</label>
<input name="nome" type="text" style="width: 50%" value="{nome}">
<label>Endereço</label>
<input name="endereco" type="text"style="width: 50%" value="{endereco}">
<label>Bairro</label>
<input name="bairro" type="text" style="width: 25%" value="{bairro}">
<label>Telefone</label>
<input name="telefone" type="text" style="width: 25%" value="{telefone}">
<label>Email</label>
<input name="email" type="text" style="width: 25%" value="{email}">
<label>Cidade</label>
<select name="id_cidade" style="width: 25%"> '{cidades}'
</select>
<input type="submit">
</form>
</body>
</html>
--> Navegador<-
Warning: file_get_contents(Cadastro.html): Failed to open stream: No such file or directory in C:\Apache24\htdocs\pessoa_form.php on line 64
-> Pasta do windows onde roda localhost <-
C:\Apache24\htdocs
Alguém pode me ajudar?
Link to post
Share on other sites
0 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.