Jump to content

email post link to user, how to get newest id?


$php_mysql$

Recommended Posts

guys this function below posts the data into table and im also able to send a link in email with caregory name but the issue is getting the id to the particular post i got no isea how do i get that?

 

function insert($postData) {		
$postData['description'] = clean($postData['description']);	
if(!EmailExists($postData['email'])){
$sql = " INSERT INTO tbl_emails SET
		email = '".$postData['email']."',
		postersname	= '".$postData['postersname']."',
		phone	= '".$postData['phone']."'
		";
		executeSql($sql);
}		
if(empty($_FILES['image']["name"])){						
		$sql = " INSERT INTO tbl SET
		title	= '".$postData['title']."',
		image	= '',
		postersname	= '".$postData['postersname']."',
		category 	= '".$postData['category']."',
		type	= '".$postData['type']."',
		state	= '".$postData['state']."',
		location	= '".$postData['location']."',
		email 	= '".$postData['email']."',
		phone	= '".$postData['phone']."',
		description	= '".$postData['description']."',
		time	= '".time()."'
		";
		executeSql($sql);
}else{			
		global $uploadPath;
		$remove_symbols = array('+', '=', '-', '{', '}', '$', '(', ')','&');
		$removed_symbols = str_replace($remove_symbols, "_", 						$_FILES['image']['name']);  
		$randomnum=rand(00000000,99999999);  
		$imagepath = uploadFile($_FILES['image'], $uploadPath);
		$image = new SimpleImage();
		$image->load($imagepath);
		$image->resize(250,280);
		$resize_rename = $uploadPath.$randomnum._.$removed_symbols;
		$image->save($resize_rename);									
		unlink($imagepath); //delete the original file						
		$sql = " INSERT INTO tbl SET
		title	= '".$postData['title']."',
		image	= '".$resize_rename."',
		postersname	= '".$postData['postersname']."',
		category 	= '".$postData['category']."',
		type	= '".$postData['type']."',
		state	= '".$postData['state']."',
		location	= '".$postData['ocation']."',
		email 	= '".$postData['email']."',
		phone	= '".$postData['phone']."',
		description	= '".$postData['description']."',
		time	= '".time()."'
		";
		executeSql($sql);						
		}
}

Link to comment
Share on other sites

Yes you are right it has a AUTO_INCREMENT field, so it should be something like this?

 

function insert($postData) {		
$postData['description'] = clean($postData['description']);	
if(!EmailExists($postData['email'])){
$sql = " INSERT INTO tbl_emails SET
		email = '".$postData['email']."',
		postersname	= '".$postData['postersname']."',
		phone	= '".$postData['phone']."'
		";
		executeSql($sql);
}		
if(empty($_FILES['image']["name"])){						
		$sql = " INSERT INTO tbl SET
		title	= '".$postData['title']."',
		image	= '',
		postersname	= '".$postData['postersname']."',
		category 	= '".$postData['category']."',
		type	= '".$postData['type']."',
		state	= '".$postData['state']."',
		location	= '".$postData['location']."',
		email 	= '".$postData['email']."',
		phone	= '".$postData['phone']."',
		description	= '".$postData['description']."',
		time	= '".time()."'
		";
                        $inserted_id = mysql_insert_id();////Does this give me the id now?
		executeSql($sql);
}else{			
		global $uploadPath;
		$remove_symbols = array('+', '=', '-', '{', '}', '$', '(', ')','&');
		$removed_symbols = str_replace($remove_symbols, "_", 						$_FILES['image']['name']);  
		$randomnum=rand(00000000,99999999);  
		$imagepath = uploadFile($_FILES['image'], $uploadPath);
		$image = new SimpleImage();
		$image->load($imagepath);
		$image->resize(250,280);
		$resize_rename = $uploadPath.$randomnum._.$removed_symbols;
		$image->save($resize_rename);									
		unlink($imagepath); //delete the original file						
		$sql = " INSERT INTO tbl SET
		title	= '".$postData['title']."',
		image	= '".$resize_rename."',
		postersname	= '".$postData['postersname']."',
		category 	= '".$postData['category']."',
		type	= '".$postData['type']."',
		state	= '".$postData['state']."',
		location	= '".$postData['ocation']."',
		email 	= '".$postData['email']."',
		phone	= '".$postData['phone']."',
		description	= '".$postData['description']."',
		time	= '".time()."'
		";
                       $inserted_id = mysql_insert_id();////Does this give me the id now?
		executeSql($sql);						
		}
}

