phpretard Posted March 4, 2008 Share Posted March 4, 2008 How do I post the array of information? $_POST['name[$i]'] <<--This what I want to happen. All works of course except the updating part. The "UPDATE" line is wrong. <?php include ('connect.php'); $sql="SELECT * FROM links"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action="test.php"> <tr> <td> <table width="500" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"><strong>Id</strong></td> <td align="center"><strong>Name</strong></td> <td align="center"><strong>url</strong></td> <td align="center"><strong>sort</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td> <td align="center"><input name="name[]" type="text" id="name" value="<? echo $rows['name']; ?>"></td> <td align="center"><input name="url[]" type="text" id="url" value="<? echo $rows['url']; ?>"></td> <td align="center"><input name="sort[]" type="text" id="sort" value="<? echo $rows['sort']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php if(isset($_POST['Submit'])){ for($i=0;$i<$count;$i++){ $sql1="UPDATE links SET name='$name[$i]', url='$url[$i]', sort='$sort[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ echo "Worky"; } mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
phpretard Posted March 4, 2008 Author Share Posted March 4, 2008 Please let me know if the question is unclear. Quote Link to comment Share on other sites More sharing options...
bpops Posted March 4, 2008 Share Posted March 4, 2008 I have to run off to class so can't be too much help, but you need to give your input names explicit names (NOT arrays). For example: <input name="url_<?php echo $i; ?>" ..... and then put them together in an array after the form is submitted. Maybe someone can be more explicity for you, gotta run. Quote Link to comment Share on other sites More sharing options...
Agricola Posted March 4, 2008 Share Posted March 4, 2008 You are not calling the input arrays from POST <?php $name=$_POST['name[]']; $url=$_POST['url[]']; ?> If the code you have provided above is all in "form1" then i would move the part where you check if form is submited and process dabase updates at the begining of the file. use if else to then give form if it hasnt been submitted. if $_POST['submit']{ update database }else{ give form } Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 4, 2008 Share Posted March 4, 2008 if your input names are var1[], var2[]... They are accessed via $_GET['var1'][] or $_POST['var1'][]... Therefor, to access a collection of these, use for ($i = 0; $i < count($_POST['var1']); $i++) echo $_POST['var1'][$i] . "<br />\n"; Quote Link to comment Share on other sites More sharing options...
phpretard Posted March 4, 2008 Author Share Posted March 4, 2008 Thank you all! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.