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 Like 40 Dislike
Previous forums Next forums
Other forums

whats wrong with my code please help!!!
this is the error


Warning: mysql_close(): supplied argument is not a valid MySQL-Link res

PHP mail() returns true but doesn't work
First off I apologize if this is a newbie question, and I generally don't like asking questions that

Can php detect connection speed and thereafter swap out elements?
No code to post, lads, yet. Just looking for a yay or nay at this stage:

Can a php script be

Problem with array max size.
Hi to everyone,
I've got a homework about filling a bidimensional array un spiral shape, I alre

ALV List display - header width adjust
Hi,

I am using REUSE_ALV_LIST_DISPLAY for my ALV display.The width of the ALV varies for

Help with echo()
I'm having some problems with this code:

Code: echo '
<A HREF="jav

How to Handle more than one submit button in single form?
Hi
I have one PHP file which contains one Form. In this form there are two Submit type Buttons

How to calculate days from variable date?
This will be easy for one of you gurus. I want to fetch the date from a variable date, for example:<

Last character removed
I have created a string from an array. I have inserted commas from my form values. I am trying to re

Regarding accessing SQL query issued by any user in Oracle 10g
Hi all,
i want to know the queries issued by various users accessing a database...

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash