Reply
A Very Very Strange Problem
Old 05-03-2008, 11:19 AM A Very Very Strange Problem
Junior Talker

Posts: 2
Hello
for 5 hours i am trying to figure out this strange problem but can't so i came here if any one of you can solve it.

What i want to do is get the text value of a SELECT by javascript then asseign it to a php variable and insert it in the mysql database
everything works fine but when i go to mysql and chekck the entry it is strange. even if i echo the variable in page it is showing the value and ok but when i check it in the database it is something like this.
<script language=javascript>document.write

Here is my page...

<html>
<body>

<form name="form1" method="post" action="">
<select name="select">
<option value="1">a</option>
<option value="2">b</option>
</select>
</form>

<?php
//asseigning the javascript variable to php
$MyVar1 = "?><script language=javascript>document.write(document.form1. select.options[form1.select.selectedIndex].text);</script><?php";
$MyVar1 = str_replace("?>", "", $MyVar1);
echo $MyVar1."<br><br>";//works fine


$host="localhost";
$user="root";
$pass="";
$db="hr_mysql";

$con=mysql_connect($host,$user,$pass);
if($con){
echo "Mysql Connected <br>";
}
else{
echo "Mysql connect error<br>";
}

$sel=mysql_select_db($db,$con);
if($sel){
echo "DB Selected<br>";
}
else{
echo "DB Select error<br>".mysql_error();
}

$sql="insert into hs_mustafa_modify values ('$MyVar1')";
$res=mysql_query($sql);
if($res){
echo "successful"; //successfuly enteres in database
}
else{
echo "Sorry ".mysql_error();
}

mysql_close();

// now go check it in the database for miracle.
?>

</body>
</html>
ufo973 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-03-2008, 11:55 AM Re: A Very Very Strange Problem
Junior Talker

Posts: 2
no body wants to help
ufo973 is offline
Reply With Quote
View Public Profile
 
Old 05-03-2008, 01:09 PM Re: A Very Very Strange Problem
chrishirst's Avatar
Super Moderator

Posts: 13,669
Location: Blackpool. UK
It's Saturday and 30 minutes later.


Apart from that it can't be done. PHP code is run and finished with, before the javascript even gets started.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-03-2008, 01:27 PM Re: A Very Very Strange Problem
Average Talker

Posts: 22
the variable actually taking the javascript code , so the database get s the javascript code.

the reason might be the value is not assigned to variable.
__________________
What is FTP and how to use FTP Client? - Read Article
Google Analytics Interface Tutorial - Watch Video
technica is offline
Reply With Quote
View Public Profile
 
Old 05-03-2008, 01:30 PM Re: A Very Very Strange Problem
Plugin-Developer's Avatar
Weightlifting CS Student

Posts: 505
Name: Nick Ohrn
I think your problem is that you're expecting to intermingle JavaScript and PHP. You just can't do that, as chrishirst pointed out. PHP is a server side language that is interpreted before the page is ever sent to the browser.

JavaScript, on the other hand, is a client-side language that processes things within the confines of the current environment, usually a browser. If you need some PHP processing to happen, you can dynamically post values to a PHP page from a JavaScript function. That may be what you want to look into. Just do a google search for AJAX.
__________________
Plugin-Developer.com - Custom plugin development to fit your needs. Plugins available for WordPress and Drupal, among others.
Plugin-Developer is offline
Reply With Quote
View Public Profile Visit Plugin-Developer's homepage!
 
Old 05-03-2008, 03:36 PM Re: A Very Very Strange Problem
Banned

Posts: 35
You dont need javascript to process a form...
halo is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to A Very Very Strange Problem
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14634 seconds with 12 queries