How can I define the language of mysql record using php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Rob_Scott
Forum Newbie
Posts: 19
Joined: Mon Nov 14, 2011 6:08 am

How can I define the language of mysql record using php?

Post by Rob_Scott »

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();
?>
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: How can I define the language of mysql record using php?

Post by maxx99 »

First of all use:
[ syntax=php ][ /syntax ]
for your code ;) its much easier to read it.

What do you want to achieve?
And i wanted to know how to define the language field in my node table (i am using drupal).
Which table? what language? you want to extend table in your db? or pull current language from drupal? Please be more specific.
Rob_Scott
Forum Newbie
Posts: 19
Joined: Mon Nov 14, 2011 6:08 am

Re: How can I define the language of mysql record using php?

Post by Rob_Scott »

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
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: How can I define the language of mysql record using php?

Post by maxx99 »

Add

Code: Select all

global $language ;
Before:

Code: Select all

 $lang_name = $language->language ;
Rob_Scott
Forum Newbie
Posts: 19
Joined: Mon Nov 14, 2011 6:08 am

Re: How can I define the language of mysql record using php?

Post by Rob_Scott »

Getting this warning :s

Notice: Undefined property: stdClass::$language in node_form() (line 302 of /homepages/25/d358721086/htdocs/modules/node/node.pages.inc).
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: How can I define the language of mysql record using php?

Post by maxx99 »

Can you post some code where you're using this $language?
This one above doesn't have it
Post Reply