problem with inserting data into database

Codes here !

Moderators: macek, egami, gesf

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

Re: problem with inserting data into database

Post by egami » Thu Jun 07, 2012 4:41 am

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

on a different php file.. try

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

$table = "TABLENAMEHERE";

$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
ejsexton82
New php-forum User
New php-forum User
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey
Contact:

Re: problem with inserting data into database

Post by ejsexton82 » 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)) {
		$this->open_connection();
	}
	$result = mysql_query($sql, $this->connection);
	$this->confirm_query($result);
	return $result;
}

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest