How can I define the language of mysql record using php?
Posted: Tue Dec 06, 2011 3:50 am
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();
?>
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();
?>