excecute if $mysqli->query successfull

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

excecute if $mysqli->query successfull

Post by someguyhere »

I'm trying to execute something only of the data is successfully inserted into the database, but I'm clearly doing something wrong. I've done as bit of digging around the forum, and it looks like the solutions to similar issues are for older versions of php...I could be wrong through, I'm just at the beginning of learning php. Anyway, I've tried to piece together the code based on what I've found on the forum, but it doesn't seem to be working - in this case, it executes whether the data is successfully inserted into the database or not.

Code: Select all

		$mysqli->query("INSERT INTO ag_pages (page_date, page_type, page_url, page_keyword, page_title, page_content) VALUES ('$page_date', '$page_type', '$new_page_url', '$new_page_keyword', '$new_page_title', '$new_page_content')");

		if($mysqli){
			stuff to excecute here
}
If I change it to

Code: Select all

		if($mysqli->query){
Then it doesn't execute at all. I'm at a loss as to what to do here. Any advice?
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: excecute if $mysqli->query successfull

Post by Darhazer »

Code: Select all

$result = $mysqli->query("INSERT INTO ag_pages (page_date, page_type, page_url, page_keyword, page_title, page_content) VALUES ('$page_date', '$page_type', '$new_page_url', '$new_page_keyword', '$new_page_title', '$new_page_content')");

                if($result){
                        stuff to excecute here
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Re: excecute if $mysqli->query successfull

Post by someguyhere »

Thanks! Worked perfectly!
Post Reply