vinataba vinataba - 1 year ago 58
SQL Question

serialize - using serialize() to pass values into database

I have this piece of code (in a survey form)

<div id="change-color0">
<label><span class="turn-white0">01</span>Họ tên đầy đủ của bạn</label>
<input type="text" id="input" name="content[]" class="addtodo0">
<div id="change-color1">
<label><span class="turn-white1">02</span>Số chứng minh thư nhân dân của bạn</label>
<input type="text" id="input" name="content[]" class="addtodo1">
<div id="change-color2">
<label><span class="turn-white2">03</span>Địa chỉ thường trú của bạn</label>
<input type="text" id="input" name="content[]" class="addtodo2">
<div id="change-color3">
<label><span class="turn-white3">04</span>Tại sao bạn muốn trở thành học viên của dự án</label>
<input type="text" id="input" name="content[]" class="addtodo3">
<div id="change-color4">
<label><span class="turn-white4">05</span>Bạn nghĩ mình là ai</label>
<input type="text" id="input" name="content[]" class="addtodo4">
<div id="change-color5">
<label><span class="turn-white5">06</span>Trong mắt người khác bạn là ai</label>
<input type="text" id="input" name="content[]" class="addtodo5">
<div id="change-color6">
<label><span class="turn-white6">07</span>Bạn sợ nhất điều gì</label>
<input type="text" id="input" name="content[]" class="addtodo6">
<div id="change-color7">
<label><span class="turn-white7">08</span>Ước mơ của bạn là gì?</label>
<input type="text" id="input" name="content[]" class="addtodo7">
<div id="change-color8">
<label><span class="turn-white8">09</span>10 năm nữa bạn là ai?</label>
<input type="text" id="input" name="content[]" class="addtodo8">

And i want to input these text fields within a row of my db by using serialise and unserialise.
Plus, there are lots of forms including those text fields which are in the code so how i can give them an identity to execute MYSQL query then i can call the one i want.

ie. I want the first input of every form to show can i do

Answer Source

well actually you should not use serialize() because when you call out info from SQL, you can not call exactly the one that you want.

Instead of using serialize(), you'd better use implode()to save your values into one row in your database. With your code snippet, I advise you should replace


by a specific name. And this code should work for your case

$arry = array("$_POST[name]","$_POST[name]","$_POST[name]");
$insert = implode(",",$array);
$sql = $conn->query("INSERT INTO yourtable_name VALUES('$insert')");
echo "insertion grand!";


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download