卡住并需要一些帮助,这应该是相对简单的,但现在已经几周了我的祸根,并且放弃了! 问题是我的社交网络的用户注册表单我正在构建我想要做的是当用户将他们的地址输入数据库时用+替换空格。 我有一个名为activation.php的页面,当用户激活你的电子邮件地址并且页面上有这个代码块时,它会被调用。
$sql = mysql_query("UPDATE myMembers SET email_activated='1' WHERE id='$id' AND password='$hashpass'");
$sql = mysql_query("UPDATE myMembers SET firstname = REPLACE(firstname, ' ', '+'");
$sql = mysql_query("UPDATE myMembers SET lastname = REPLACE(lastname, ' ', '+'");
$sql = mysql_query("UPDATE myMembers SET housenumber = REPLACE(housenumber, ' ', '+'");
$sql = mysql_query("UPDATE myMembers SET addressone = REPLACE(addressone, ' ', '+'");
$sql = mysql_query("UPDATE myMembers SET addresstwo = REPLACE(addresstwo, ' ', '+'");
$sql = mysql_query("UPDATE myMembers SET county = REPLACE(county, ' ', '+'");
$sql = mysql_query("UPDATE myMembers SET city = REPLACE(city, ' ', '+'");
$sql = mysql_query("UPDATE myMembers SET country = REPLACE(country, ' ', '+'");
$sql = mysql_query("UPDATE myMembers SET postcode = REPLACE(postcode, ' ', '+'");
$sql = mysql_query("UPDATE myMembers SET phone = REPLACE(phone, ' ', '+'");
$sql_doublecheck = mysql_query("SELECT * FROM myMembers WHERE id='$id' AND password='$hashpass' AND email_activated='1'");
$doublecheck = mysql_num_rows($sql_doublecheck);
但当然不是用+来更新空格,我错过了某个地方的技巧,或者注定会失败! 当然不用说我会事先感谢你们! 问候 -P
答案 0 :(得分:7)
REPLACE()
个调用都没有括号括号。
$sql = mysql_query("UPDATE myMembers SET email_activated='1' WHERE id='$id' AND password='$hashpass'");
$sql = mysql_query("UPDATE myMembers SET firstname = REPLACE(firstname, ' ', '+')");
$sql = mysql_query("UPDATE myMembers SET lastname = REPLACE(lastname, ' ', '+')");
$sql = mysql_query("UPDATE myMembers SET housenumber = REPLACE(housenumber, ' ', '+')");
$sql = mysql_query("UPDATE myMembers SET addressone = REPLACE(addressone, ' ', '+')");
$sql = mysql_query("UPDATE myMembers SET addresstwo = REPLACE(addresstwo, ' ', '+')");
$sql = mysql_query("UPDATE myMembers SET county = REPLACE(county, ' ', '+')");
$sql = mysql_query("UPDATE myMembers SET city = REPLACE(city, ' ', '+')");
$sql = mysql_query("UPDATE myMembers SET country = REPLACE(country, ' ', '+')");
$sql = mysql_query("UPDATE myMembers SET postcode = REPLACE(postcode, ' ', '+')");
$sql = mysql_query("UPDATE myMembers SET phone = REPLACE(phone, ' ', '+')");
$sql_doublecheck = mysql_query("SELECT * FROM myMembers WHERE id='$id' AND password='$hashpass' AND email_activated='1'");
$doublecheck = mysql_num_rows($sql_doublecheck);
答案 1 :(得分:1)
几个问题
正如巴特弗里德里希斯所指出的那样,你错过了密切的括号。
您的大多数UPDATE语句将更新所有数据库条目(没有WHERE语句的查询)
每个字段创建一个查询以进行更新...
UPDATE myMembers SET
email_activated='1',
firstname = REPLACE(firstname, ' ', '+'),
lastname = REPLACE(lastname, ' ', '+'),
housenumber = REPLACE(housenumber, ' ', '+')
--etc
WHERE
id='$id' AND password='$hashpass'