PHP,Wordpress - 如何在文件中传递变量?

时间:2014-10-22 15:52:13

标签: php mysql wordpress

我在我的Wordpress安装中使用插件集成了一个PHP文件。我发现了,我怎么能发送几个变量并将它们发布到MySQL数据库,但我很困惑,如何操纵我的数据:

$web = "http://internal.weddingcenter.at/wp-content/themes/twentytwelve/orders.php";
a href="<? echo ''.$web.'?contact='.$daten[id].'' ?>">Rechnung</a>

if ($contact) {


$datum = date('Y-m-d', $date);

$sql_update = "Update wccrm_orders set contacted_date = $datum where id = $contact";
$result = mysql_query($sql_update, $db);

}

我从不跳进if-clause

如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

必须是:

    if($_GET['contact'])
        ...

或者你不能旅行>

$contact = $_GET['contact'];
    if($_GET['contact'])
        ...

答案 1 :(得分:0)

要加入Kunal Gupta,我可以看到更多问题......

if ($_GET['contact']) {

  //Forgot to mention SQL injection prevention...
  //Try preg_replace or mysqli_real_escape_string()

  $datum = preg_replace('[0-9 \/]', '', date('Y-m-d',$date)); //I think that will work
  //OR
  $test = date('Y-m-d', $date);
  $datum = mysqli_real_escape_string($test); //Should also work...

  //You must always place PHP variables in inverted commas
  $sql_update = "UPDATE wccrm_orders SET contacted_date='$datum' WHERE id='$contact'";
  //use MySQLi... It's quicker. Use the variables this way around
  $result = mysqli_query($db, $sql_update);
}

代码仍然存在很多问题,但是如果没有完全理解来自上一页的数据或者您打算如何处理数据,我只能提供很多帮助。