function tempdbentry()
{       
    var regex=/^[0-9A-Za-z]+$/; //^[a-zA-z]+$/
    var myname = document.ItemEntryForm.iname.value;
    var mycat = document.ItemEntryForm.selectcat.value;
    var mypic = document.ItemEntryForm.ipic.value;

    "<?php
    $phpmyname = '?><script language=javascript>document.write(myname);</script><?php';
    $phpmyname = str_replace('?>', '', $phpmyname);
    ?>"

    "<?php
    $phpmycat = '?><script language=javascript>document.write(mycat);</script><?php';
    $phpmycat = str_replace('?>', '', $phpmycat);
    ?>"

    "<?php
    $phpmypic = '?><script language=javascript>document.write(mypic);</script><?php';
    $phpmypic = str_replace('?>', '', $phpmypic);
    ?>"

    if(regex.test(myname))
    {
        "<?php $query1 = "SELECT * FROM temp_item_details WHERE titem_name = '$phpmyname'"; ?>"
        "<?php $result1 = mysql_query($query1); ?>"

        if ( "<?php mysql_num_rows($result1); ?>" == 0 )
        {
            "<?php $query2 = "SELECT * FROM temp_item_details WHERE titem_image = '$phpmypic'"; ?>"
            "<?php $result2 = mysql_query($query2); ?>"

            if ( "<?php mysql_num_rows($result2); ?>" == 0 )
            {
                //Get rid of Hackers
                "<?php $itemname=strip_tags($phpmyname); ?>"
                "<?php $itemcatagory=strip_tags($phpmycat); ?>"
                "<?php $itempicture=strip_tags($phpmypic); ?>"

                //finally insert into database
                "<?php $sql="INSERT INTO temp_item_details SET titem_name='$itemname',titem_catagory='$itemcatagory',titem_image='$itempicture'"; ?>"
                "<?php $result = mysql_query($sql); ?>"
            } 
            else
            {
                alert("Picture Already Exist for another Item");
                return false
            }
        } 
        else
        {
             alert('item name already exist');  
            return false;
        }
    } 
    else 
    {
        alert("Please Enter Alpha Numeric Value");
        return false;
    }    

}

//--> 
</script>

Hi there I am trying to run a simple logic but m completely paralized to assign javascript variable value to php variable value. I would be kind if someone direct me accordingly... thanks

Hussainiat,

It's so simple you will kick yourself. Remember that javascript is delivered as text, just like HTML, so you can write it with php echo or print statemets as if you were typing it yourself at the keyboard.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Airshow :: Untitled</title>
<style type="text/css">
#myCatContainer { color:red; font-size:20pt; font-weight:bold; }
</style>

<?php
$phpmyname = 'hussainiat';
$phpmycat = 99;
?>
<script>
alert('<?php echo $phpmyname; ?>');
var myCat = <?php echo $phpmycat; ?>;
onload = function(){
	var myCatContainer = document.getElementById('myCatContainer');
	myCatContainer.innerHTML = myCat;
};
</script>
</head>

<body>

<span id="myCatContainer"></span>

</body>
</html>

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.