Jump to content

simple query help


esiason14

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.