CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 insert new value into listbox from textarea

Print topic Send  topic

Author Message
syah

Posts: 29
Posted: 03/19/2009, 8:55 PM

hi...
i have some problm using codecharge 4.0...
i hope anyone will help me...

i had create 3 list box
1. country
2. subcountry
3.city

the user will select them...
but the problm is, how the user want to insert new record in listbox city?
i had create one text area beside the city's listbox..,so user can choice either they want to add a new city....at the same time the record will automatic entered in city record and restaurant record where i put city_id in restaurant table...

please expalain clearly, because i'am a beginner programmer
anyone can help???
View profile  Send private message
damian

Posts: 838
Posted: 03/23/2009, 10:23 PM

Quote syah:
i had create 3 list box
1. country
2. subcountry
3.city
but the problm is, how the user want to insert new record in listbox city?
i had create one text area beside the city's listbox..,so user can choice either they want to add a new city....at the same time the record will automatic entered in city record and restaurant record where i put city_id in restaurant table...

i dont believe that you can do this strictly only in php - you would need some js/ajax to refresh the drop down after you submit the new city record....

can you post a link to your page so that we can see more of what you are doing....?


_________________
if you found this post useful take the time to help someone else.... :)
View profile  Send private message
syah

Posts: 29
Posted: 03/24/2009, 7:56 AM

i try to explain my problm clearly to get the answer...please reply as soon as possible...because i need to finish it

TABLE for city
city_name
city_id

TABLE for add restaurant
restaurant_id
restaurant_name
city_id

i had create one listbox for city and textbox if the name of city is not in the listbox.....if the user add their restaurant and fill up the city in the textbox because the city is not in the listbox...after user click the button add, automatically their record in database is fill in table city for a new city name and auto increment for city_id and at the same time,it record in the table add restaurant with a new city_id from table city...how i can do that?
View profile  Send private message
melvyn


Posts: 333
Posted: 03/24/2009, 10:03 AM

You need javascript. Some custom php and some understanding of how this work.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com
View profile  Send private message
damian

Posts: 838
Posted: 03/24/2009, 2:01 PM

Quote melvyn:
You need javascript. Some custom php and some understanding of how this work.
thats correct - what you are trying to do is not so *easy*.
please post a link to your webpage so we can see it...

_________________
if you found this post useful take the time to help someone else.... :)
View profile  Send private message
melvyn


Posts: 333
Posted: 03/24/2009, 2:12 PM

1) Create normal listbox and textbox for city.
2) Give the textbox the display property none: <input id="city_textbox"style="display:none"... >
3) The city listbox must have an option "other" <option value="other">Other</option>
4) The select statement of that listbox must fire a javascript to show/hide the textbox: <select id="city_list" name="city" onchange="javascript:toggleTextBox(this.value);">
5) This is the funcion for the javascript:
  
function toggleTextBox(cityname){  
  if(cityname == 'other'){  
    document.forms['0'].city_textbox.display = 'block'  
  }else{  
    document.forms['0'].city_textbox.display = 'none'  
  }  
}  

Until now, we can show/hide the textbox according to what the user select.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com
View profile  Send private message
melvyn


Posts: 333
Posted: 03/24/2009, 2:52 PM

Now let's go to CCS events
6) This event: BeforeBuildInsert; place this code:
  
// first let's check if the user entered a custom city  
if(strlen($Container->city_textbox->GetValue()) >0 ){  
  $db = new clsDBMydatabase();  
  $custom_city = $Container->city_textbox->GetValue();  
  $SQL = "INSERT INTO city (city_field) VALUES ('$custom_city') ";  
  $db->query($SQL);  
    
  // now let's find the last inserted id you need:  
  $SQL = "SELECT id FROM city WHERE city_field = '$custom_city'";  
  $db->query($SQL);  
  $city_id = $db->f(0); // now we have the id to the current city.  
   
  $Container->city_listbox->SetValue($city_id);  
    
}else{  
// do nothing  
}  

That must work. Some validations must be done, this mockup works. Tell us the results.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com
View profile  Send private message
syah

