kcm2611 Posted September 18, 2010 Share Posted September 18, 2010 Hi I am looking for help with a working script to input multiple lines of data , but i am looking for each line of data to have the $_SESSION[userid] entered into each line, ie into the table $_SESSION[userid], name, surname, age Many Thanks <? include "include/session.php"; include "include/z_db.php"; // check the login details of the user and stop execution if not logged in require "check.php"; // If member has logged in then below script will be execuated. // let us collect all data of the member $row=mysql_fetch_object(mysql_query("select * from plus_signup where userid='$_SESSION[userid]'")); if(isset($_POST['submit'])) { foreach($_POST['person'] as $person) { $name= mysql_real_escape_string($person['name']); $surname= mysql_real_escape_string($person['surname']); $age= mysql_real_escape_string($person['age']); $values[] = "('$name', '$surname', '$age')"; } $query = "INSERT INTO plus_signup (name,surname,age) VALUES " . implode(', ', $values); $result = mysql_query($query) or die("Error!<br />Query: $query<br />Error: " . mysql_error()); } ?> <form method="POST" action='multi.php' name=""> <table> <tr> <td>Name<input type="text" name="person[0][name]"></td> <td>surname<input type="text" name="person[0][surname]"></td> <td>age<input type="text" name="person[0][age]"></td> </tr> <tr> <td>name<input type="text" name="person[1][name]"></td> <td>surname<input type="text" name="person[1][surname]"></td> <td>age<input type="text" name="person[1][age]"></td> </tr> <tr> <td>name<input type="text" name="person[2][name]"></td> <td>surname<input type="text" name="person[2][surname]"></td> <td>age<input type="text" name="person[2][age]"></td> </tr> </table> <td><p> <input type="submit" name="submit" value="add"> </p> <p> </p>| <a href=update-profile.php>back</a>| </form> <? require "bottom.php"; ?> <center><br>| <a href=update-profile.php>back</a>|<br></center> </body> </html> Link to comment https://forums.phpfreaks.com/topic/213729-session-id/ Share on other sites More sharing options...
Mod-Jay Posted September 18, 2010 Share Posted September 18, 2010 Try this: $row=mysql_fetch_object(mysql_query("select * from plus_signup where userid='{$_SESSION['userid']}'")); Link to comment https://forums.phpfreaks.com/topic/213729-session-id/#findComment-1112450 Share on other sites More sharing options...
kcm2611 Posted September 18, 2010 Author Share Posted September 18, 2010 Mod-jay that didn't work any other thoughts? Link to comment https://forums.phpfreaks.com/topic/213729-session-id/#findComment-1112467 Share on other sites More sharing options...
Pikachu2000 Posted September 18, 2010 Share Posted September 18, 2010 What is the purpose of the first query? Its result doesn't appear to ever be used. Link to comment https://forums.phpfreaks.com/topic/213729-session-id/#findComment-1112469 Share on other sites More sharing options...
kcm2611 Posted September 18, 2010 Author Share Posted September 18, 2010 your right that query doesnt do anything should have deleted that... Link to comment https://forums.phpfreaks.com/topic/213729-session-id/#findComment-1112477 Share on other sites More sharing options...
DavidAM Posted September 18, 2010 Share Posted September 18, 2010 Add it to the VALUES clause and the INSERT clause $values[] = "({$_SESSION[userid]}, '$name', '$surname', '$age')"; } $query = "INSERT INTO plus_signup (userid, name,surname,age) VALUES " . implode(', ' $values); Of course, if there is no userid column in the table, you will have to ALTER the table before the code will work. Link to comment https://forums.phpfreaks.com/topic/213729-session-id/#findComment-1112503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.