Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Send opened session new data to database

Featured Replies

Hey I am wondering if anyone knows how you can add session information into a database.

 

So far I have a session started when a user logs in and from there I have a page set up so they can add additional information such as their real name / email etc...

 

What I want to happen is when a user fills in these boxes the info is sent to the same row? where their username / password is.

 

like this...

 

userid|Username|Password|NAME|EMAIL |

1 |matt123 | passkey |matt |matt@.com| <------ all the session data to be added and stored in a table on the same line.

 

So far i have an input form but it sends the info to the next userid.

 

my userinput code so far is.

 

<?php
//check to see if user is logged in
session_start();


//Connecting to MySQL
$con = mysql_connect("localhost","root","root");

	if(!$con){
		echo "Error connecting to MySQL";
	}


//Connecting to Database
$db = mysql_select_db("search_site",$con);

	if(!$db){
		echo "Error connecting to Database";
	}


if(!isset($_SESSION['user']))
{
echo "please log in to see this page";
}
else{
echo $_SESSION['user'] . " is logged in<br />";

echo '<form action="userinfo.php" method="post">
Name: <input type="text" name="realname"><br />
E-mail: <input type="text" name="email"><br />
<input type="submit" value="send">
</form>';
}

$input = true;
if ( ($_POST["realname"] == "") || ($_POST["email"] == "") ) {
	$input = false;
}

$realname = $_POST["realname"];
$email = $_POST["email"];	 

if (!$input) {
	echo('You need to put a Username and Password');
}
else {

mysql_query("INSERT INTO user (name, email) VALUES ('$realname', '$email')");
echo "Welcome " . $realname;

}


?>

 

I would greatly appreciate any help :huh:

 

Thanks

 

Matt

 

 

Also here is some info where i defined the session data earlier this works ok:

 

$username = $_POST["username"];

$_SESSION['user']= $username;

You have:

 

mysql_query("INSERT INTO user (name, email) VALUES ('$realname', '$email')");

which is fine for the first query since it inserts a new record. On subsequent updates you need to use an UPDATE query like this:

 

mysql_query("UPDATE user SET email='$email' WHERE ???=???");

The question is how you limit the update to just the one row - this is where I've put ???=???. The left side needs to be a unique key for the record to be updated, the right side is the value identifying that row. So if your username column is unique, you could store the $username in the session and do this for example:

 

mysql_query("UPDATE user SET email='$email' WHERE Username=$username");

You can also use the id column for this by including a mysql_last_insert_id() in your code after the initial INSERT, and then storing that in the session, but that's a bit more cumbersome. You'd also have to retrieve it each time an existing user logs in. Probably best to stick with unique usernames.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.