search
HomeBackend DevelopmentPHP TutorialPHP POST上传,无法读取上传的字符串

本地c#写的 用WebClient类http://1.liuruitao.sinaapp.com/test.php?name={0}通过这个url上传的,网页那边

 if($_SERVER['REQUEST_METHOD']=="POST")   
{
  // $s=json_encode($_post)

    $s=$_GET["name"];
     echo "hello world!!";
    echo $_POST["name"];
    $conn=mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS);
    if(!$conn)
    die("connect fail".mysql_error());
     mysql_select_db('app_liuruitao',$conn);
     $sql = "insert into $db values ('3344556677',$s,3,'4',5,'6','7','8','9')";
     mysql_query($sql,$conn);//借SQL语句插入数据
    mysql_close();//关闭MySQL连接
   echo "insert success";
}
就是无法正确获取上传的name里面的字符串插入到数据库中,大家帮帮忙谢谢了


回复讨论(解决方案)

echo $_POST["name"];改为print_r($_REQUEST);试一下

是无法获取值还是无法插入值?

是无法获取值还是无法插入值? 感觉是得到一个值了,但是这个值我不能确定是什么,他往数据库里面插不进去,好像是类型问题

echo $_POST["name"];改为print_r($_REQUEST);试一下 可以试不了啊代码放人家服务器上了,他执行我不能控制啊

http://1.liuruitao.sinaapp.com/test.php? name={0}
显然 name 应从 $_GET 数组获取
$s=$_GET["name"];

$sql = "insert into $db values ('3344556677',$s,3,'4',5,'6','7','8','9')";
估计问题在这里
一般建表时都有一个字段作为唯一的主键,而主键是不能赋重复值的,不然就不是唯一了
如果主键是自增的话,那么缺省字段列表就可能出错


http://1.liuruitao.sinaapp.com/test.php?name={0}
显然 name 应从 $_GET 数组获取
$s=$_GET["name"];

$sql = "insert into $db values ('3344556677',$s,3,'4',5,'6','7','8','9')";
估计问题在这里
一般建表时都有一……[/quote客户端发送的时候用的是POST发送的这个,还是用GET吗

http://1.liuruitao.sinaapp.com/test.php?name={0}
显然 name 应从 $_GET 数组获取
$s=$_GET["name"];

$sql = "insert into $db values ('3344556677',$s,3,'4',5,'6','7','8','9')";
估计问题在这里
一般建表时都有一……
我客户端用的是POST发送的,还是用GET吗接收

写在 url 中的就用 $_GET
$_POST 只获取 POST 方法传递的数据(除了上传文件)

写在 url 中的就用 $_GET
$_POST 只获取 POST 方法传递的数据(除了上传文件)
改成get也不行,那个数据库哪里可以插入的,我每次都是改一次值然后插入的,没有重复主键

$s=$_GET["name"];
echo $s;
exit();
这样有输出吗

$s=$_GET["name"];
echo $s;
exit();
这样有输出吗
没有,他只有在请求这个页面时这个程序才跳进去去读,没有上传请求他就进不了IF语句

$sql = "insert into $db values ('3344556677', $s,3,'4',5,'6','7','8','9')";
如果 $s 无值,那么实际执行的 SQL指令为
insert into 表名 values ('3344556677',,3,'4',5,'6','7','8','9')
显然是错误的
可通过
mysql_query($sql,$conn) or die(mysql_error());
知道这种情况是否存在
另外
$sql = "insert into $db values ('3344556677',$s,3,'4',5,'6','7','8','9')";
应写作
$sql = "insert into $db values ('3344556677', '$s',3,'4',5,'6','7','8','9')";
以免意外的发生

$s=$_GET["name"];
echo $s;
exit();
这样有输出吗
我sizeof($s)存数据库里面是1

$sql = "insert into $db values ('3344556677',$s,3,'4',5,'6','7','8','9')";
如果 $s 无值,那么实际执行的 SQL指令为
insert into 表名 values ('3344556677',,3,'4',5,'6','7','8','9')
显然是错误的
可通过
mysql_quer……
嗯,你说的这2个问题我已经改了,后边我sizeof($s)把结果存数据库结果是1从这里可以看出来什么问题不

本地服务器上可以正确获取发送的字符串,放在新浪哪里就不行了............看来应该是他们的平台有些规定吧...

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

How do you optimize PHP applications for performance?How do you optimize PHP applications for performance?May 08, 2025 am 12:08 AM

TooptimizePHPapplicationsforperformance,usecaching,databaseoptimization,opcodecaching,andserverconfiguration.1)ImplementcachingwithAPCutoreducedatafetchtimes.2)Optimizedatabasesbyindexing,balancingreadandwriteoperations.3)EnableOPcachetoavoidrecompil

What is dependency injection in PHP?What is dependency injection in PHP?May 07, 2025 pm 03:09 PM

DependencyinjectioninPHPisadesignpatternthatenhancesflexibility,testability,andmaintainabilitybyprovidingexternaldependenciestoclasses.Itallowsforloosecoupling,easiertestingthroughmocking,andmodulardesign,butrequirescarefulstructuringtoavoidover-inje

Best PHP Performance Optimization TechniquesBest PHP Performance Optimization TechniquesMay 07, 2025 pm 03:05 PM

PHP performance optimization can be achieved through the following steps: 1) use require_once or include_once on the top of the script to reduce the number of file loads; 2) use preprocessing statements and batch processing to reduce the number of database queries; 3) configure OPcache for opcode cache; 4) enable and configure PHP-FPM optimization process management; 5) use CDN to distribute static resources; 6) use Xdebug or Blackfire for code performance analysis; 7) select efficient data structures such as arrays; 8) write modular code for optimization execution.

PHP Performance Optimization: Using Opcode CachingPHP Performance Optimization: Using Opcode CachingMay 07, 2025 pm 02:49 PM

OpcodecachingsignificantlyimprovesPHPperformancebycachingcompiledcode,reducingserverloadandresponsetimes.1)ItstorescompiledPHPcodeinmemory,bypassingparsingandcompiling.2)UseOPcachebysettingparametersinphp.ini,likememoryconsumptionandscriptlimits.3)Ad

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools