PHP Classes

insert problem

Recommend this page to a friend!

      PDO Multi Connection Class  >  All threads  >  insert problem  >  (Un) Subscribe thread alerts  
Subject:insert problem
Summary:please help me to solve insert problem, thank you!
Messages:3
Author:CamusHsu
Date:2017-06-20 06:09:46
 

  1. insert problem   Reply   Report abuse  
Picture of CamusHsu CamusHsu - 2017-06-20 06:09:46
Dear Sir,
I tried to insert one data as below,
$result = $db->query("INSERT INTO TB_USERS (NAME, ADDRESS, COMPANY) VALUES ('Evert Ulises German', 'Internet #996 Culiacan Sinaloa', 'Freelancer');");

I get bool(true) message, but the data doesn't insert into the database.

I tried another way to insert one data as below,
$result = $db->insert("TB_USERS", "NAME='Yusef German',ADDRESS='Tetameche #3035 Culiacan Sin. Mexico',COMPANY='Aluminium'");

It works well, so I can't use $db->query(insert......)?

Thank you!

CamusHsu


  2. Re: insert problem   Reply   Report abuse  
Picture of Evert Ulises German Soto Evert Ulises German Soto - 2017-06-23 21:03:14 - In reply to message 1 from CamusHsu
Hi CamusHsu,

This way is more secure because with prepared statements you prevent sql injection.
$result = $db->query("INSERT INTO TB_USERS (NAME, ADDRESS, COMPANY) VALUES (?,?,?);", array('Evert Ulises German', 'Internet #996 Culiacan Sinaloa', 'Freelancer'));

You can check if return some error with:
echo $db->getError();

Best regards!

  3. Re: insert problem   Reply   Report abuse  
Picture of CamusHsu CamusHsu - 2017-06-29 08:20:00 - In reply to message 2 from Evert Ulises German Soto
Dear Sir,

Thank for your reply.

CamusHsu

 
For more information send a message to info at phpclasses dot org.