0

被卡住了,需要一些帮助,这应该相对简单,但几周来一直是我的祸根,快要放弃了!问题是我正在构建的社交网络的用户注册表单我想做的就是当用户将他们的地址输入数据库时​​用 + 替换空格。我有一个名为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

4

2 回答 2

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); 
于 2012-10-01T06:29:20.983 回答
1

几个问题

正如 Bart Friederichs 所指出的,您缺少右括号。

您的大部分 UPDATE 语句将更新您的所有数据库条目(没有 WHERE 语句的查询)

您为每个字段创建一个查询以更新...

UPDATE myMembers SET 
   email_activated='1',
   firstname = REPLACE(firstname, ' ', '+'),
   lastname = REPLACE(lastname, ' ', '+'),
   housenumber = REPLACE(housenumber, ' ', '+')
   --etc
WHERE 
   id='$id' AND password='$hashpass'
于 2012-10-01T06:32:01.433 回答