Jump to content

MYSQL & PHP Creating Two Rows


Recommended Posts

I am slowly learning php and im try to combine two tutorials. The form is posting fine to the database  ,but it creates two rows. one row for the blob and one for all the text. ??? My goal is to place all the info in one single row.

 

Thanks for the help ???

 

Code:

 

<?
$username="";
$password="";
$database="jaybirdf_RealEstate";

$Address=$_POST['Address'];
$Picture=$_POST['Picture'];
$City=$_POST['City'];
$Map=$_POST['Map'];
$Bed=$_POST['Bed'];
$Bath=$_POST['Bath'];
$Terms=$_POST['Terms'];
$SQFT=$_POST['SQFT'];
$LSQFT=$_POST['LSQFT'];
$Price=$_POST['Price'];
$file=$_POST['Image'];
$type=$_POST['FileType'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO Listing (Address,City,Map,Bed,Bath,Terms,SQFT,LSQFT,Price,Picture,Image,FileType)
VALUES ('$Address','$City','$Map','$Bed','$Bath','$Terms','$SQFT','$LSQFT','$Price','$Picture','$file','$type')";
mysql_query($query);




//File upload Part


      if ($_POST['Submit']) {
        if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) {
          //print_r($_FILES);
          mysql_connect("localhost", "", "") or die(mysql_error());
          mysql_select_db("jaybirdf_RealEstate");
          $photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"),
$_FILES['file']['size']));
           $query = sprintf("INSERT INTO Listing(Image, FileType) VALUES
('%s', '%s')", $photo, $_FILES['file']['type']);
           if (mysql_query($query)) {
            $messages[] = "Your files is successfully store in database"; 
           } else {
            $messages[]= mysql_error();
           }
          } else {
           $messages[]="The file is bigger than the allowed size please resize";
          }
        }
      ?>
      <html>
      <head>
      <title>Add Image</title>
      </head>    
      <body>
      <? 
      if (isset($messages)) { 
        foreach ($messages as $message) {
         print $message ."<br>";
        } 
      }
  mysql_close();
      ?>

Link to comment
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.