Jump to content

Recommended Posts

I need help this may be easy i don't know...

 

 

I need to link my two table together.  The first table(listings) has a row ID (primary and auto inc) my second table (images) has a row LISTING_ID.  I cannot get the last id from the listings table to get inserted on to the images table.

 

I have the part of my code below:

 

mysql_query("LOCK TABLES listings, images WRITE");

 

mysql_query("INSERT INTO images (name, size, type, content ) ".

"VALUES ('$fileName', '$fileSize', '$fileType', '$content')");

$result = mysql_query("SELECT MAX(ID) AS LAST_ID FROM listings");

 

$id = mysql_fetch_array($result);

mysql_query("UNLOCK TABLES");

 

echo "Last ID#" . $id[LAST_ID];

echo "<br>File $fileName uploaded<br>";

 

 

the images load and i am able to see the ID via the echo "Last ID#" .$id[LAST_ID'] part of the code.  But, nomater what I have tried i cannot get that id to be posted in the listing_id  of the images table.

from another page....

i would like to have this all on the same page but it was way to confusing.

 

this is the code for the listings

 

<?php

if (isset($_REQUEST['Submit']))

{

 

# THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE

$address=mysql_real_escape_string($_POST['address']);

$city=mysql_real_escape_string($_POST['city']);

$state=mysql_real_escape_string($_POST['state']);

$bed=mysql_real_escape_string($_POST['bed']);

$bath=mysql_real_escape_string($_POST['bath']);

$garage=mysql_real_escape_string($_POST['garage']);

$rent=mysql_real_escape_string($_POST['rent']);

$description=mysql_real_escape_string($_POST['description']);

$zip=mysql_real_escape_string($_POST['zip']);

$sql = "INSERT INTO listings(address, city, state, bed, bath, garage, rent, description, zip) values ('$address', '$city', '$state', '$bed', '$bath', '$garage', '$rent', '$description', '$zip')";

if($result = mysql_query($sql , $db))

{

echo "Thank you, Your information has been entered into our database";

echo "<a href= '$config_basedir./database entry/addingimages.php'>add images</a>";

}

else

{

echo "ERROR: ".mysql_error();

}

 

}

else

{

?>

<form method="post" action="">

  <p>Address:

    <input name="address" type="text" size="50" maxlength="100">

  </p>

  <p><br>

   

    City:

    <input name="city" type="text" size="30" maxlength="30">

   

    State:

  <input name="state" type="text" size="2" maxlength="2">

    Zip:

  <input name="zip" type="text" size="6" maxlength="5">

  </p>

  <p><br>

   

    Bed:

    <input name="bed" type="text" size="4" maxlength="1">

   

    Bath:

    <input name="bath" type="text" size="4" maxlength="3">

   

    Garage:

    <input name="garage" type="text" size="4" maxlength="1">

   

    Rent: $

    <input name="rent" type="text" size="6" maxlength="4">

  </p>

  <p>    <br>

    Description: <br>

    <textarea name="description" cols="100" rows="5"></textarea>

   

    <br>

    <br>

    <input type="submit" name="Submit" value="Submit">

  </p>

</form>

<p>

 

i do have phpmyadmin and that is true it is not get inserted.  (that is the listing_id)

 

the listings table is auto id so it is automaticly inserted into the table.

 

i just can not figure out how to get that auto inserted id into the images table and into the listing_id.

 

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.