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
https://forums.phpfreaks.com/topic/96744-mysql-php-creating-two-rows/
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.