Jump to content

Inputs a 0 instead of username in field


walshybiker

Recommended Posts

Hi I'm new to this and am struggling with an assignment.

 

I want to populate a database (in phymyadmin) called event.  When a link is clicked it then moves to this page where I want it to populate a field called eventa with the username.  It just sends a 0 to all fields.

 

The php code is below:

 

 

<?php

 

//This checks that the user is registered and has entered the correct details

session_start();

 

// check if logged in or not?

if (!isset($_SESSION['username'])

    ||$_SESSION['username']=$username) {

 

    // not logged in, move to login page

    header('Location: login.php');

 

}

else {

$con=mysql_connect("localhost", "20154162", "lynne");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

 

mysql_select_db ("two0154162") or die (mysql_error());

$_POST[$_SESSION['username']=$username;

 

//insert fields into databse

$query = "INSERT INTO event(eventa)

VALUES ('"$_SESSION ["username"]'")";

 

mysql_query($query) or die('Error, insert query failed'.mysql_error());

 

//after login it returns to events page

// header('location:events.html');

// exit;

mysql_close ($con);

}

//echo ("got here");

 

?>

 

 

Thanks

Walshybiker

Link to comment
Share on other sites

I'm surprised you don't get an error message :)

 

 $_POST[$_SESSION['username']=$username;

 

Also, are you trying to compare or set the value here? (Do you need two equal signs?)

if (!isset($_SESSION['username']) 
    ||$_SESSION['username']=$username) {

 

Edit: Don't know how I missed it, but your query is wrong as well.

$query = "INSERT INTO event(eventa)
      VALUES ('"$_SESSION ["username"]'")";

It should be

$query = "INSERT INTO event(eventa)
      VALUES ('".$_SESSION ['username']."')";

 

Hope that helps,

-Kalivos

 

 

Link to comment
Share on other sites

<?php

//This checks that the user is registered and has entered the correct details
session_start();

// check if logged in or not?
if (!isset($_SESSION['username']) 
    ||$_SESSION['username']==$username) {

    // not logged in, move to login page
    header('Location: login.php');
   
}
else {
$con=mysql_connect("localhost", "20154162", "lynne");
if (!$con)
{
		die('Could not connect: ' . mysql_error());
}

mysql_select_db ("two0154162") or die (mysql_error());
$_POST[$_SESSION['username']=true;

//insert fields into databse
	$query = "INSERT INTO event(eventa)
	VALUES ('"$_SESSION ["username"]"')";

	mysql_query($query) or die('Error, insert query failed'.mysql_error());

	//after login it returns to events page
//	header('location:events.html');
//		exit;
	mysql_close ($con);
}
echo ("got here");

?>

 

Edit: We have


tags for posting code within.

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.