Hi,
I am creating a form to insert information into 2 tables in mysql database,
And i wanted to know how to define the language field in my node table (i am using drupal).
This is my code so far.....
<?php
// Giving nodeid a value
$sqlCommand = "SELECT MAX(nid) FROM node";
$query = mysql_query($sqlCommand) or die(mysql_error());
while ($row = mysql_fetch_array($query))
$bert = max($row) + 1;
// Giving position a value
$sqlCommand = "SELECT MAX(position) FROM cars";
$query = mysql_query($sqlCommand) or die(mysql_error());
while ($row = mysql_fetch_array($query))
$stu = max($row) + 1;
// Get values from form and add values to nodeid
$car_name=$_POST['car_name'];
$car_info=$_POST['car_info'];
$colour=$_POST['colour'];
$bhp=$_POST['bhp'];
$power=$_POST['power'];
$price=$_POST['price'];
$engine=$_POST['engine'];
$picture=$bert;
$link=$bert;
$type = "product";
$title=$_POST['car_name'];
$visible = 1;
$position = $stu;
// Inserting values into node table
define('DRUPAL_ROOT', getcwd());
include_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$form_state = array();
module_load_include('inc', 'node', 'node.pages');
$node = array('type' => 'product');
$form_state['values']['title'] = $title;
$form_state['values']['uid'] = 1;
$form_state['values']['op'] = t('Save');
drupal_form_submit('product_node_form', $form_state, (object)$node);
// Insert data into cars table
$sql="INSERT INTO $tbl_name2(title, uid)VALUES('$type', '$title')";
$sql="INSERT INTO $tbl_name(car_name, position, visible, car_info, colour, link, bhp, power, price, picture, engine)VALUES('$car_name', $position, $visible, '$car_info', '$colour', '$link', '$bhp', '$power', '$price', '$picture', '$engine')";
$result=mysql_query($sql);
if($result){
$url = "http://www.test.co.uk/?q=node/13";
header( "Location: $url" );
}
else {
echo "ERROR";
}
// close connection
mysql_close();
?>
How can I define the language of mysql record using php?
Moderator: General Moderators
Re: How can I define the language of mysql record using php?
First of all use:
[ syntax=php ][ /syntax ]
for your code
its much easier to read it.
What do you want to achieve?
[ syntax=php ][ /syntax ]
for your code
What do you want to achieve?
Which table? what language? you want to extend table in your db? or pull current language from drupal? Please be more specific.And i wanted to know how to define the language field in my node table (i am using drupal).
Re: How can I define the language of mysql record using php?
Ok thanks 
The node table, i just wanted to use the 'und' default language from drupal.
I get a error message when i use the code to create the table just saying "Undefined property: stdClass::$language"
Thanks for the help,
Rob
The node table, i just wanted to use the 'und' default language from drupal.
I get a error message when i use the code to create the table just saying "Undefined property: stdClass::$language"
Thanks for the help,
Rob
Re: How can I define the language of mysql record using php?
Add
Before:
Code: Select all
global $language ;Code: Select all
$lang_name = $language->language ;Re: How can I define the language of mysql record using php?
Getting this warning :s
Notice: Undefined property: stdClass::$language in node_form() (line 302 of /homepages/25/d358721086/htdocs/modules/node/node.pages.inc).
Notice: Undefined property: stdClass::$language in node_form() (line 302 of /homepages/25/d358721086/htdocs/modules/node/node.pages.inc).
Re: How can I define the language of mysql record using php?
Can you post some code where you're using this $language?
This one above doesn't have it
This one above doesn't have it