Error INSERT (Mysqli object oriented )

Codes here !

Moderators: macek, egami, gesf

gabbopeace
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Jul 25, 2013 3:16 am

Error INSERT (Mysqli object oriented )

Postby gabbopeace » Thu Jul 25, 2013 3:31 am

Hello guys, i'm new there and i try not to break the forum rules in the first topic yet.
I'm writing a little application in php and mysqli but i can't resolve an error: php refuse to run an insert query, there is the code:

Code: Select all

$sql = "INSERT INTO `money`.`spese` (`ID`, `Mese`, `Importo`, `Oggetto`, `Info`, `Data`) VALUES (NULL, '1','$_GET[euro]','$_GET[ogg]','$_GET[info]','2013-04-04');";
if(!$link->query($sql)){
     print_r("error INSERT");


php is regulary connected to my db and his object name is "link", but i can't even INSERT anything from php pages...Any solution?
Thanks.

developerahusain
New php-forum User
New php-forum User
Posts: 44
Joined: Tue May 28, 2013 10:04 pm
Location: India,Lucknow

Re: Error INSERT (Mysqli object oriented )

Postby developerahusain » Thu Jul 25, 2013 6:18 am

this is my tried and tested code. You can modify it as per your requirements
if(mysql_query("insert into test_database.f0001_name(mn,en,Title,Fullname,Fname,Lname,Mname,Oname) values ('"
.$_SESSION['mn']."','".$_SESSION['en']."','".$titel."',
'".$_POST['txtfullname']."','".$_POST['txtfirstname']."','".$_POST['txtlastname']."','".$_POST['txtmiddlename']."','".$_POST['txtothername']."')") or die("the eror ".mysql_error())) ;
developerahusain

gabbopeace
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Jul 25, 2013 3:16 am

Re: Error INSERT (Mysqli object oriented )

Postby gabbopeace » Thu Jul 25, 2013 9:13 am

Thanx for your reply developerahusain, but i tried it just before looking again at the forum, but the script continue simply to execute ( generating any error ) but no rows are added in the mysql DB. I hope in some other help then.
Gabbopeace
Last edited by gabbopeace on Fri Jul 26, 2013 12:19 am, edited 1 time in total.

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Error INSERT (Mysqli object oriented )

Postby johnj » Thu Jul 25, 2013 8:06 pm

when there is an error, please print the error message using $link->error

gabbopeace
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Jul 25, 2013 3:16 am

Re: Error INSERT (Mysqli object oriented )

Postby gabbopeace » Fri Jul 26, 2013 12:07 am

It was an idiot mistake: i give all privileges to an user for my db from all location, but i forget that mysql need the specification for 'user'@'localhost'. Among other i was using for the first time mysqli object-oriented and i was doing some other mistakes in printing error. In any case i'm pretty sure $link->error wasn't printing anything. Thanx to all.

P.S. ( I've to change the post title? i think the error was off-topic... )


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest