problem with inserting data into database

Codes here !

Moderators: egami, macek, gesf

Post Reply
User avatar
php-forum GURU
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Thu Jun 07, 2012 4:41 am

Sorry, I'm not a big fan of OOP..

on a different php file.. try

$connect = mysql_connect("IPADDRESS","USERNAME","PASSWORD");
$db = mysql_select_db("DATABASENAME");


$query = "SELECT * FROM $table LIMIT 20";
$result = mysql_query($query) or die (mysql_error());

if (mysql_num_rows($result) > 0) {
echo "SQL READ QUERY WORKS! YAY! <br />";

$query = "INSERT INTO $table (fieldname1,fieldname2,fieldname3) VALUES ('$value1','$value2','$value3')";
$result = mysql_query($query) or die (mysql_error());
if (mysql_affected_rows() > 0) {
echo "SQL WRITE WORKS! YAY!<br/>";

User avatar
New php-forum User
New php-forum User
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey

Thu Jun 07, 2012 10:14 pm

For some reason, $connection is not set. Possibly, a call to close_connection() was made earlier in the code, unsetting $connection.

Try opening the connection at the beginning of the query() function:

Code: Select all

public function query($sql){
	if(!isset($this->connection) || !is_resource($this->connection)) {
	$result = mysql_query($sql, $this->connection);
	return $result;

Post Reply