Posts: 29
Posted: 03/26/2009, 5:52 PM

thanks 4 reply...
but unsucessful result :-(

please explain me in another way...

i have one record name restaurant....in the record restaurant, user will enter their detail include their country,subcountry and city...but the problem is, when city is not in the listbox, user will enter their city in the textbox...after user click button add, the in the database will generate automatically...

i was create TABLE city
city
city_id

TABLE restaurant
restaurant_name
country_id
subcountry_id
city_id

TABLE country
country
country_id

TABLE subcountry
subcountry
subcountry_id

when user enter their detail, the new city will listed in and in the same time will add in the restaurant table....

how i can do a new detail in the listbox and TABLE city and at the same time add detail in the TABLE restaurant.....i need your help...
urgent....
View profile  Send private message
melvyn


Posts: 333
Posted: 03/26/2009, 9:12 PM

Please, read my last post. I'm sure it must work. it's not 100%; you must (at least) try it. If you don't get it working, report which error or which behavior you get. Your goal isn't so simple, anyways my detailed procedures will work, I promise.

_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com
View profile  Send private message
syah

Posts: 29
Posted: 03/28/2009, 9:24 AM

thanks melvyn for reply, i have done it, but still unsucessfully :(, it show this error:


The value in field s_city is not valid.

s_city is for listbox
City is for textbox

i have three listbox
s_country
s_subcountry
s_city

please give me some idea to solve it....

View profile  Send private message
melvyn


Posts: 333
Posted: 03/28/2009, 9:43 AM

Quote :
The value in field s_city is not valid.
Which datatype is supossed to be in s_city? I guess s_city must receive some integuer and is receiving text.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com
View profile  Send private message
syah

Posts: 29
Posted: 03/28/2009, 11:51 PM

i use integer in s_city because i use listbox and features PTDepandent Listbox for s_subcountry and s_city
View profile  Send private message
damian

Posts: 838
Posted: 03/29/2009, 5:57 AM

please post a link to your page so we can see what is happening....
_________________
if you found this post useful take the time to help someone else.... :)
View profile  Send private message
syah

Posts: 29
Posted: 03/29/2009, 8:37 AM

i'am just only done in my localhost...

if u have any idea please post step by step hw to insert the value from the textbox into listbox....
as i mention my problem before....

thnks for ur help
View profile  Send private message
syah

Posts: 29
Posted: 03/30/2009, 6:23 AM

please...anyone help......
View profile  Send private message
syah

Posts: 29
Posted: 04/07/2009, 1:36 AM

i have already done as u wrote before to insert the new from the textbox and it insert into TABLE city. hoe i want insert the value into TABLE restaurant that call the last id from TABLE city?
this is my coding to insert the last id from TABLE city into TABLE restaurant

function NewRecord1_AfterInsert(& $sender)
{
$NewRecord1_AfterInsert = true;
$Component = & $sender;
$Container = & CCGetParentContainer($sender);
global $NewRecord1; //Compatibility
//End NewRecord1_AfterInsert

//Custom Code @31-2A29BDB7
// -------------------------

if(strlen($Container->City->GetValue()) >0 )
{
$db = new clsDBhalal2all();
$SQL = "SELECT MAX(city_id) FROM city";
$db->query($SQL);
if ($db->next_record())
{
$city_id = $db->f(0);
}


$db2 = new clsDBhalal2all();
while ($db->next_record())
{
$SQL = "INSERT INTO restaurant (city_id) VALUES (" . $db2->ToSQL($city_id,ccsInteger).")";
$db2->query($SQL);
}
unset($db2);

}

View profile  Send private message
melvyn


Posts: 333
Posted: 04/07/2009, 6:08 AM

Quote syah:
i have already done as u wrote before to insert the new from the textbox and it insert into TABLE city. hoe i want insert the value into TABLE restaurant that call the last id from TABLE city?

Getting the last id can be very tricky. if you read above then check my post. I wrote how to get the last id.

Don't try with "SELECT max(id) FROM city".
Why? Because if there are 2 users inserting then that last id can't be trusted.

On 03/24/2009 2:52 PM I posted:
  
// now let's find the last inserted id you need:    
  $SQL = "SELECT id FROM city WHERE city_field = '$custom_city'";    
  $db->query($SQL);    
  $city_id = $db->f(0); // now we have the id to the current city.    
How that work? It select the only ID which belongs to the city you have entered right now.


Another thing:
$db2 = new clsDBhalal2all();
....
unset($db2);

unset ? why?

Please call the close method after using your db connection
$db2 = new clsDB...
<your operations>
$db2->close();

Another one:
  
while ($db->next_record())  
{  
$SQL = "INSERT INTO restaurant (city_id) VALUES (" . $db2->ToSQL($city_id,ccsInteger).")";  
$db2->query($SQL);  
}  

Never, never, never, I mean NEVER do that!!!

You're doing a loop of inserts. That can overload your server without reason. Sorry that's very very <reserved comment>

Change to:

  
$SQL = "INSERT INTO restaurant (city_id) VALUES ";  
while ($db->next_record())  
{  
$SQL .= "(" . $db2->ToSQL($city_id,ccsInteger).")";  
}  
  
$db2->query($SQL);  

That will build one SQL and execute once.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com
View profile  Send private message
syah

Posts: 29
Posted: 04/08/2009, 6:17 PM

it's unsucessfully i put all the code in beforebuildinsert event....it's that true?in TABLE city,the new data is insert but another TABLE, TABLE restaurant, it not call city_id from TABLE city, if any wrong please correct it...i'm so glad for ur help...

if(strlen($Container->City->GetValue()) >0 ){
$db = new clsDBhalal2all();
$custom_city = $Container->City->GetValue();
$SQL = "INSERT INTO city (city) VALUES ('$custom_city') ";
$db->query($SQL);

//now let's find the last inserted id you need:
$SQL = "SELECT city_id FROM city WHERE city_id = '$custom_city'";
$db->query($SQL);
$city_id = $db->f(0); // now we have the id to the current city.

$Container->s_city->SetValue($city_id);

$db2 = new clsDBhalal2all();
$SQL = "INSERT INTO restaurant (city_id) VALUES ";
while ($db->next_record())
{
$SQL .= "(" . $db2->ToSQL($city_id,ccsInteger).")";
}

$db2->query($SQL);



}
else{
// do nothing
}
View profile  Send private message
gaetgodi

Posts: 9
Posted: 11/13/2009, 1:14 PM

I had to add .style to the javascript code to get it to work. Given that I am not a Java programmer this cost me lots of time to find... on the plus side, I learned a lot about javascript

function toggleTextBox(cityname){
if(cityname == 'other'){
document.forms['0'].city_textbox.style.display = 'block'
}else{
document.forms['0'].city_textbox.style.display = 'none'
}
}
View profile  Send private message
gaetgodi

Posts: 9
Posted: 11/13/2009, 3:30 PM

Followed all these instructions, works great for me. Thanks for your contributions...
In my case the drop-downl lists were fields in the same table in which I was inserted the record. The effect of inserting each one of these fields would have been to create new rows that I did not wish. I only wished the new row to be created with the new fields in place. I put this code in the BeforeInsert event ( I had four lists that potentially could have new entries): Obviously the fields ending with a 1 are the text field.

I created one row in my table with "Other" in each one of the fields to supply my "Other" value to trigger the text box.

$custom_app = $Container->Application1->GetValue(true);
if(strlen($custom_app) >0 ){
$Container->Application->SetValue($custom_app);
}
$custom_app = $Container->Topic1->GetValue(true);
if(strlen($custom_app) >0 ){
$Container->Topic->SetValue($custom_app);
}
$custom_app = $Container->Type1->GetValue(true);
if(strlen($custom_app) >0 ){
$Container->Type->SetValue($custom_app);
}
$custom_app = $Container->FAQ1->GetValue(true);
if(strlen($custom_app) >0 ){
$Container->FAQ->SetValue($custom_app);
}
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.