need help in update query
Posted on
16th Feb 2014 07:03 pm by
admin
hi
i have a dynamic form. i need help in how can i use update query when values from dynamic form get pass to php file.
currently when i press submit it displays this and does not update fields
Code: UPDATE contacts SET name='Array', im='Array' WHERE userid='1'
this my code for dynamic form
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="lib/jquery-1.4.min(Production).js"></script>
<script>
var id = 0;
function addFormField() {
//document.getElementById("id").value;
id++;
$("#divTxt").append(
"<p id='row" + id + "'><label>Relation <select name='relation[]' id='relation" + id + "'><option value='brother'>Brother</option><option value='sister'>Sister</option><option value='father'>Father</option><option value='mother'>Mother</option></select> <input type='text' name='name[]' /> <a href='#' onClick='removeFormField("#row" + id + ""); return false;'>Remove</a></p>"
);
}
function removeFormField(id) {
$(id).remove();
}
</script>
</head>
<body>
<form action="addDynamicFields.php" method="post" id="form1">
<label>Relation</label>
<select name="relation[]" id="relation0">
<option value="brother">Brother</option>
<option value="sister">Sister</option>
<option value="mother">Mother</option>
<option value="father">Father</option>
<option value="daughter">Daughter</option>
<option value="son">Son</option>
</select>
<input type="text" name="name[]" />
<div id="divTxt"></div>
<p><input type="submit" value="Submit" name="submit">
<!-- <input type="reset" value="Reset" name="reset"> --></p>
</form>
<p><a href="#" onClick="addFormField(); return false;">Add</a></p>
</body>
</html>
this is my php file
Code: <?php
$screenname = $_POST['relation'];
$name = $_POST['name'];
$connect = mysql_connect("localhost","user","pass");
mysql_select_db("test");
for($i=1; $i<count($screenname); $i++) {
//$imscreenname = $_POST['screenname'][$i];
//$imname = $_POST['name'][$i];
//echo $imscreename;
//$imscreenname = $screenname[$i];
$screennamesave = "UPDATE contacts SET name='$screenname', im='$name' WHERE userid='1'" or die(mysql_error());
$result = mysql_query($screennamesave);
echo $screennamesave;
}
?>
No comments posted yet
Your Answer:
Login to answer
170
40
Other forums
include function being weird?
I have a very simple system to grab an IP outputted by a PHP file.. (for a project I have) but it ou
Update Database
Hi All,
I have a problem with this:
Code: [Select]<?php
session_start();
IMAGE - SERVER SIDE scripting help...
How to receive pixel data of an image and buid a bitmap file on the server using the HTTP POST metho
onclick problem
I have <input type="text" name="message">
<a href=page2.
Beginner question regarding Array's
Hi everyone, the page im working on has an array of variable at the top...
Code: $define_li
iMatch stored value with the current value in a loop
Hello,
I have a MySQL db were I store articles in.
I have a form to fill these article
Multi language - seo links
Im trying to figure out the best method to have a multi language website that will function with seo
how to get sn motherboard
Hello.
I want to get serial number motherboard, cpu and else hardware.
Can You show me sam
PHP Include w/If IE Condition Statement?
I was having a problem with Internet Exploder (big surprise, right?) displaying my drop down menus i
Something like an INI editor or a DelimitedText-Editor
Hi all,
Am very, very, very new to PHP and not sure if I should be posting this to a Javascri