PHP和MySQL请求

编程入门 行业动态 更新时间:2024-10-27 16:35:02
本文介绍了PHP和MySQL请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试在数据库中插入一个我之前保存的值. 我的代码如下:

Hi I try to insert in database a value that I have save just before. My code is the following :

<?php //title: $title = $_POST["title"] ; // request sql $isbn = 'SELECT isbn FROM book WHERE title = "'.$title.'" '; //execution $sql=mysql_query($isbn) //$sqld = 'NOW() + INTERVAL 10 DAY'; // Add in the base $sqle = 'INSERT INTO emprunt (date_emprunt, date_retour, adherents_login, book_ISBN) VALUES ( NOW(), NOW() + INTERVAL 10 DAY, "'.$login.'", "'.$sql.'") ' ; //execution of the request SQL: $requete = mysql_query($sqle) or die( mysql_error() ) ; if($requete) { echo("Add success") ; } else { echo("failed") ; } ?>

我怎么了?

推荐答案

mysql_query不会像这样从标量查询中返回原始值,而是从中获取数据的资源.您需要在该资源上使用mysql_fetch_array来提供数据.

mysql_query doesn't return the raw value from a scalar query like that, but a resource from which you can get the data. You need to use mysql_fetch_array on that resource to give you the data.

$result = mysql_query($isbn); $array = mysql_fetch_array($result);

然后在第二个查询中使用$array['isbn']而不是$sql.

Then use $array['isbn'] instead of $sql in your second query.

更多推荐

PHP和MySQL请求

本文发布于:2023-11-22 03:05:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615734.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PHP   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!