GhostElite_89 Posted February 17, 2020 Share Posted February 17, 2020 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> Quote Link to comment https://forums.phpfreaks.com/topic/310050-cant-get-pop-up-to-work-in-phpjs/ Share on other sites More sharing options...
mactron Posted February 17, 2020 Share Posted February 17, 2020 (edited) 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 February 17, 2020 by mactron Quote Link to comment https://forums.phpfreaks.com/topic/310050-cant-get-pop-up-to-work-in-phpjs/#findComment-1574357 Share on other sites More sharing options...
GhostElite_89 Posted February 17, 2020 Author Share Posted February 17, 2020 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); } } Quote Link to comment https://forums.phpfreaks.com/topic/310050-cant-get-pop-up-to-work-in-phpjs/#findComment-1574377 Share on other sites More sharing options...
GhostElite_89 Posted February 17, 2020 Author Share Posted February 17, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/310050-cant-get-pop-up-to-work-in-phpjs/#findComment-1574378 Share on other sites More sharing options...
maxxd Posted February 17, 2020 Share Posted February 17, 2020 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? Quote Link to comment https://forums.phpfreaks.com/topic/310050-cant-get-pop-up-to-work-in-phpjs/#findComment-1574380 Share on other sites More sharing options...
GhostElite_89 Posted February 17, 2020 Author Share Posted February 17, 2020 I got it figured out. I had the code at the top of the page and when I moved it to the bottom, it worked. Quote Link to comment https://forums.phpfreaks.com/topic/310050-cant-get-pop-up-to-work-in-phpjs/#findComment-1574387 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.