Jump to content

script only executes half...help needed


eZe616

Recommended Posts

I've read a little on some command on the mysql_insert_id(); I got it displaying the last inserted id and everything. Now when I want the code to use that id and insert a url into another talbe, but somehow the code only executes the first part, and no the images part.

 

Here's the code.

 

<?php 

include 'dbcon.php';

$name 	= $_POST['name'];
$lname 	= $_POST['lname'];
$type	= $_POST['type'];
$address= $_POST['address'];
$city	= $_POST['city'];
$area	= $_POST['district'];	
$dscpt	= $_POST['dscpt'];
$bedr	= $_POST['bedr'];
$bathr	= $_POST['bathr'];
$story	= $_POST['story'];
$sqft	= $_POST['sqft'];
$yearb	= $_POST['yearb'];
$status	= $_POST['status'];
$awg	= $_POST['awg'];
$usd	= $_POST['usd'];
$floor	= $_POST['flooring'];
$cooling= $_POST['cooling'];
$garage = $_POST['garage'];
$swpool = $_POST['swpool'];

if( empty($type) && empty($status) )
	{
		echo "Please Fill in the type/status fields";
		die();
	}

$sql = "INSERT INTO house SET 	name='".$name."',
								lastn='".$lname."',
								usd='".$usd ."',
								price_AWG='".$awg."',
								address='".$address."',
								area='".$area."',
								sqft='".$sqft."',
								yearb='".$yearb."',
								status='".$status."',
								type='".$type."',
								story='".$story."',
								bedr='".$bedr."',
								bathr='".$bathr."',
								flooring='".$floor."',
								cooling='".$cooling."',
								garage='".$garage."',
								swpool='".$swpool."',
								dispr='".$dscpt."'";

$insert = mysql_query($sql) or die("<b>Error</b>: " . mysql_error());
$id = mysql_insert_id();	

echo "New ID:  ". $id;	

foreach ( $_FILES['pictures']['error'] as $key => $error ) 
	{
		if ( $error == UPLOAD_ERR_OK ) 
			{
				$tmp_name = $_FILES['pictures']['tmp_name'][$key];
       				 $name = $_FILES['pictures']['name'][$key];
				 $path = "upload/$name";
        			
				if(move_uploaded_file($tmp_name, $path))
					{
						$sql2 = "INSERT INTO hpics SET p1='".$path."'";
						$result = mysql_query($sql2) or die("Error");
						echo "<img src=\"".$path."\" alt=\"\" /><br />";
					}
		}
	}


?>

Link to comment
https://forums.phpfreaks.com/topic/52549-script-only-executes-halfhelp-needed/
Share on other sites

I think you are using the wronf sql syntax not sure if u can use SET with insert. Try the following:

 

<?php 

include 'dbcon.php';

$name 	= $_POST['name'];
$lname 	= $_POST['lname'];
$type	= $_POST['type'];
$address= $_POST['address'];
$city	= $_POST['city'];
$area	= $_POST['district'];	
$dscpt	= $_POST['dscpt'];
$bedr	= $_POST['bedr'];
$bathr	= $_POST['bathr'];
$story	= $_POST['story'];
$sqft	= $_POST['sqft'];
$yearb	= $_POST['yearb'];
$status	= $_POST['status'];
$awg	= $_POST['awg'];
$usd	= $_POST['usd'];
$floor	= $_POST['flooring'];
$cooling= $_POST['cooling'];
$garage = $_POST['garage'];
$swpool = $_POST['swpool'];

if( empty($type) && empty($status) )
	{
		echo "Please Fill in the type/status fields";
		die();
	}
$sql = "INSERT into house (name, lastn, usd, price_AWG, address, area, sqft, yearb, status, type, story, bedr, bathr, flooring, cooling, garage, swpool, dispr)
	VALUES ('$name', '$usd', '$awg', '$address', '$area', '$sqft', '$yearb', '$status', '$type', '$story', '$bedr', '$bathr', $floor', '$cooling', '$garage', '$swpool', '$dscpt')";


$insert = mysql_query($sql) or die("<b>Error</b>: " . mysql_error());
$id = mysql_insert_id();	

echo "New ID:  ". $id;	

foreach ( $_FILES['pictures']['error'] as $key => $error ) 
	{
		if ( $error == UPLOAD_ERR_OK ) 
			{
				$tmp_name = $_FILES['pictures']['tmp_name'][$key];
       				 $name = $_FILES['pictures']['name'][$key];
				 $path = "upload/$name";
        			
				if(move_uploaded_file($tmp_name, $path))
					{
						$sql2 = "INSERT INTO hpics (p1)
							 VALUES ('$path.')";
						$result = mysql_query($sql2) or die("Error");
						echo "<img src=\"".$path."\" alt=\"\" /><br />";
					}
		}
	}


?>

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.