eZe616 Posted May 22, 2007 Share Posted May 22, 2007 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 />"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52549-script-only-executes-halfhelp-needed/ Share on other sites More sharing options...
B34ST Posted May 22, 2007 Share Posted May 22, 2007 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 />"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52549-script-only-executes-halfhelp-needed/#findComment-259311 Share on other sites More sharing options...
eZe616 Posted May 22, 2007 Author Share Posted May 22, 2007 I'm getting this error when I use your version... >> Column count doesn't match value count at row 1 ------------- i'm not sure, i think you can use since, it does insert the values of the house, but it wont insert the mysql for the images. Quote Link to comment https://forums.phpfreaks.com/topic/52549-script-only-executes-halfhelp-needed/#findComment-259338 Share on other sites More sharing options...
B34ST Posted May 22, 2007 Share Posted May 22, 2007 I left a . in the code replace: $sql2 = "INSERT INTO hpics (p1) VALUES ('$path.')"; with: $sql2 = "INSERT INTO hpics (p1) VALUES ('$path')"; not sure if this will make a difference tho Quote Link to comment https://forums.phpfreaks.com/topic/52549-script-only-executes-halfhelp-needed/#findComment-259353 Share on other sites More sharing options...
eZe616 Posted May 22, 2007 Author Share Posted May 22, 2007 nah didn't do anything Quote Link to comment https://forums.phpfreaks.com/topic/52549-script-only-executes-halfhelp-needed/#findComment-259374 Share on other sites More sharing options...
eZe616 Posted May 22, 2007 Author Share Posted May 22, 2007 Ok, I found the problem, but it's not uploading the images, or inserting them into the DB Quote Link to comment https://forums.phpfreaks.com/topic/52549-script-only-executes-halfhelp-needed/#findComment-259395 Share on other sites More sharing options...
eZe616 Posted May 23, 2007 Author Share Posted May 23, 2007 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/52549-script-only-executes-halfhelp-needed/#findComment-259601 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.