Jump to content

session id


kcm2611

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.