0

I am trying to insert into a table media and a column membro, a member name when he is logged in and he has uploaded an image/video, with no luck, this is my code that I put in submit.php:

<?php $fbme = $_SESSION['jigowatt']['username'];?>
<?php if (!isset($_SESSION)) session_start();
    if(isset($_SESSION['jigowatt']['username'])) {
    mysqli_query("INSERT INTO media (membro) values ('$fbme')");
}?> 

I don't like to waste your time as I love this site, but some tips will be thanked.

1
  • 1
    Your session_start() placement is wrong. It should be at top the document (before the $fbme line). Commented Dec 29, 2013 at 14:57

3 Answers 3

1

Try your code with little difference like this :

<?php
if (!isset($_SESSION)) session_start();
 $fbme = $_SESSION['jigowatt']['username'];?>
<?php 
if(isset($_SESSION['jigowatt']['username'])) {
mysqli_query("INSERT INTO media (membro) values ('$fbme')");
}?> 
Sign up to request clarification or add additional context in comments.

9 Comments

You need to start_session() no matter what, not only if $_SESSION is not set.
Where the problem is ? in query or session value ?
@MadsBjaerge But you can check whether the session is already started or not.
@MahmoodRehman, no you check whether the $_SESSION var i set, which is not the same as having it actually started...
I can't test your code just now.can you tell me the error ? or what you expect from code that is not working
|
1

Start session at the start of the code and the use session after that

     <?php if (!isset($_SESSION)) session_start(); ?>
       <?php $fbme = $_SESSION['jigowatt']['username'];?>

Comments

0

Try turning on your session so it can be accessed:

session_start();

Throw this at the top of your page, unles you already have it on an include further up the page. If you already have; Everything looks in order from a first glimpse, if there is an under-laying problem with the MySQLI Driver within your code, try turning on the error reporting

mysqli_report(MYSQLI_REPORT_ALL);

Or even it's because you have not specified the database link:

$DB = new mysqli("","","","");
mysqli_query($DB,"");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.