Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
A Very Very Strange Problem
Old 05-03-2008, 12:19 PM A Very Very Strange Problem
Junior Talker

Posts: 2
Trades: 0
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
 
 
Register now for full access!
Old 05-03-2008, 12:55 PM Re: A Very Very Strange Problem
Junior Talker

Posts: 2
Trades: 0
no body wants to help
ufo973 is offline
Reply With Quote
View Public Profile
 
Old 05-03-2008, 02:09 PM Re: A Very Very Strange Problem
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-03-2008, 02:27 PM Re: A Very Very Strange Problem
Average Talker

Posts: 22
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
- Win $5 every week on the forum

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
technica is offline
Reply With Quote
View Public Profile Visit technica's homepage!
 
Old 05-03-2008, 02:30 PM Re: A Very Very Strange Problem
Plugin-Developer's Avatar
Weightlifting CS Student

Posts: 504
Name: Nick Ohrn
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
- 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, 04:36 PM Re: A Very Very Strange Problem
Banned

Posts: 35
Trades: 0
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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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.71624 seconds with 12 queries