无法将文本值上传到mysql [英] Can't upload text value to mysql

查看:40
本文介绍了无法将文本值上传到mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我提交网站表单时,它只会创建一个新ID.但是所有其他值均为空,我该怎么办?

Every time I submit the form of my website,It only create a new ID.But all other value is empty, what should I do?

<?php
error_reporting(E_ALL);ini_set('display_errors',1); 

$servername = "localhost";
$username = "seamaszhou";
$password = "123456";
$dbname = "guest";




$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, 
$password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// prepare sql and bind parameters
$stmt = $conn->prepare("INSERT INTO guest 
(guestName,guestEmail,guestContent) 
VALUES (:guestName, :guestEmail, :guestContent)");

$stmt->bindParam(':guestName', $guestName);
$stmt->bindParam(':guestEmail', $guestEmail);
$stmt->bindParam(':guestContent', $guestContent);

// insert a row
$guestName = "$guestName";
$guestContent = "$guestContent";
$guestEmail = "$guestEmail";
$stmt->execute();



?>

推荐答案

因为您没有设置任何值.当您这样做时:

Because you're not setting any values. When you do this:

$guestName = "$guestName";

变量$guestName被设置为包含变量$guestName当前值的字符串.由于它不包含任何内容,因此您只需将其设置为空字符串即可.

The variable $guestName gets set to a string containing the current value of the variable $guestName. Since it doesn't contain anything, you're just setting it to an empty string.

使用实际值.例如:

$guestName = "Some name";

或者,如果您确实希望将变量名作为字符串使用,请使用单引号将其解释为变量:

Or, if you literally wanted that variable name as a string, use single-quotes so it doesn't get interpreted as a variable:

$guestName = '$guestName';

这篇关于无法将文本值上传到mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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