PHP和MySQL请求 [英] php and MySQL request

查看:42
本文介绍了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请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