How to navigate to a page using base_url() function in codeigniter? - javascript

I want to navigate to a page after doing some operations. Earlier I navigated like this:
echo "<script>alert('not deleted..'); window.location='http://localhost/CodeIgniter/crud/index.php/Crud_C'</script>";
And it was working perfectly.
But now I want to navigate like this using base_url():
$this->load->helper('url');
echo "<script>alert('not deleted..'); window.location='" . <?= base_url('index.php/Crud_C'); ?> . "';</script>";
Which is not working. I have used
$config['base_url'] = 'http://localhost/CodeIgniter/crud/';
in config.php file;
What should be the correct syntax of the code after echo?
Thanks

You can use the code as below.
echo "<script>alert('Not Deleted...'); window.location.href = '" . base_url('index.php/Crud_C') . "'</script>";

Related

How to know system command is in use in php?

I have a HTML/PHP code as shown below in which on click of a button conversion of mp4 into mp3 starts happening.
HTML/PHP Code:
<?php foreach ($programs as $key => $program) { ?>
<tr data-index="<?php echo $key; ?>">
<td><input type="submit" id="go-btn" name="go-button" value="Go" data-id="<?php echo $key; ?>" ></input></td>
</tr>
<?php }?>
Php code (where mp4=>mp3 conversion happens):
$f = $mp4_files[$_POST['id']];
$parts = pathinfo($f);
switch ($parts['extension'])
{
case 'mp4' :
$filePath = $src_dir . DS . $f;
system('C:\ffmpeg\bin\ffmpeg.exe -i ' . $filePath . ' -map 0:2 -ac 1 ' . $destination_dir . DS . $parts['filename'] . '.mp3', $result);
break;
}
As soon as the button is clicked from the HTML/PHP Code above, the text gets changed from Go to Converting in the UI because I have added JS/jQuery code in my codebase but this JS/jQuery code which I have added just change the text only.
It doesn't actually know that the Conversion is happening in the background.
JS/jQuery code:
$("input[name='go-button']").click( function() {
// Change the text of the button, and disable
$(this).val("Converting").attr("disabled", "true");
});
Problem Statement:
I am wondering what modification I need to do in the JS/jQuery code above so that UI actually knows that conversion is happening in the background.
Probably, we need to add make establish some connection between JS/jQuery and php code above but I am not sure how we can do that.

Cordova PHP get back to the original page

I am building a Cordova ( intel XDk app ) with HTML CSS and JavaScript.
For Backend i use PHP. I want that after the php finishes it's job, it will return to a specific page in my app, let's say #menupage.
This is my php code:
<?php
echo 'welcome ';
echo $_GET["name"];
echo 'your password is ';
echo $_GET["password"];
echo '<button onclick="activate_page("#menupage");">Go to the menu</button>';
?>
I want the button to activate that function, but it doesn't. Every other Javascript code I try doesn't work. Can somebody help me please.
you have a wrong sequnce of quotes try assign properly and escape the inner quotes
echo '<button onclick="activate_page(\'#menupage\');">Go to the menu</button>';

Creating a rollover with PHP and Javascript

I've read a TON of question and answers about rollovers using PHP and Javascript and can't figure out why this isn't working. So I have this PHP code:
$rollover = '$("#' . $godName . '").mouseenter(function() {
$("#' . $godName . '").attr("src","img/gods/god_cards/dark/' . $godImage . '2.png");
});
$("#' . $godName . '").mouseleave(function() {
$("#' . $godName . '").attr("src","img/gods/god_cards/' . $godImage . '.png");
});';
$godName and $godImage are variables retrieved through a query to a database. I wanted to use this code to cut down on the amount I'd have to write to create a rollover for over 50 images, so basically it would create a function for every image retrieved in the query. Then I wanted to stick it in a javascript tag like so:
<script type="text/javascript">
<?php echo $rollover; ?>
</script>
But it doesn't work. And I've tried doing it with and without the echo and no version of whatever I've found on here or anywhere else works. When I echo it out as just text it looks fine, it spits out what it should so I'm not sure why the javascript just doesn't seem to be accepting the php. Any help?
Do you check if the HTML Dom is ready? You are using jQuery, so you can use:
<script type="text/javascript">
$(function(){
<?php echo $rollover; ?>
});
</script>