Link to comment
Share on other sites

How are you using your insert function? Is it supposed to send out the email aswell or is that later in the script.

If you can show us the context in which the function is used it might help us understand.

 

Also, is the executeSql function using the mysql_ or mysqli_ function set?

Link to comment
Share on other sites

hey mate, yes im planing to add the email function within the insert function. once user post is inserted it should imdtly send out an email with link to the post and to the email which the user posted in form.

 

i tried it like this to get the id

 

///////////////////////////////////Insert		
function insert($postData) {		
$postData['description'] = clean($postData['description']);	
if(!ifEmailExists($postData['email'])){
$sql = " INSERT INTO tbl__emails SET
		email = '".$postData['email']."',
		postersname	= '".$postData['postersname']."',
		phone	= '".$postData['phone']."'
		";
		executeSql($sql);
}		
if(empty($_FILES['image']["name"])){						
		$sql = " INSERT INTO tbl SET
		title	= '".$postData['title']."',
		image	= '',
		postersname	= '".$postData['postersname']."',
		category 	= '".$postData['category']."',
		type	= '".$postData['type']."',
		state	= '".$postData['state']."',
		location	= '".$postData['location']."',
		email 	= '".$postData['email']."',
		phone	= '".$postData['phone']."',
		description	= '".$postData['description']."',
		time	= '".time()."'
		";
		executeSql($sql);
		$inserted_id = mysql_insert_id();
		echo $inserted_id;
		/*Here ill add the email function with the link once i get the id*/
}else{			
		global $uploadPath;
		$remove_symbols = array('+', '=', '-', '{', '}', '$', '(', ')','&');
		$removed_symbols = str_replace($remove_symbols, "_", $_FILES['image']['name']);  
		$randomnum=rand(00000000,99999999);  
		$imagepath = uploadFile($_FILES['image'], $uploadPath);
		$image = new SimpleImage();
		$image->load($imagepath);
		$image->resize(250,280);
		$resize_rename = $uploadPath.$randomnum._.$removed_symbols;
		$image->save($resize_rename);									
		unlink($imagepath); //delete the original file						
		$sql = " INSERT INTO tbl SET
		title	= '".$postData['title']."',
		image	= '".$resize_rename."',
		postersname	= '".$postData['postersname']."',
		category 	= '".$postData['category']."',
		type	= '".$postData['type']."',
		state	= '".$postData['state']."',
		location	= '".$postData['location']."',
		email 	= '".$postData['email']."',
		phone	= '".$postData['phone']."',
		description	= '".$postData['description']."',
		time	= '".time()."'
		";
		executeSql($sql);	
		$inserted_id = mysql_insert_id();				
		echo $inserted_id;	
		/*Here ill add the email function with the link once i get the id*/
		}
}

 

and my executeSql function  is

 

    function executeSql($sql){
        $conn = db_connect();          
        $result = mysql_query($sql, $conn)
                      or die(mysql_error($conn));
        return $result;       
    }

Link to comment
Share on other sites

maybe i did it wrong, is this what u asked me to do?

 

/////////////////////////////////////SQL Execution     

    function executeSql($sql){

        $conn = db_connect();         

        $result = mysql_query($sql, $conn)

                      or die(mysql_error($conn));

        return $result;     

    }

if (executeSql($sql)) {

    $inserted_id = mysql_insert_id();

    var_dump($inserted_id);

}

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.