close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

MySQLi connection on die redirect to website

Thread begun 2/06/2023 8:22 am by mlowe4 | Last modified 2/12/2023 11:32 am by Ray Borduin | 1915 views | 10 replies |

mlowe4

MySQLi connection on die redirect to website

Hi there, how would I modify the connection script so that on a connect error it redirects to a website, I've tried the script below but it's not working, any help would be much appreciated, thanks.


<?php
# FileName="WADYN_MYSQLI_CONN.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_securex = "localhost";
$database_securex = "database";
$username_securex = "account";
$password_securex = "password";
@session_start();

$securex = mysqli_init();
if (defined("MYSQLI_OPT_INT_AND_FLOAT_NATIVE")) $securex->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, TRUE);
$securex->real_connect($hostname_securex, $username_securex, $password_securex, $database_securex) or die(header("Location: https://lm-activate.nexuscst.com/?na=1"));
?>

Sign in to reply to this post

Ray BorduinWebAssist

php:
<?php

# FileName="WADYN_MYSQLI_CONN.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_securex "localhost";
$database_securex "database";
$username_securex "account";
$password_securex "password";
@
session_start();

$securex mysqli_init();
if (
defined("MYSQLI_OPT_INT_AND_FLOAT_NATIVE")) $securex->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVETRUE);
$securex->real_connect($hostname_securex$username_securex$password_securex$database_securex);

if (
$securex->connect_errno) {
header("Location: https://lm-activate.nexuscst.com/?na=1");
die();
}

?>
Sign in to reply to this post
Did this help? Tips are appreciated...

mlowe4

Thank you that helps

Sign in to reply to this post

mlowe4

I'm receiving a 500 error on connection failure
I have a test.php file that just contains the line

<?php require_once('securex.php'); ?>


nothing else so I think there might be an error with the connection file, I've generated a new connection file and changed as above but it's still doing the same, I've tried PHP 8.1 and PHP 8.2, it returns 200 with a successful connection

I’ve tried generating a new connection file and still fails with 500 if the connection details are wrong

<?php
# FileName="WADYN_MYSQLI_CONN.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_securex = "localhost";
$database_securex = "database";
$username_securex = "account";
$password_securex = "password";

@session_start();
$securex = mysqli_init();
if (defined("MYSQLI_OPT_INT_AND_FLOAT_NATIVE")) $securex->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, TRUE);
$securex->real_connect($hostname_securex, $username_securex, $password_securex, $database_securex) or die("Connect Error: " . mysqli_connect_error());
?>
Sign in to reply to this post

Ray BorduinWebAssist

Add this to the top of the page:
<?php
ini_set("display_errors",1);
?>

That might display the actual error instead of a generic 500 error message.

Sign in to reply to this post
Did this help? Tips are appreciated...

Ray BorduinWebAssist

Are you sure the path to the connection file is right? I would expect it to be something like:

<?php require_once('Connections/securex.php'); ?>

Sign in to reply to this post
Did this help? Tips are appreciated...

mlowe4

Hi the error I'm getting is Fatal error: Uncaught mysqli_sql_exception, I've uploaded a couple of test files with the connection code modified in one with the connect_errno code and the other just the original generated code both throw this error when the information to connect is wrong instead of an error message or redirecting, I'll include FTP details if you want to have a look for your self or you can visit the URL I've uploaded the files to

Sign in to reply to this post

Ray BorduinWebAssist

You don't have real connection information in your connection file... it has:

$hostname_securex = "fakehost";
$database_securex = "database";
$username_securex = "account";
$password_securex = "password";

That needs to have real database credentials to connect to a database.

Sign in to reply to this post
Did this help? Tips are appreciated...

mlowe4

This post has been deleted.

Ray BorduinWebAssist

I updated the code on your connection file so it should work how you want it to now.

Sign in to reply to this post
Did this help? Tips are appreciated...
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...