Jump to content
  • 0

Где ошибка?


vitaxastifler
 Share

Question

Б/Д

http://hostingkartinok.com/show-image.php?id=a928168c5643f015202a75126d205ded

Код

<?php//add serialif(isset($_REQUEST["add_serial"]) && $_REQUEST["add_serial"] == 1) {    $name = $_REQUEST['name'];    $soname = $_REQUEST['soname'];    $serial  = array(":name" => $name, ":soname" => $soname);    $STH = $DBH->prepare("INSERT INTO `qqq` SET `name` = :name, `soname` = :soname");    $STH->execute($serial);    echo "Serial successfully added.<br />";}//edit serialif(isset($_REQUEST["edit_serial"]) && $_REQUEST["edit_serial"] == 1) {    $id = isset($_REQUEST["id"]) ? (int)$_REQUEST["id"] : "null";    $name = $_REQUEST['name'];    $soname = $_REQUEST['soname'];    $serial  = array(":id" => $id, ":name" => $name, ":soname" => $soname);    $STH = $DBH->prepare("UPDATE `qqq` SET `name` = :name, `soname` = :soname");    $STH->execute($serial);    echo "Serial successfully updated.<br />";}//delete serialif (isset($_REQUEST["del_serial"]) && $_REQUEST["del_serial"] == 1) {    $id = isset($_REQUEST["id"]) ? (int)$_REQUEST["id"] : "null";    $STH = $DBH->query("DELETE FROM `qqq` WHERE `id` = ". $id );    echo "Serial successfully deleted";}?><table border="1">    <?php    $STH = $DBH->query('SELECT * FROM `qqq` ORDER BY `id` ASC');    $STH->setFetchMode(PDO::FETCH_OBJ);    while($row = $STH->fetch()){    ?>        <tr>            <td><?php echo $row->name; ?></td>            <td><a href="index.php?handler=edit_serial&id=<?php echo $row->id; ?>">Edit</a></td>            <td><a href="index.php?handler=delete_serial&id=<?php echo $row->id; ?>">Delete</a></td>        </tr>    <?php } ?></table><br /><form action="index.php" method="post">    <input type="hidden" name="handler" value="add_serial">    <input type="submit" value="Add Serial"></form>

Ошибка 

Fatal error: Call to a member function setFetchMode() on a non-object in C:\Users\site\123\htdocs\qqq\serial.php on line 37

где 37 строка     $STH->setFetchMode(PDO::FETCH_OBJ);

 

Ну то что некоторые переменные названы как "серии",не обращайте внимания,просто пытаюсь тренироваться...

Делаю то же самое,просто переименовую по сути...

А получаю ошибки(

И так всегда...

Edited by vitaxastifler
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

А где у вас

$DBH = new PDO("mysql:host=localhost;dbname=qqq", $user, $pass);

???

 

Кроме этого вы пытаетесь сделать выборку из таблицы 'qqq' , а  у вас нет такой таблицы. У вас есть база 'qqq' и в ней таблица 'name'.

 

То есть запрос должен быть:

'SELECT * FROM `name` ORDER BY `id` ASC'
Edited by wwt
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

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. See more about our Guidelines and Privacy Policy