PHP - Problem With Php Code Inside A Javascript
Hello,
I have a php code within a javascript. The javascript gets invoked on button click. The php code withing javascript never gets executed. I don't face the same problem in other browsers. Any help is much appreciated! Regards, Cole Similar TutorialsI have the following code in html: <html> <head> <script type="text/javascript"> <!-- function delayer(){ window.location = "http://VARIABLEVALUE.mysite.com" } //--> </script> <title>Redirecting ...</title> </head> <body onLoad="setTimeout('delayer()', 1000)"> <script type="text/javascript"> var sc_project=71304545; var sc_invisible=1; var sc_security="9c433fretre"; </script> <script type="text/javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript> <div class="statcounter"><a title="vBulletin statistics" href="http://statcounter.com/vbulletin/" target="_blank"><img class="statcounter" src="http://c.statcounter.com/71304545/0/9c433fretre/1/" alt="vBulletin statistics" ></a></div></noscript> </body> </html> Is a basic html webpage with a timer redirect script and a stascounter code. I know a bit about html and javascript, but almost nothing about php. My question is: How a can convert this html code into a php file, in order to send a variable value using GET Method and display this variable value inside the javascript code where says VARIABLEVALUE. Thanks in adavance for your help. Hey guys,
I'm facing an issue compiling the above stack from a source code inside lxc using centos 6.5 as a domain OS.
[lxc@lxc1 httpd-2.4.9]$ ./configure --with-included-apr checking for chosen layout... Apache checking for working mkdir -p... yes checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu configu configu Configuring Apache Portable Runtime library... configu configuring package in srclib/apr now checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu Configuring APR library Platform: x86_64-unknown-linux-gnu checking for working mkdir -p... yes APR Version: 1.5.1 checking for chosen layout... apr checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... configu error: in `/home/lxc/httpd-2.4.9/srclib/apr': configu error: cannot run C compiled programs. If you meant to cross compile, use `--host'. See `config.log' for more details configure failed for srclib/apr This problem has been detected by me when I replaced my desktop machine with new one and installed a centOS again. This such a problem never happened before using my old machine with the same version of OS and libvirt. Just to be clear, a new selinux policy into a "domain machine" has been created to be able to use the "dbus daemon" to all containers and if I try to complile this stack from source using the "domain os" this problem never happens at all. All "Development tools" is installed to this particular container, in case someone asks me why I get the following error message - "configu error: cannot run C compiled programs" Any ideas? Edited by jazzman1, 08 June 2014 - 01:37 PM. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=316889.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=316454.0 I'm trying to pull results from a database (using php) to populate a javascript "top news rotation" script I found. The problem is that I'm getting the "java is disabled" message that is in the code...instead of the results I'm expecting. Here's the code: Code: [Select] <!-- create a element in your HTML like the following --> <div id="quotetext" > Text will go here. Be sure to add initial text here for users with JavaScript disabled. </div> <!-- The easiest way is to place the below JavaScript code after the above HTML. The better way would be to add in the <head> section of the document and call the rotatequote() function through the window.onload event. However this can cause problems if you have other scripts that use the window onLoad settings --> <script type="text/javascript" > var myquotes = new Array( <?php $link = mysql_pconnect($host, $username, $password); mysql_select_db('briansch_brn',$link); $sql = "SELECT * FROM story WHERE ORDER BY date DESC LIMIT 4"; $rs = mysql_query($sql,$link); $matches = 0; while ($row = mysql_fetch_assoc($rs)) { $matches++; echo "'<strong>$row[headline]</strong><br />(posted $row[date]) - $row[short_story]<br /><a href='/pages/$row[keyword]'>READ MORE</a>'"; if($matches < 4) { echo ','; } if($matches == 4) { echo ''; } } if (! $matches) { echo (""); } echo ""; ?> ); function rotatequote() { thequote = myquotes.shift(); //Pull the top one myquotes.push(thequote); //And add it back to the end document.getElementById('quotetext').innerHTML = thequote; // This rotates the quote every 10 seconds. // Replace 10000 with (the number of seconds you want) * 1000 t=setTimeout("rotatequote()",10000); } // Start the first rotation. rotatequote(); </script> I know that javascript inside php is hard to make work...and I know that php inside javascript is hard to make work. Any ideas? Thanks! How can I insert PHP code inside MySQL DB? I have mixed HTML and PHP code like this: <div class="rightpanel"> <div class="hltred"> <div class="hlthead"> <p><?php echo $pages->naslov; ?></p> </div> <div class="hltcontent"> <p> ovde treba da ide loop sa svi podlinkovi za taj glavni koji je aktivan</p> </div> </div> </div>, but when i insert it into DB i get this code (I use htmlspecialchars function to store): <div class="rightpanel"> <div class="hltred"> <div class="hlthead"> <p> <!--?php echo $pages---> naslov; ?></p> </div> <div class="hltcontent"> <p> ovde treba da ide loop sa svi podlinkovi za taj glavni koji je aktivan</p> </div> </div> </div> hi i have this form that runs with ASP. [this is a must since i didn't create that form] and must run in the wordpress header.php... is this even possible? This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=348601.0 Hi all, I am trying to replicate/modify this checkbox for a different script and I don't understand what the php code is doing in this form? Could someone explain to me whats happening by including that php code in the form? Code: [Select] <input type="checkbox" onclick="showArchive()" NAME="showarchive" id="showarchive" <?php echo ($showarchive ? 'checked="checked"' : '');?> /> Thanks! Hello, people!
I was watching some php tutorials in youtube and, in a video, the guy was showing how put php script inside html code. I would like to know why in the following code he didn't use only one php script?
1- Code used in the video:
<html> <body> <?php $color = $_GET['clr']; ?> <b><font color="<?php echo $color;?>">This is a test.</font></b> </body> </html>2- Modified code by me to test with one script: <html> <body> <?php $color = $_GET['clr']; echo "<b><font color=\"$color\"> This is a test. </font></b>"; ?> </body> </html>Is his code more correct(with two scripts)? Why? Hi, I have this curl string required by an email verification vendor I use. Inside my php file I wish to run it. Apparently there is a problem with the syntax as I’m getting the following error in the browser: ”Parse error: syntax error, unexpected '--' (T_DEC) in /var/www/html/wp-content/plugins/dw_functionality_plugin/dw_functionality_plugin.phpon line 398 Here is the code string:
< > any help much appreciated! Edited March 23 by dwest100Hi everybody. I have this script in the <head></head> tag to help me reload images, so when i put the mouse over image it appear in another location of the table. The problem is i have to put the images manually to the script. Can i automatic put the images with php in the script. The script look like this: Code: [Select] <script> function changeimage(towhat,url){ if (document.images){ document.images.targetimage.src=towhat.src gotolink=url } } function warp(){ window.location=gotolink } </script> <script language="JavaScript1.1"> var myimages=new Array() var gotolink="#" function preloadimages(){ for (i=0;i<preloadimages.arguments.length;i++){ myimages[i]=new Image() myimages[i].src=preloadimages.arguments[i] } } preloadimages("images/plane1.gif","images/plane2.gif") </script> So instead of manually put "images/plane1.gif", images/plane2.gif" I want to use something like this: Code: [Select] ' . tep_image(DIR_WS_IMAGES . $product_info['product_image_6'], $product_info['products_name'], SMALL_WIDTH_IMAGE, SMALL_HEIGHT_IMAGE, 'hspace="5" vspace="5"') . ' So the script look like this: Code: [Select] preloadimages("<? php echo ' . tep_image(DIR_WS_IMAGES . $product_info['product_image_6'], $product_info['products_name'], SMALL_WIDTH_IMAGE, SMALL_HEIGHT_IMAGE, 'hspace="5" vspace="5"') . ' ?>","<? php echo ' . tep_image(DIR_WS_IMAGES . $product_info['product_image_6'], $product_info['products_name'], SMALL_WIDTH_IMAGE, SMALL_HEIGHT_IMAGE, 'hspace="5" vspace="5"') . ' ?>" Any help or suggestions will greatly appriciate. vanvoquan Hi Everyone. I'm working on a form, that allows the user to select the country / county / area where they are from. I am doing this using: - mysql database store the locations in - PHP OOP, to pull this information from the database - AJAX/Javascript to only show the next dropdown, once the first dropdown has been selected. Example: select country then the county dropdown will appear, select county then the area/town will appear. However, the first drop down for country is placed directly on to the page. So the javascript works fine. but the second dropdown is placed in to a PHP function, and the javascript seems to no longer want to work. CODE: Code: [Select] //////////////// CODE FOR COUNTRY /////////// if(isset($_REQUEST['country'])) { echo ' <div class="labelleft">County / State:</div> <div class="fieldleft"> <div > <select name="county" id="county" onchange="javascript:AJAXQuery("lib/search.php?town="+this.value, "tw", "")"> <option value="0">Select County</option> <option value="0">-------</option>'; $countyList = Area_county::find_country_id($_REQUEST['country']); foreach($countyList as $countyLists){ $county_id = $countyLists->id; $county_list = $countyLists->county; echo '<option value="'.$county_id.'">'.ucwords($county_list).'</option>'; } echo ' </select> </div> </div> <div class="clear"></div>'; } Any ideas? Thanks greetings! I have here codes that have two checkboxes, if 1 checkbox is checked, the other and textbox is disabled. I think my codes in js is functional, my problem is how to put it inside the mysql_fetch_array, I want to put those checkbox in every data fetch from my db. only the first data is affected ..i really appreciate your help guys! <?php include('connect-db.php');?> <html> <head> <script language = "Javascript" type="text/javascript" > function checkbox_disabled(tocheck,todisable,todisable2) { var x = document.getElementById(tocheck); if(x.checked){ document.getElementById(todisable).disabled=true; document.getElementById(todisable2).disabled=true; document.getElementById(todisable2).checked = false; }else{ document.getElementById(todisable).disabled=false; document.getElementById(todisable2).disabled=false; document.getElementById(todisable2).checked = true; } } </script> </head> <body> <?php echo "<table>"; $query = mysql_query("SELECT * FROM tbl_user") or die (mysql_error()); while ($row = mysql_fetch_array($query)) { echo '<tr>'; echo '<td>'.$row['user_Id'].'</td>'; echo '<td>'. $row['user_Fname'].'</td>'; echo '<td>'.$row['user_Lname'].'</td>'; echo "<td><input type='checkbox' id='checkbox1' value ='checked' onclick=checkbox_disabled('checkbox1','textbox1','checkbox2')></td>"; echo '<td><input type="checkbox" id = "checkbox2"><input type="text" id="textbox1" /><td>'; echo '</tr>'; } echo "</table>"; ?> </body> </html> This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=347585.0 I have the following code which gets staff working on a selected day and their start and finish times. The code then lists out the day for every 15min of time for each staff member. During the loop of each staff member I then check an appointment table to see if a user has any appointments, and lists the booked time slots, if no appointments lists user as available for all the time slots. My problem is when a user has appointments it only shows the booked times and not the available times. I know the problem lies here else if ($inc<$resSTART && $inc>$resEND) { and the complete code that is from is here // convet to US format $input="$month/$day/$year"; // readable date $readDATE="$day/$month/$year"; // convert for mysql date $sqlDATE="$year-$month-$day"; // get day of the week $weekday=date(l, strtotime($input)); echo $weekday."<br/>"; // get working staff from staff table $staffSQL=mysql_query("SELECT * FROM staff WHERE ".$weekday." != 'off' AND onLEAVE='no' AND ACTIVE='yes' ORDER BY staffID ASC"); // return results putenv("TZ=Australia/Adelaide"); while ($staff=mysql_fetch_array($staffSQL)) { $name=$staff['staffNAME']; $avail=$staff[$weekday]; $staffID=$staff['staffID']; list($first, $last)=explode(" ", $name); list($in, $out)=explode("-", $avail); $firstTIME="$sqlDATE $in:00"; $lastTIME="$sqlDATE $out:00"; echo "$first is available between $avail on $weekday<br/>"; $in2=strtotime($firstTIME); $out2=strtotime($lastTIME); $stop=$out2-900; echo $in2." - time start - $firstTIME<br/>"; echo $out2." - time finish - $lastTIME<br/>"; for ($inc=$in2;$inc<=$stop;$inc+=900) { $existSQL=mysql_query("SELECT * FROM appointment WHERE date='$sqlDATE' AND staffID='$staffID'"); if (mysql_num_rows($existSQL)>=1) { while ($appointV=mysql_fetch_array($existSQL)) { $resSTART=$appointV['dateTIME']; $length=$appointV['totalTIME']; $resEND=$resSTART+($length*60); if ($inc>=$resSTART && $inc<=$resEND) { echo "Appointment time is ".date("g.i a", $inc)." <font color='red'><< $first BOOKED</font><br/>"; } else if ($inc<$resSTART && $inc>$resEND) { echo "Appointment time is ".date("g.i a", $inc)." <font color='green'><< $first AVAILABLE</font><br/>"; } } } if (mysql_num_rows($existSQL)==0) { echo "Appointment time is ".date("g.i a", $inc)." <font color='green'><< $first AVAILABLE</font><br/>"; } } } any ideas how to restructure that if statement to work properly would be very much appreciated I have a mysql database table that lists baseball and softball umpires for the season. The table has columns for: date, sport, umpire1, umpire2, umpire3, umpire 4, umpire5, visitor team, and home team. I'm trying to write a bit of code that will tell me how many times I have schedule (manually) an umpire to see a particular school. Here's what I've come up with. Code: [Select] <?php require_once "/config.php"; $dbc = mysql_pconnect($host, $username, $password); mysql_select_db($db,$dbc); $start_date = '2011-04-01'; $end_date = '2011-06-01'; $umpires = Array('umpire 1 name', 'umpire 1 name', 'umpire 2 name', 'umpire 3 name', 'umpire 4 name', 'umpire 5 name', 'umpire 6 name'); $schools = Array('Bagley', 'Bemidji', 'Blackduck', 'Fosston', 'International Falls', 'Kelliher', 'Laporte', 'Lake of the Woods', 'Remer', 'Walker'); ?> <?php foreach($umpires as $umps) { //selects the first umpire in the array echo "<table width='20%' border ='1'>"; echo "<tr><td>$umps</td><td>Baseball</td><td>Softball</td></tr>"; foreach($schools as $town) { //selects the first town in the array $sql_baseball = "SELECT * FROM $table WHERE (ump1 = $umps OR ump2 = $umps OR ump3 = $umps OR ump4 = $umps OR ump5 = $umps) AND (visitor = $town OR home = $town) AND sport = 'Baseball' AND date >= $start_date AND DATE <= $end_date"; $result_baseball = mysql_query($sql_baseball); $count_baseball=mysql_num_rows($result_baseball); $sql_softball = "SELECT * FROM $table WHERE (ump1 = $umps OR ump2 = $umps OR ump3 = $umps OR ump4 = $umps OR ump5 = $umps) AND (visitor = $town OR home = $town) AND sport = 'Softball' AND date >= $start_date AND DATE <= $end_date"; $result_softball = mysql_query($sql_softball); $count_softball=mysql_num_rows($result_softball); echo "<td>$town</td><td>$count_baseball</td><td>$count_softball</td></tr>"; } //loops the towns echo "</table>"; } //ends each umpire ?> As you can see, I've put all the umpire names in an array...and each school in a separate array. The html tables are being displayed (with the correct names and schools listed...but I'm getting this error: Quote Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /by_school.php on line 33 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /by_school.php on line 37 Line 33 is this - - - $count_baseball=mysql_num_rows($result_baseball); Line 37 is this - - - $count_softball=mysql_num_rows($result_softball); I'm guessing that the problem is that I have multiple selects (one for each town) while using the same variable names for each select...but I can't figure out how to concacate the variable names properly...or even if that's the problem. Any ideas? Thanks! The Script:
$desired_width = 110; if (isset($_POST['submit'])) { $j = 0; //Variable for indexing uploaded image for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array $target_path = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/uploads/"; //Declaring Path for uploaded images $validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) $file_extension = end($ext); //store extensions in the variable $new_image_name = md5(uniqid()) . "." . $ext[count($ext) - 1]; $target_path = $target_path . $new_image_name;//set the target path with a new name of image $j = $j + 1;//increment the number of uploaded images according to the files in array if (($_FILES["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded. && in_array($file_extension, $validextensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>'; $tqs = "INSERT INTO images (`original_image_name`, `image_file`, `date_created`) VALUES ('" . $_FILES['file']['name'][$i] . "', '" . $new_image_name . "', now())"; $tqr = mysqli_query($dbc, $tqs); // Select the ID numbers of the last inserted images and store them inside an array. // Use the implode() function on the array to have a string of the ID numbers separated by commas. // Store the ID numbers in the "image_file_id" column of the "thread" table. $tqs = "SELECT `id` FROM `images` WHERE `image_file` IN ('$new_image_name')"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); $fetch_array = array(); $row = mysqli_fetch_array($tqr); $fetch_array[] = $row['id']; /* * This prints e.g.: Array ( [0] => 542 ) Array ( [0] => 543 ) Array ( [0] => 544 ) */ print_r($fetch_array); // Goes over to create the thumbnail images. $src = $target_path; $dest = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/thumbs/" . $new_image_name; make_thumb($src, $dest, $desired_width); } else {//if file was not moved. echo $j. ').<span id="error">please try again!.</span><br/><br/>'; } } else {//if file size and file type was incorrect. echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>'; } } }Hey, sorry that I am posting this darn image upload script again, I have this almost finished and I am not looking to ask more questions when it comes to this script specifically. With the script above I have that part where the script should store the ID numbers (the auto_increment column of the table) of the image files inside of one array and then the "implode()" function would get used on the array and then the ID numbers would get inserted into the "image_file_id" column of the "thread" table. As you can see at the above part the script prints the following: Array ( [0] => 542 ) Array ( [0] => 543 ) Array ( [0] => 544 )And I am looking to insert into the column of the table the following: 542, 543, 544I thought of re-writing the whole image upload script since this happens inside the for loop, though I thought maybe I could be having this done with the script as it is right now. Any suggestions on how to do this? translate my code please; javascript to php. very very very very thanks. <form> <input type="checkbox" name="myfilter" value="+abst">Amytag1 <input type="checkbox" name="myfilter" value="+mini">Amytag8 <input type="checkbox" name="myfilter" value="+popa">Amytag9 <input type="checkbox" name="myfilter" value="+impr">Amytag13 <input type="checkbox" name="myfilter" value="+green">Amytag15 <input type="checkbox" name="myfilter" value="+gh5">Amytag18 <input type="checkbox" name="myfilter" value="+gh4">Amytag19 <input type="checkbox" name="myfilter" value="+gh3">Amytag34 <input id="search1" placeholder="Word Search..." value=""> <input id="year1" placeholder="Year" value=""> <input id="month1" placeholder="Month" value=""> <input id="day1" placeholder="Day" value=""> <input id="mymenu" value=""> </form> <button onclick="myFunction()" class="Sbutton">search it</button> <script> function myFunction() { var myfilter = document.forms[0]; var txt = ""; var i; for (i = 0; i < myfilter.length; i++) { if (myfilter[i].checked) { txt = txt + myfilter[i].value; } var year = "&year=" + document.getElementById("year1").value; var month = "&month=" + document.getElementById("month1").value; var day = "&day=" + document.getElementById("day1").value; var search = "&s=" + document.getElementById("search1").value; var tag = "/?tag=" + document.getElementById("mymenu").value; } var zzz = "http://test.com/category/art" + txt + tag + year + month + day + search; window.location.assign(zzz) } </script>
and please, not use this way: header("Location: {$target}"); exit; Because it doesn't work on my site (for some reason). p.s: I have a lot of checkbox. Edited May 4, 2020 by ldonopHow can i run this javascript command show_seasons(some_value), in php code, i mean without any action ? I have this php code: if ($sid == $s_id) { javascript:show_seasons($sid); } How to do that? Thanks.. |