dotxxh0998 2014-04-03 12:12
浏览 24
已采纳

将两个变量放入同一个表的Field中

I have two textboxes in HTML and I want to join them into the same field in sql.

Those two textboxes where I have my cursor are the zip code ($zip and $zip2): http://i.imgur.com/tYxNZrX.png and I and to put them together on the same place in my sql table:

I'm inserting the values like this:

$insere="INSERT INTO Perfil VALUES ('".$nome."','".$apelido."','".$dataNasc."','".$sex."','".$PLSHELPME."','".$morada."','".$username."')";

How can i do this ?

Is it $zip+$zip2 or what ?

As asked by Typoheads:

<?php
        $username=$_POST['username'];
        $password=$_POST['password'];
        $email=$_POST['email'];
        $nome=$_POST['nome'];
        $apelido=$_POST['apelido'];
        $dataNasc=$_POST['dataNasc'];
        $sex=$_POST['sex'];
        $zip=$_POST['zip'];
        $zip2=$_POST['zip2'];
        $morada=$_POST['morada'];
        echo '<h2>Registado:</h2>';
        echo 'Bemvindo '.$nome.' '.$apelido.' aka '.$username.'.';
        $conexao=mysql_connect('localhost','root','');
        if (!$conexao)
            {
            echo 'falha na ligação,<br>';
            echo mysql_error();
            }
        mysql_select_db("alienstore",$conexao);
        $insere="INSERT INTO Perfil VALUES ('".$nome."',
                                            '".$apelido."',
                                            '".$dataNasc."',
                                            '".$sex."',
                                            '".$zip . $zip2."',
                                            '".$morada."',
                                            '".$username."')";
        $resultado=mysql_query($insere);
        if($resultado==1)
            {
            echo "<br><b>Registado</b>";
            }
        else
            "<br><b>Erro, não registado</b>";
        mysql_close($conexao);
        }
    ?>

Ok now I got a new problem... that has nothing to do with the previous one: it all goes well without errors, but it seems that it isn't inserting to the table the right way. I checked the database and there was no data that I inserted.. Does anyone know any usual problems or erros that people do so I can check it on my code/programs?

  • 写回答

1条回答 默认 最新

  • dt246813579 2014-04-03 12:15
    关注

    In PHP you use the . to concatenate string values:

    $insere = "INSERT INTO Perfil VALUES (
        '".$nome."',
        '".$apelido."',
        '".$dataNasc."',
        '".$sex."',
        '".$zip1 . $zip2."',
        '".$morada."',
        '".$username."'
    )";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来