Jump to content

Recommended Posts

So, I have part of this snippet of code in my homepage and it pops up an inner window notification that briefly displays and then goes away...I'm looking to do it for a non-index.php page and it just isnt working. In the index.php page, it automatically occurs when the form loads and in this case, I need to invoke it...any help would be awesome..

 

It is the section where I'm echoing the JS script that isn't working.

 

<?php

if($_GET){

    if(isset($_GET['add'])){
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "test", "vendors");
 
// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
$name = mysqli_real_escape_string($link, $_REQUEST['vendor']);
$company = mysqli_real_escape_string($link, $_REQUEST['company']);
$type = mysqli_real_escape_string($link, $_REQUEST['type']);
$email = mysqli_real_escape_string($link, $_REQUEST['email']);
$soc = mysqli_real_escape_string($link, $_REQUEST['soc']);
$status = mysqli_real_escape_string($link, $_REQUEST['status']);

// Attempt insert query execution
$sql = "INSERT INTO vendor_data (name, company, type, email, soc, status) VALUES ('$name', '$company', '$type', '$email', '$soc', '$status')";
if(mysqli_query($link, $sql)){
		echo ' 	<script type="text/javascript">
					$(document).ready(function(){

					demo.initChartist();

					$.notify({
					icon: "pe-7s-gift",
					message: "TESTING!"				
            },{
                type: "info",
                timer: 4000
            });

    	});
	</script>';
} 
else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
 
// Close connection
mysqli_close($link);
      
    }

}


?>
<!doctype html>

 

Link to comment
https://forums.phpfreaks.com/topic/310050-cant-get-pop-up-to-work-in-phpjs/
Share on other sites

Try

$msg = "<script type="text/javascript">
					$(document).ready(function(){

					demo.initChartist();

					$.notify({
					icon: 'pe-7s-gift',
					message: 'TESTING!'				
            },{
                type: 'info',
                timer: 4000
            });

    	});
JS;

print '<script>'.msg.'</script>';

P.S. Your code is not safe. Use PDO instead MySQLi.

Edited by mactron
2 hours ago, mactron said:

Try


$msg = "<script type="text/javascript">
					$(document).ready(function(){

					demo.initChartist();

					$.notify({
					icon: 'pe-7s-gift',
					message: 'TESTING!'				
            },{
                type: 'info',
                timer: 4000
            });

    	});
JS;

print '<script>'.msg.'</script>';

P.S. Your code is not safe. Use PDO instead MySQLi.

I'll look into switching to PDO for sure!

 

The code threw an error on .msg but I can't see the entire error due to having a container in the way of the text. I switched the code to this due to it throwing errors cause of the quotes.

if(mysqli_query($link, $sql)){
$msg = "<script type='text/javascript'>
					$(document).ready(function(){

					demo.initChartist();

					$.notify({
					icon: 'pe-7s-gift',
					message: 'TESTING!'				
            },{
                type: 'info',
                timer: 4000
            });

    	});
JS";

echo '<script>'.msg'</script>';
} 
else{
    echo 'ERROR: Could not able to execute $sql. ' . mysqli_error($link);
}
 
// Close connection
mysqli_close($link);
      
    }

}

 

Fixed it to this, now no error:

<?php

if($_GET){

    if(isset($_GET['add'])){
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "test", "vendors");
 
// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
$name = mysqli_real_escape_string($link, $_REQUEST['vendor']);
$company = mysqli_real_escape_string($link, $_REQUEST['company']);
$type = mysqli_real_escape_string($link, $_REQUEST['type']);
$email = mysqli_real_escape_string($link, $_REQUEST['email']);
$soc = mysqli_real_escape_string($link, $_REQUEST['soc']);
$status = mysqli_real_escape_string($link, $_REQUEST['status']);

// Attempt insert query execution
$sql = "INSERT INTO vendor_data (name, company, type, email, soc, status) VALUES ('$name', '$company', '$type', '$email', '$soc', '$status')";
if(mysqli_query($link, $sql)){
$msg = '<script type="text/javascript">
					$(document).ready(function(){

					demo.initChartist();

					$.notify({
					icon: "pe-7s-gift",
					message: "TESTING!"				
            },{
                type: "info",
                timer: 4000
            });

    	});
JS;';

echo '<script>'.$msg.'</script>';
} 
else{
    echo 'ERROR: Could not able to execute $sql. ' . mysqli_error($link);
}
 
// Close connection
mysqli_close($link);
      
    }

}


?>

BUT the window still does not appear when the user clicks a button.

Is $_GET['add'] set for the button(s) in question? The code you've posted will only run when vendor data is inserted into your database - does this happen on every page or every time a user clicks a button? What does your form code look like?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.