Jeszcze jedno. Macie jakiś pomysł, żeby zrobić coś takiego, że jakby ktoś uruchomił w przeglądarce plik z klasą, ale nie wysłałby danych formularzem,tak jakby wchodził od razu na adres z klasą zamiast adresu formularza to żeby przekierowało go od razu na plik z formularzem?
Kod
<?php
class user
{
public function add()
{
$pdo= new PDO ('mysql:host=localhost;dbname=trial','root','');
$stmt= $pdo-> prepare ('INSERT INTO experiment (name, content) VALUES (:name, :content)');
$stmt-> bindValue (':name', $_POST['subject'], PDO::PARAM_STR);
$stmt-> bindValue (':content', $_POST['content'], PDO::PARAM_STR);
if (! empty($_POST['subject']) && ! empty($_POST['content']))
{
$stmt-> execute();
echo 'Done.';
}
else
{
echo 'Fill in all fields';
}
$stmt-> closeCursor();
}
}
$name= new User;
$name-> add();
?>
class user
{
public function add()
{
$pdo= new PDO ('mysql:host=localhost;dbname=trial','root','');
$stmt= $pdo-> prepare ('INSERT INTO experiment (name, content) VALUES (:name, :content)');
$stmt-> bindValue (':name', $_POST['subject'], PDO::PARAM_STR);
$stmt-> bindValue (':content', $_POST['content'], PDO::PARAM_STR);
if (! empty($_POST['subject']) && ! empty($_POST['content']))
{
$stmt-> execute();
echo 'Done.';
}
else
{
echo 'Fill in all fields';
}
$stmt-> closeCursor();
}
}
$name= new User;
$name-> add();
?>
Kod
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<head>
<title>Title</title>
</head>
<body>
<form action="execute.php" method="post">
<input type="text" name="subject" />
<input type="text" name="content" />
<input type="submit" value="Send" />
</form>
</body>
</html>
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<head>
<title>Title</title>
</head>
<body>
<form action="execute.php" method="post">
<input type="text" name="subject" />
<input type="text" name="content" />
<input type="submit" value="Send" />
</form>
</body>
</html>