zocker Posted February 24, 2012 Share Posted February 24, 2012 Greetings and thanks in advance! I got this script from http://www.phpeasystep.com/mysql/9.html for which I give much thanks. It takes user input and uses it to UPDATE a mysql db, the actual row concerned being chosen by a previous script. The script runs purrfectly unless I add another db field to be updated. After what seems like several years I narrowed it down to the form1 as coded below. This table posts only 3 fields to the script , if for exampleI change the order of the columns, only the first three are enntered into the $_REQUEST array on the next script...I think its something to do with the table layout??? so that in this example, $email = $_REQUEST['email'] (in the next script) throws an error. What is the problem please? And another question....this script has // close connection mysql_close(); I read that this is VERY bad practice.....your thoughts are welcomed. [pre]CODE ############### Code <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="soltheatre"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get value of id that sent from address bar $id=$_GET['id_user']; // Retrieve data from database $sql="SELECT * FROM $tbl_name WHERE id_user='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="update_ac.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td> </td> <td colspan="4"><strong>Update data in mysql</strong> </td> </tr> // ******** somewhere here there are not enough fields or columns defined. ************** <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <tr> <td align="center"> </td> <td align="center"><strong>Name</strong></td> <td align="center"><strong>Username</strong></td> <td align="center"><strong>phonenumber</strong></td> <td align="center"><strong>E-mail</strong></td> </tr> <tr> <td> </td> <td align="center"><input name="name" type="text" id="name" value="<? echo $rows['name']; ?>"></td> <td align="center"><input name="username" type="text" id="username" value="<? echo $rows['username']; ?>" size="15"></td> <td align="center"><input name="phonenumber" type="text" id="phonenumber" value="<? echo $rows['phonenumber']; ?>" size="15"></td> <td align="center"><input name="phonenumber" type="text" id="email" value="<? echo $rows['email']; ?>" size="15"></td> </tr> <tr> <td> </td> <td><input name="id" type="hidden" id="id" value="<? echo $rows['id_user']; ?>"></td> <td align="center"><input type="submit" name="Submit" value="Submit"></td> <td> </td> </tr> </table> </td> </form> </tr> </table> <? // close connection mysql_close(); ?>[/pre] Quote Link to comment Share on other sites More sharing options...
givememore Posted February 24, 2012 Share Posted February 24, 2012 the name of the input field is wrong in the email input. <td align="center"><input name="phonenumber" type="text" id="email" value="<? echo $rows['email']; ?>" size="15"></td> The name "phonenumber" is already used in the field above. Try to call it '... name="email" ...'. Quote Link to comment Share on other sites More sharing options...
zocker Posted February 24, 2012 Author Share Posted February 24, 2012 Thanks! Z 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.