Can someone tell me why the same script I use to connect to MySQL works on one page but not this one? Uses the same script. Includes the file but then doesn’t connect. Ideas? Script below.
<?php session_start(); if (isset($_SESSION["manager"])) { header("location: index.php"); exit(); } ?> <?php if (isset($_POST["username"]) && isset($_POST["password"])) { $manager = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["username"]); $password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]); include_once "scripts/connect_to_mysql.php"; $sql = mysql_query("SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1"); $existCount = mysql_num_rows($sql); if ($existCount == 1) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; } $_SESSION["id"] = $id; $_SESSION["manager"] = $manager; $_SESSION["password"] = $password; header("location: index.php"); exit(); } else { echo 'That information is incorrect, try again Click Here'; exit(); } } ?>it might be the directory location. If you are saying that the connection script works, and it is proven to work via another script, but you are not getting connection with this script, I am going to go out on a limb and guess that it is a directory location error.
I thought so as well. Originally this was in a different directory and had the …/ before scripts folder to move up a directory. But I moved it to the root folder and tried again (hence the lack of the …/ here) and still no good. The other files are in root directory but I wanted this one in an admin folder which is SSL (since this is obviously my admin log in script) but regardless it doesn’t connect.
Interestingly, I did away with the include and just did a standard connect script in full. Still wouldn’t connect.
I was hoping it was just something stupid I’m overlooking in my code. That’s what it usually is when I find a problem.
Thanks for your reply though.
can you copy the exact error you get, which is telling you that you are not connecting to the database, and paste it here.
also can you copy your connection script, delete the password info, and paste it here so I can see what is going on.