简体   繁体   English

无法访问PHP中的数据库

[英]unable to access database in php

I am using the following script for appending the serialized array 我正在使用以下脚本来添加序列化数组

mysql_select_db("formdemo", $con);

    $result=mysql_query("select * from rohit where fid='$y'");
    if(mysql_num_rows($result)!=0)
    {
        if($result)
        {
            while($row=mysql_fetch_array($result))
            {
                $n=$row['tags'];

                $a=explode(',', $n);
                print_r($a);
                $cnt=count($a);
                $x=unserialize($row['data']);
                for($i=0;$i<$cnt;$i++)
                {
                    $d=$_GET[$a[$i]];
                    array_push($x,$d);
                }
                array_push($x,"<br/>");
            }
        }
    }
    $str=serialize($x);
    $sql="update rohit set data='$str' where fid='$y'";
    if(!mysql_query($sql,$con))
        die(mysql_error());
    else
        echo "Your data has been updated successfully\n";

when i am running this for the first time when database is empty, then it is giving an error: array_push() expects parameter 1 to be array, and store a value b;0 in database. 当我第一次在数据库为空时运行此函数时,它给出了一个错误:array_push()期望参数1为数组,并将值b; 0存储在数据库中。 what should i do in this situation. 在这种情况下我该怎么办。 please help... 请帮忙...

The simplest solution would be to initialize your variable $x with an array, before you start processing. 最简单的解决方案是在开始处理之前,使用数组初始化变量$x But please review my comment Here 但是请在这里查看我的评论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM