Jump to content

'insert into' won't work on mysql


gongpex

Recommended Posts

Hello everyone,

 

today I test to record data on mysql using this code :

mysql_query("insert into member           (m_user,m_pass,m_name,m_email,m_phone,m_cell,m_address,m_address2,m_country,m_city,m_join,m_security,m_secure,m_post)             values		   ('$u_user','$u_pass','$u_name','$u_email','$u_phone','$u_cell','$u_address','$u_address2','$u_country','$u_city','$u_join','$u_security','$secure','$u_post')");

this code work well when I use mysql previous version mysql-essential-5.1.24-rc-win32.msi (32 bit) for windows.

 

but when I change mysql (same version) but 64 bit for windows, it won't to record.

 

I had tried using phpmyadmin using insert into it's successful to record data.

 

Q : Is different bit can affects on syntax?

 

my specification : Apache24 (32 bit) win

: php 5.3.0

: phpmyadmin 3.4.3.1-all language

: mysql-essential-5.1.73-winx64.msi

 

note : this code had connect to database using code :

$host = "localhost"; $user = "root"; $pass = "12345678"; $dtb = "mysql"; $connect = mysql_connect($host,$user,$pass); $db = mysql_select_db($dtb,$connect);

please help me

 

Thanks

 

 

Link to comment
Share on other sites

did you check for mysql errors? I would start there and find out what's it's telling you the problem is.

Link to comment
Share on other sites

mysql error log did you mean?

 

I found this on : log_error

140307 21:50:30 [Note] Plugin 'FEDERATED' is disabled.140307 21:50:30  InnoDB: Initializing buffer pool, size = 44.0M140307 21:50:30  InnoDB: Completed initialization of buffer poolInnoDB: The first specified data file .ibdata1 did not exist:InnoDB: a new database to be created!140307 21:50:30  InnoDB: Setting file .ibdata1 size to 10 MBInnoDB: Database physically writes the file full: wait...140307 21:50:31  InnoDB: Log file .ib_logfile0 did not exist: new to be createdInnoDB: Setting log file .ib_logfile0 size to 22 MBInnoDB: Database physically writes the file full: wait...140307 21:50:33  InnoDB: Log file .ib_logfile1 did not exist: new to be createdInnoDB: Setting log file .ib_logfile1 size to 22 MBInnoDB: Database physically writes the file full: wait...InnoDB: Doublewrite buffer not found: creating newInnoDB: Doublewrite buffer createdInnoDB: Creating foreign key constraint system tablesInnoDB: Foreign key constraint system tables created140307 21:50:35  InnoDB: Started; log sequence number 0 0140307 21:50:35 [Note] Event Scheduler: Loaded 0 events140307 21:50:35 [Note] C:Program FilesMySQLMySQL Server 5.1binmysqld: ready for connections.Version: '5.1.73-community'  socket: ''  port: 3306  MySQL Community Server (GPL)

note : this error log I got from function : show variables like '%log%';

 

when I open mysql

 

please help me

 

thanks

_________________________________________________________________________________________________________

 

off : Can I know what OS that you are use currently? I ask this because since I use windows 8, I always found a problem during installation web software

like this, it's different while I use windows XP. Again, thanks if you answer this off question

Link to comment
Share on other sites

I meant this, for checking mysql_errors

http://www.php.net/mysql_error

 

Locally, I develop on a Mac, so it's "unixy" (technically a mish-mash of BSDs and other stuff). my dev server runs on CentOS (linux based).

Link to comment
Share on other sites

hello,

 

I had tried to use mysql_error() like this :

<?php$host ="localhost";$user = "root";$pass = "12345678";$database = "gong";$connect = mysql_connect($host,$user,$pass);mysql_select_db($database,$connect);echo mysql_errno($connect). ":" . mysql_error($connect). "n";?>

and also :

<?php$u_user = $_POST["u_user"];$u_pass = $_POST["u_pass"];$u_name= $_POST["u_name"];$u_address =$_POST["u_address"];$u_address2 =$_POST["u_address2"];$u_phone = $_POST["u_phone"];$u_cell = $_POST["u_cell"];$u_email = $_POST["u_email"];$u_country = $_POST["u_country"];$u_city = $_POST["u_city"];$u_post = $_POST["u_post"];$u_security = $_POST["u_security"];$secure = $_POST['secure'];$u_join = date('D d M Y');$u_save = mysql_query("insert into member           (m_user,m_pass,m_name,m_email,m_phone,m_cell,m_address,m_address2,m_country,m_city,m_join,m_security,m_secure,m_post)             values		   ('$u_user','$u_pass','$u_name','$u_email','$u_phone','$u_cell','$u_address','$u_address2','$u_country','$u_city','$u_join','$u_security','$secure','$u_post')");		   echo mysql_errno($u_save). ":" . mysql_error($u_save). "n";?>

but it's didn't result anything, it only show 0 :

 

Q : Is there mistake on placed this code?

 

:( : I astonished, why only "insert into" syntax that got trouble, another syntax is alright............

 

please help

 

thanks

_________________________________________________________________________________________________

 

thanks before for your off answer,

 

OQ : I heard from my friend if linux can be modified, but it must using C or C++ is that true?

Edited by gong
Link to comment
Share on other sites

You're passing the return value of mysql_query to mysql_error, that is not correct. The error functions take a connection resource, not a result resource.I highly recommend that you stop working with the mysql extension, and switch to either mysqli or PDO instead. Your code above is not correct or secure because you are using values from $_POST directly in a query without any sanitization. If you were using prepared statements with mysqli or PDO then that wouldn't be a problem.

Link to comment
Share on other sites

 

 

You're passing the return value of mysql_query to mysql_error, that is not correct. The error functions take a connection resource, not a result resource.

 

I had tried using mysql_error() on connection too as what thescientist said, but the result is : "0 :"

 

please see :

<?php$host ="localhost";$user = "root";$pass = "12345678";$database = "gong";$connect = mysql_connect($host,$user,$pass);mysql_select_db($database,$connect);echo mysql_errno($connect). ":" . mysql_error($connect). "n";?>

I had tried to change setting from mysql to mysqli but it didn't work here my code :

<?php $host = "localhost"; $user = "root"; $pass = "12345678"; $dtb = "gong"; $connect = mysqli_connect($host,$user,$pass); $db = mysqli_select_db($dtb,$connect);    if($db) {       echo "successful connect";		}else{		echo "there is failure";		} 		?>

the result is : there is failure

 

Q1 : Is there some mistake configuration on my php.ini? (on attach file on php.txt please rename it on .ini)

 

Q2 : if I change mysql to mysqli, is data that I imported from mysql (data.sql for example) can be exported to database that using mysqli?

 

please help

 

thanks

php.txt

Edited by gong
Link to comment
Share on other sites

I had tried using mysql_error() on connection too as what thescientist said, but the result is : "0 :"

OK, then that means there is no error.

I had tried to change setting from mysql to mysqli but it didn't work here my code :

You're not using mysqli_select_db correctly, check the manual:http://www.php.net/manual/en/mysqli.select-db.php

if I change mysql to mysqli, is data that I imported from mysql (data.sql for example) can be exported to database that using mysqli?

I don't know what you're asking. Changing from mysql to mysqli does not change the database, it changes how PHP interacts with the database.
Link to comment
Share on other sites

hello,

 

thanks this work well even "insert into" can be record data now.

 

but I want to ask about PDO,

 

Q : Is this same with mysql? where I can download it?

__________________________________________________________________________________________________________

OFFQ : I want to ask what OS that you are use currently? if you using linux please give me tutorial about it, because I want to try to use linux,

btw I heard from my friend if linux can be modified by ourself (using C or C++) is that true?

(I really2 appreciate and thanks again if you want to answer my OFFQ because this important for me)

Link to comment
Share on other sites

if you want to learn about PDO, just look it up.

http://php.net/pdo

 

mysql is old and deprecated. I would favor the use of PDO over mysqli though.

 

If you want tinker with the linux kernel, since it is open source, you can always clone the repo and fiddle with it yourself.

https://github.com/torvalds/linux

 

It is written in C.

Link to comment
Share on other sites

hello,

 

I had visit on : http://php.net/pdo

 

but when I open about requirement : http://id1.php.net/manual/en/pdo.requirements.php

 

the page shown : "No external libraries are needed to build this extension"

 

Q : so, that's mean I don't need to download database anymore, just use mysql database and then change the configuration on php.ini?

_________________________________________________________________________________________________________

 

thanks for OFF answer, I appreciate it, but I still wonder with oracle database,

 

OFFQ : Is this database is more powerful than other database? (because I heard oracle DB, more complicated than other database)

Link to comment
Share on other sites

Hello,

 

I had tried to connect PDO using this code :

<?php$user = "root";$pass = "12345678";try {     $dbh = new PDO('mysql:host=localhost;dbname=test',$user,$pass);	 foreach($dbh->query('SELECT * from person') as $row) {	    print_r($row);    }	$dbh = null;} catch (PDOException $e) {  print "Error! :" . $e->getMessage()."<br/>";  die();}?> 

it's result : "Error! :could not find driver"

 

Q : How to fix this problem?

 

OQ : So, is oracle DB not free?

 

thanks

Edited by gong
Link to comment
Share on other sites

Q : so, in other word I need to configure php.ini ?

_________________________________________________________________________

 

OQ : what do you think about PostGre SQL? Is that more effective and safe than mysql or PDO ?

Link to comment
Share on other sites

You need to enable the drivers that you want to use in php.ini.

what do you think about PostGre SQL? Is that more effective and safe than mysql or PDO ?

PostgreSQL is a database, PDO is an API. You can use PDO to work with a PostgreSQL database also. These are the databases that PDO supports:http://www.php.net/manual/en/pdo.drivers.php
Link to comment
Share on other sites

I think today I found my true problem,

 

please see these code :

 

CODE no 1)

<?php require("connect.php");  mysqli_query($connect,"SELECT * FROM person");  $user = $_POST['test']; $name = $_POST['num'];  $ins = mysqli_query($connect,"INSERT INTO person(user,name) VALUES ('$user','$name')");  if($ins) { echo "n". "inserted"; } else {  echo "n". "trouble"; }  ?>

this is connect.php

<?php $host = "localhost"; $user = "root"; $pass = "12345678"; $dtb = "test"; $connect = mysqli_connect($host,$user,$pass); $db = mysqli_select_db($connect,$dtb);?>

But, after I change it like this (change database also) :

 

CODE no 2)

<?php require("connect_db.php");  mysqli_query($connect,"SELECT * FROM member");  $user = $_POST['test']; $name = $_POST['num'];  $ins = mysqli_query($connect,"INSERT INTO member(m_user,m_name) VALUES ('$user','$name')");  if($ins) { echo "n". "inserted"; } else {  echo "n". "trouble"; }  ?>

this connect_db.php

<?php$host ="localhost";$user = "root";$pass = "12345678";$database = "exercise";$connect = mysqli_connect($host,$user,$pass);$data = mysqli_select_db($connect,$database);?>

on CODE no 1 this is successful to record data it's display : "inserted" , but after I change it like CODE no 2 it's display "trouble",

 

note : database test and table person I made it manually.

: but database exercise and table member I got it from import SQL (it's shape extension .sql) from phpmyadmin (this still use mysql not mysqli)

so,database exercise is from my old data (from my web hosting)

 

Q : Is SQL file data that I got from import unable to record data ?

 

please help

 

thanks

Edited by gong
Link to comment
Share on other sites

like we've told you in other threads, use error handling / reporting. don't just guess, actually have the code tell you what the problem is.

Link to comment
Share on other sites

like we've told you in other threads, use error handling / reporting

 

did you mean mysql_error() ? if so, please see on this thread post #7 .

 

actually have the code tell you what the problem is.

 

well, this is my code :

<?php require("connect_db.php");  mysqli_query($connect,"SELECT * FROM member");  $user = $_POST['test']; $name = $_POST['num'];  $ins = mysqli_query($connect,"INSERT INTO member(m_user,m_name) VALUES ('$user','$name')");  if($ins) { echo "n". "inserted"; } else {  echo "n". "trouble"; }  ?>

this is registered.php

 

and this is my form file :

<form name="test" action="registered.php" method="post"> user : <input type="text" name ="test" id="test" /><br /> name : <input type="text" name ="num" id="num" />  <input type="submit" value="SUBMIT" /></form>

this is register.php

 

in here I just use simple form just to test whether database can be record or not,

 

this is my problem : when I use code on above (registered.php) using database "exercise" it won't to record data from register.php, but if I use database "test" (with change connect_db.php) it can be record.

 

for more information about both database and my problem, please read my post on #17 again.

 

thanks

 

Link to comment
Share on other sites

 

did you mean mysql_error() ? if so, please see on this thread post #7 .

 

I don't see you using it in this latest code though.

Link to comment
Share on other sites

hello,

 

sorry for long reply,

 

I don't see you using it in this latest code though.

 

this is my code :

 

connect_db-server.php

<?php$host ="localhost";$user = "root";$pass = "1234567";$database = "test";$connect = mysqli_connect($host,$user,$pass);$data = mysqli_select_db($connect,$database);echo mysqli_errno($connect). ":" . mysqli_error($connect). "n";?> 

this result : 0 :

 

com.php :

<form name="test" action="test.php" method="post"> user : <input type="text" name ="test" id="test" /><br /> name : <input type="text" name ="num" id="num" /> <!--id : <input type="text" name ="id" id="id" /> -->  <input type="submit" value="SUBMIT" /></form> 

test.php as destination and insert into syntax location :

<?php require("connect_db-server.php");  mysqli_query($connect,"SELECT * FROM person");  $user = $_POST['test']; $name = $_POST['num']; $ins = mysqli_query($connect,"INSERT INTO person(user,name) VALUES ('$user','$name')");  if($ins) { echo "n". "inserted"; } else {  echo "n". "trouble"; }  ?> 

this result : trouble

 

today I had check what php version that used by my web hosting,

 

my php version is 5.3.0 and my web hosting using version 5.3.1

 

but I still have problem like this, that after I import data from web hosting server (database.sql),

 

I astonished, when I create database manually then I use insert into syntax like on above it's result : "inserted" or successful.

But after I import database.sql from my web hosting then I use insert into syntax, it's shown : "trouble" or failed.

(this is same name database,table and column)

 

Q : Is different php version can give some effect on import and export SQL data?

 

please help me

 

thanks

 

Link to comment
Share on other sites

This entire thread is about checking for MySQL errors, and you're still not doing that? Look at what the manual page for mysqli_query says:

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

It says it returns false on failure. According to your if statement, it returned false. So the query failed. So, how are you going to check to see what error happened in the query? Since post 2 in this thread we've been trying to get you to check for MySQL errors. How else do you plan on finding out what the problem is if you're not checking for errors? Why are you printing "trouble" instead of the actual error message?
Link to comment
Share on other sites

I think I need to clarify about this :

 

- Is code like :

<?php$host ="localhost";$user = "root";$pass = "1234567";$database = "test";$connect = mysqli_connect($host,$user,$pass);$data = mysqli_select_db($connect,$database);echo mysqli_errno($connect). ":" . mysqli_error($connect). "n";?> 

Q : not what did you mean?

 

if so, please show me what code that supposed I use

 

please help

 

many thanks

Link to comment
Share on other sites

the error happens when you run the query. That's where you need to put. It's not going mean anything to log an error when no error has happened yet.

 

I linked you a reference for how to use it in the fourth post of this thread.

 

edit: make sure you look for mysqli equivalents as you have migrated to that over the course of this thread

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...