将来自2个php文件的2个查询加在一起

问题描述:

我正在开发一个android应用程序,我应该创建一个包含其图片的配方。我有一个名为create_recipe.php的php文件,在该文件中,我创建了标题,成分,描述和类别 - 所有这些值都是在单个查询中创建的。另外,我还有第二个名为UploadImage.php的php文件,可以从相册或相机中选择一张照片并将其上传到网络服务器,并且这也可以在单个查询中完成。在我的java代码中,我首先调用create_recipe.php,然后调用UploadImage.php。这样做会将信息保存在不同的行中。将来自2个php文件的2个查询加在一起

有没有什么办法让这个查询在数据库的单个行中?任何帮助将不胜感激!

这里是我的UploadImage.php

<?php 

$target_path = "./images".basename($_FILES['uploadedfile']['name']); 
$pic   = ($_FILES['photo']['name']); 
$file_path  = $_FILES['tmp_name']; 

// include db connect class 
define('__ROOT__', dirname(dirname(__FILE__))); 
require_once(__ROOT__.'/android_connect/db_connect.php'); 

// connecting to db 
$db = new DB_CONNECT(); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { 
    echo "The file ". basename($_FILES['uploadedfile']['name'])." has been uploaded"; 
    // Make your database insert only if successful and insert $target_path, not $file_path 
    // Use mysqli_ or PDO with prepared statements 

    // here I'm making the query to add the image 
    $result = mysql_query("INSERT INTO scb(name) VALUES('$target_path')"); 
} else 
    echo "There was an error uploading the file, please try again!"; 

?>; 

代码这里是我的create_recipe.php

<?php 

/* 
* Following code will create a new recipe row 
* All recipe details are read from HTTP Post Request 
*/ 

// array for JSON response 
$response = array(); 

// check for required fields 
if (isset($_POST['title']) 
    && isset($_POST['ingredients']) 
    && isset($_POST['description']) 
    && isset($_POST['category'])) { 
// && isset($_POST['image']) 

    $title = $_POST['title']; 
    $ingredients = $_POST['ingredients']; 
    $description = $_POST['description']; 
    $category = $_POST['category']; 

    // include db connect class 
    define('__ROOT__', dirname(dirname(__FILE__))); 
    require_once(__ROOT__.'/android_connect/db_connect.php'); 

    // connecting to db 
    $db = new DB_CONNECT(); 

    // mysql inserting a new row 
    $result = mysql_query("INSERT INTO scb(title, ingredients, description, category, name) VALUES('$title', '$ingredients', '$description', '$category', '$target_path')"); 

    // check if row inserted or not 
    if ($result) { 
     // successfully inserted into database 
     $response["success"] = 1; 
     $response["message"] = "Recipe successfully created."; 

     // echoing JSON response 
     echo json_encode($response); 
    } else { 
     // failed to insert row 
     $response["success"] = 0; 
     $response["message"] = "Oops! An error occurred."; 

     // echoing JSON response 
     echo json_encode($response); 
    } 
} else { 
    // required field is missing 
    $response["success"] = 0; 
    $response["message"] = "Required field(s) is missing"; 

    // echoing JSON response 
    echo json_encode($response); 
} 

一个简单的更新查询会做的伎俩代码!

$result = mysql_query("UPDATE scb SET name = '$target_path' ORDER BY id DESC LIMIT 1");