inserting popup window command in sql

I'm assigning popup window on my links but it doesn't work sorry i'm still learning about mysqli and javascript.
while($row = mysqli_fetch_array($result))
{
$id = $row['BapID'];
echo "<tr>";
echo "<th>" . "<a href=bapview.php?BapID=$id onlick='pop_up(this);'>View Full Info</a>" .
" | " .
"<a href=bapupdate.php?BapID=$id onlick='pop_up(this);'>Edit</a>" . "</th>";
My script
function pop_up(url){
window.open(url,'win2','status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=1076,height=768,directories=no,location=no') }
The url that you want the pop-up window to point should be put as the parameter to your function call in your onclick handlers:
<a onclick="pop_up('bapupdate.php?<?php echo $id; ?>');">Edit</a>
As you can see at
https://developer.mozilla.org/en-US/docs/Web/API/Window.open
the first parameter to the window.open method is a string value for the url you want the opening window to point to. Your code was attempting to provide as that argument the actual reference to the link element on your page (that's what this will refer to in that context).
A couple of suggestions:
Don't be afraid to 'exit' (?>) PHP half way through a script. This will make it easier to read later on and allows you to write in pure HTML.
It looks like your missing you quotation marks around your href parameter. This likely won't cause issues but you never know. I would also recommend using the full url in your href and also as your pop_up() parameter (as suggested by #myesain)
<?php
while($row = mysqli_fetch_array($result)){
$id = $row['BapID']; ?>
<tr>
<th>
<a href=# onclick='pop_up("http://fullurl.com/bapview.php?BapID=<?php echo $id; ?>");'>View Full Info</a>
|
<a href=# onclick='pop_up"http://fullurl.com/bapupdate.php?BapID=<?php echo $id; ?>");'>Edit</a>
</th>
</tr>
<?php
//Rest of code
?>

include variable in javascript?

I need some help with the following.
I have a script that close down the web page using the following:
<a href=\"Javascript:void(0);\" onclick=\"parent.location.reload();window.parent.Shadowbox.close();\">
It works as it should. My problem is that I need to change parent to another page. For this I used the following:
<a href=\"Javascript:void(0);\" onclick=\"parent.location='http://www.google.com';window.parent.Shadowbox.close();\">
It also works, but now I do not want it to go to google but one of my pages where it should include a variable. Normally I would use:
<?=$array["id"]?>
But since it is a javascript then I cant use PHP and the following solution does not work:
<a href=\"Javascript:void(0);\" onclick=\"parent.location='new-new.php?$array[‘id’];window.parent.Shadowbox.close();\">
So I tried this:
function getNewURL() {
var root="http://minside.net";
var id="topic/#entry667119";
var nURL=root+"/"+id;
return nURL;
}
With the javascript:
<a href=\"Javascript:void(0);\" onclick=\"parent.location.replace(getNewURL);window.parent.Shadowbox.close();\">
For in this way to get my variables with me, but it does not work.
Someone who can help me? Or have another idea for how to resolve this?
you can assign a php variable to javascript variable.
var a=<?php echo $array[‘id’]?>;
you are using echo for that right since you use \ for ", so it should be like this:
<a href=\"Javascript:void(0);\" onclick=\"parent.location='new-new.php?'.$array[‘id’]'.window.parent.Shadowbox.close();\">
The best way to assign a variable in Javascript is
var id = <?php echo json_encode($array["id"]); ?>
You need to use echo:
<? echo $array["id"]; ?>
Edit
var id = <?php echo $array["id"]; ?>;
var link = "<a href=\"Javascript:void(0);\" onclick=\"parent.location='new-new.php?id="+id+";window.parent.Shadowbox.close();\">";
assuming you use $_GET['id'] in new-new.php (you omitted it in the URL)
Edit
if(strlen($large_photo_exists) > 0 && strlen($thumb_photo_exists) > 0)
{
echo $thumb_photo_exists;
echo "<p>Use this photo as my profile photo</p>";
echo "<br> OR <br>";
echo "<p>Upload and use another photo</p>";
}

Categories