chipmunken Posted May 7, 2009 Share Posted May 7, 2009 I like the example from this site I found. I have used another example from this site and I hade to fix some stuff before it worked 100%. Now I want this update multiple row example becouse it fits my needs. It gets the data from my db and inserts it into the forms fields. I alter the fields and then press submit.. And the changes wont stick. Its back to as it was before...I have modifed the form and so on so it fits me. After fiddeling with it and not geting it to work I copied exactly as its done on the page and still dosent work. After looking at the code I think the problem is with the name's of the fields in the form. I dont know how the submit function work when you have a if($Submit). I think its cus the array isent changeing to the new values? Take a look at this example and please tell me whats wrong with it. http://www.phpeasystep.com/mysql/10.html Things I think might be wrong. form action="" ? Not needed when you have if(Submit)? id="name" this is the same on every loop should not thise be uniqe? id="lastname" id="email" Link to comment https://forums.phpfreaks.com/topic/157218-whats-wrong-here/ Share on other sites More sharing options...
revraz Posted May 7, 2009 Share Posted May 7, 2009 FORM ACTION points to what page you want to process the FORM Variables in, after you hit Submit. Checking if the page is submitted on the page that processes the FORM Variables is just good validation so you don't process unless it was Submitted. If you process the FORM on the same page as you submit it, the FORM ACTION is not required. Without seeing more of the code you are using, no one can help you. Link to comment https://forums.phpfreaks.com/topic/157218-whats-wrong-here/#findComment-828432 Share on other sites More sharing options...
chipmunken Posted May 7, 2009 Author Share Posted May 7, 2009 here you go <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="test_mysql"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); // Count table rows $count=mysql_num_rows($result); ?> <table width="500" border="0" cellspacing="1" cellpadding="0"> <form name="form1" method="post" action=""> <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>Lastname</strong></td> <td align="center"><strong>Email</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="lastname[]" type="text" id="lastname" value="<? echo $rows['lastname']; ?>"></td> <td align="center"><input name="email[]" type="text" id="email" value="<? echo $rows['email']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td> </tr> </table> </td> </tr> </form> </table> <?php // Check if button name "Submit" is active, do this if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } if($result1){ header("location:update_multiple.php"); } mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/157218-whats-wrong-here/#findComment-828448 Share on other sites More sharing options...
revraz Posted May 7, 2009 Share Posted May 7, 2009 This script is outdated and relies on Register Globals to be turned on in your php.ini I don't agree with the logic order either. Link to comment https://forums.phpfreaks.com/topic/157218-whats-wrong-here/#findComment-828451 Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 if($Submit){ for($i=0;$i<$count;$i++){ $sql1="UPDATE $tbl_name SET name='$name[$i]', lastname='$lastname[$i]', email='$email[$i]' WHERE id='$id[$i]'"; $result1=mysql_query($sql1); } } The quoted block above makes no sense. Read up on $_POST Link to comment https://forums.phpfreaks.com/topic/157218-whats-wrong-here/#findComment-828452 Share on other sites More sharing options...
chipmunken Posted May 8, 2009 Author Share Posted May 8, 2009 Well then as i said in first post this script was taken from a site http://www.phpeasystep.com/mysql/10.html Thats why I wanted to see whats was wrong with it. I have another update databas structure on my site today that lists the posts and puts a update link next to each db post. When link is clicked you are directed to a new page with that specific entry where you edit and update. When I came accross this script I found it a little bit better for my purpose. Since you skip some steps and makes editing faster. Not really that important but when I get some time off Ill have to make my own one day Link to comment https://forums.phpfreaks.com/topic/157218-whats-wrong-here/#findComment-829268 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 You shouldn't be posting third-party codes in this forum unless you modified some part of it. Read the rules - click the links in my sig. Link to comment https://forums.phpfreaks.com/topic/157218-whats-wrong-here/#findComment-829398 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.