Saving content to user

I am trying to save crafts that I have displayed by clicking on an image that is in the container of the craft. I have all the functions working to start a php script and write the user_id of the person logged in, but I’m not sure how to pull the craft_id specific to the craft I’m trying to save. Any suggestions?
[php]
PAGE 1

while($row = mysqli_fetch_array($result))
{
$id = $row[‘id’];
$title = $row[‘title’];
$image = $row[‘imagesmall’];
$image2 = $row[‘imagelarge’];
$owner = $row[‘owner’];
$time = $row[‘time’];
$price = $row[‘price’];
$skill = $row[‘skill’];

$result2 = mysqli_query($mysqli ,"SELECT * FROM craft_materials WHERE craft_id='$id'");
$result3 = mysqli_query($mysqli ,"SELECT * FROM craft_tools WHERE craft_id='$id'");
$result4 = mysqli_query($mysqli ,"SELECT * FROM craft_category WHERE craft_id='$id'");

include 'popup_modal.php';

if ($i <= 3) //load the larger images
{
echo '<div id="craftlarge">';

echo '<div id="craftlargeimage">';
echo "<a href='#openModal".$title."".$id."'><img src=\"".$image2."\" width=270 height=270></a>";
echo "</div>";

echo '<div id="crafttitle">';
echo "$title";
echo "</div>";

echo '<div id="craftowner">';
echo "$owner";
echo "</div>";

echo '<div id="save">';
echo "<img onClick='save()' src='../resources/images/save_alt.png' style='cursor:pointer'>";
echo '</div>';

echo nl2br($body);

echo "</div>";
$i++;
$a++;
}

else if ($i <= 11) //load the smaller images
{
echo '<div id="craftsmall">';

echo '<div id="craftsmallimage">';
echo "<a href='#openModal".$title."".$id."'><img src=\"".$image."\"></a>";
echo "</div>";

echo '<div id="openModal" class="modalDialog">';
echo '<div>';
echo '<a href="#close" title="Close" class="close">x</a>';
echo "<img src=\"".$image2."\">";
echo '</div>';
echo '</div>';

echo '<div id="crafttitle">';
echo "$title";
echo "</div>";

echo '<div id="craftowner">';
echo "$owner";
echo "</div>";

echo '<div id="save">';
echo "<img onClick='save()' src='../resources/images/save_alt.png' style='cursor:pointer'>";
echo '</div>';

echo nl2br($body);

echo "</div>";
$i++;
$a++;
}

else if($i > 11) //reset counter to repeat craft loading
{
        $i=1;
}

}

PAGE 2

$user = $_SESSION[‘user_id’];
$craft = $_SESSION[‘craft’];

mysqli_query($mysqli,"INSERT INTO saved_content (user_id, craft_id)
VALUES
('$user','$craft')");[/php]

I’m sorry, I didn’t get your question can please explain it a bit further :’(

I’m trying to save the user_id and craft_id in one table so the craft will be be saved to the user essentially. I have no problem pulling the user_id as it is stored in $_SESSION[‘user_id’]. I’m trying to figure out how I can pull the craft_id from the craft that I select. Problem I am getting is I don’t know how to tell the PHP to pull the craft_id from that specific craft I click on and store it in a @_SESSION variable that I can then upload to my table. Sorry, trying to have it make sense :\

When you fetch the result, aren’t you getting back the craft_id in $row[‘id’] or is it something else??

When I store the craft_id in $_SESSION[‘craft_id’] it stores a random number because it doesn’t know which craft I am actually selecting from. I tried two things one was $_SESSION[‘craft_id’] = $craft_id. The result was some random number. The second thing I tried was $_SESSION[‘craft_id’’.$craft_id’] = $craft_id so the variable would change depending on which craft I selected, but When calling $_SESSION[‘craft_id’’.$craft_id’] on the second page it calls the very last one created. Is there something I can do to the html to assign a value to that div and push that value to the second page through javascript, which I can then add to the table?

Have you tried the query string??? use the get method to pass the information.

I look into that. Thanks. I’ll let you know how it goes.

Sponsor our Newsletter | Privacy Policy | Terms of Service