PDA

View Full Version : Arghh, mysql insert not working in VB


Jaynesh
04-07-2006, 12:44 PM
:tired: I have been trying to get it to insert values into a table.

Ive intergrated it with vBulletin and its database, but it just does not insert the values.

I receive no error message.


<?php

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ##################### DEFINE IMPORTANT CONSTANTS #######################
// change the line below to the actual filename without ".php" extention.
// the reason for using actual filename without extention as a value of this constant is to ensure uniqueness of the value throughout every PHP file of any given vBulletin installation.

define('THIS_SCRIPT', 'test');

// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
// change the lines below to the list of actual templates used in the script
'quotegen',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');

// #################### HARD CODE JAVASCRIPT PATHS ########################
$headinclude = str_replace('clientscript', $vbulletin->options['bburl'] . '/clientscript', $headinclude);

// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################

$navbits = array();
// change the line below to contain whatever you want to show in the navbar (title of your custom page)
$navbits[$parent] = 'Test Page';

$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');

// change the line below to contain the name of the actual main output template used in your script
eval('print_output("' . fetch_template('quotegen') . '");');

$vbulletin->db->query_write("INSERT INTO quotegen VALUES ('hello')");
?>


What am i doing wrong?

peterska2
04-07-2006, 02:11 PM
I'm not a php expert by a long way, but it looks like the problem is here$vbulletin->db->query_write("INSERT INTO quotegen VALUES ('hello')"); I believe it should be$db->query_write("INSERT INTO quotegen VALUES ('hello')"); If I'm wrong I apologise, but looking at similar queries in vB, it is always set out the second way.

Jaynesh
04-07-2006, 02:48 PM
Doesnt work :(

sabret00the
04-07-2006, 03:58 PM
having not provided the error messge, i'm not totally sure, but...

$vbulletin->db->query_write("INSERT INTO quotegen(colname) VALUES ('hello')");

Jaynesh
04-07-2006, 04:51 PM
I get no error message. it just does not insert into the table

Aesma Deva
04-08-2006, 10:26 AM
Try adding the column where you want to add the data, like this:

$db->query_write("INSERT INTO quotegen (column_name) VALUES ('hello')")

(Replace column_name with the name of the column you want to add your data at)

akanevsky
04-08-2006, 01:18 PM
I believe that the query is not executed because it's placed after print_output.

sabret00the
04-08-2006, 02:13 PM
I believe that the query is not executed because it's placed after print_output.
yup you're right, totally missed that, print_output had a die in there.

Jaynesh
04-09-2006, 08:59 AM
Aesma Deva, Tried that never worked :(

Psionic Vision, sabret00the, How would i fix it, im a newbie to php:(

sabret00the
04-09-2006, 09:06 AM
<?php

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ##################### DEFINE IMPORTANT CONSTANTS #######################
// change the line below to the actual filename without ".php" extention.
// the reason for using actual filename without extention as a value of this constant is to ensure uniqueness of the value throughout every PHP file of any given vBulletin installation.

define('THIS_SCRIPT', 'test');

// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
// change the lines below to the list of actual templates used in the script
'quotegen',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');

// #################### HARD CODE JAVASCRIPT PATHS ########################
$headinclude = str_replace('clientscript', $vbulletin->options['bburl'] . '/clientscript', $headinclude);

// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################


$vbulletin->db->query_write("INSERT INTO quotegen VALUES ('hello')");

$navbits = array();
// change the line below to contain whatever you want to show in the navbar (title of your custom page)
$navbits[$parent] = 'Test Page';

$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');

// change the line below to contain the name of the actual main output template used in your script
eval('print_output("' . fetch_template('quotegen') . '");');
?>

Jaynesh
04-09-2006, 09:09 AM
Thankyou Thankyou Thankyou Thankyou :D Its working, you dont know how happy i am :)