Jump to content

Recommended Posts

Thanks for the reply..session management is definitely working...I did a print_r(_$SESSION) and it returns my username and passwd. Also did an echo"$sql" and it returned my username.

What I'm trying to do is get the user id from the above query and use it in the following query, which stores user entered info. The following query is storiing $newp in my db, but not the user id from the first query. Maybe my problem is how I'm using the results from the first query here:

[code]foreach($myplayers AS $newp) {

    $sql = "INSERT INTO myplayers (user_id, player_id) VALUES ('$id', $newp)";
    mysql_query ($sql) or die(mysql_error());
}[/code]



Link to comment
https://forums.phpfreaks.com/topic/6381-simple-query-help/#findComment-23089
Share on other sites

Thanks guys...I ended up figuring it out. this works for me. Not sure if it is efficient, but it works.

[code]$sessu = mysql_escape_string($_SESSION['username']);

$result = mysql_query("SELECT id from users WHERE username = '$sessu'");
if (!$result) {
   die('Invalid query: ' . mysql_error());
}
while ($row = mysql_fetch_array($result))
{
    $id = $row['id'];
}

foreach($player_id AS $newp) {

    $sql = "INSERT INTO myplayers (user_id, player_id) VALUES ($id, $newp)";
    mysql_query ($sql) or die(mysql_error());
}[/code]
Link to comment
https://forums.phpfreaks.com/topic/6381-simple-query-help/#findComment-23303
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.