designedfree4u Posted March 18, 2008 Share Posted March 18, 2008 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/96744-mysql-php-creating-two-rows/ Share on other sites More sharing options...
treehugger88 Posted March 18, 2008 Share Posted March 18, 2008 You are doing 2 INSERTS, so you are getting 2 rows. You should go back and combine the 2 INSERTS into 1 statement. Quote Link to comment https://forums.phpfreaks.com/topic/96744-mysql-php-creating-two-rows/#findComment-495392 Share on other sites More sharing options...
designedfree4u Posted March 21, 2008 Author Share Posted March 21, 2008 oh I see thanks. Quote Link to comment https://forums.phpfreaks.com/topic/96744-mysql-php-creating-two-rows/#findComment-497526 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.