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
Change snippet to use CURDATE
I am using time() in the snippet below, I would like to use CURDATE() and have the database setup fo
There was a problem with the request. (Code: 0)
Any Idea what could cause this? I get it randomly at best. But with both IE and FF. It derives from
Displaying different page content, depending on the logged in user.
Hi all, I am new to ASP.net (and web development in general), and have a question about how I can di
Form help: Syntax & Logic
Hello again all,
I'm working on a form and ran into a wall (again) and can't seem to think th
PHP Programming error. Please help!
Hi there,
Am making a website for a friend and have encountered a problem that i need fixing
Adding meta tags under Zend FW
Hello there, recently has come to my hands the FTP of a website which is running under Zend, I would
Need help to identify this error please
:confused:Can anyone help me tell what this error message means? Maybe tell me where to look to fix
Grouping and sorting results
Please help with this query.
I have 2 tables in a database, countires and cities. states look
please help me in this update statment
hi every one
if I have table and this data in it
id name
10
registration form
first time posting. did some searches but didnt find exactly what i am looking for. dont flame cause