Jump to content

Search the Community

Showing results for tags 'mysql error'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 4 results

  1. I am currently handling MySQL errors like this: $conn = mysql_connect("", "", ""); if(!$conn) { // Present message to user. echo "<p>Sorry, there has been an error. The webmaster has been informed.</p>"; // Send yourself an e-mail. error_log("MySQL connection failed! Date: " . date("l jS \of F, Y, h:i:s A") . ". File: " . $_SERVER['REQUEST_URI'], 1, "personaladdress@example.com", "From: help@mysite.com"); } else { $selectdb = mysql_select_db(""); if(!$selectdb) { // Present message to user. echo "<p>Sorry, there has been an error. The webmaster has been informed.</p>"; // Send yourself an e-mail. error_log("MySQL selectdb failed! Date: " . date("l jS \of F, Y, h:i:s A") . ". File: " . $_SERVER['REQUEST_URI'], 1, "personaladdress@example.com", "From: help@mysite.com"); } else { $query = mysql_query("", $conn); if(!$query) { // Present message to user. echo "<p>Sorry, there has been an error. The webmaster has been informed.</p>"; // Send yourself an e-mail. error_log("MySQL query failed! Date: " . date("l jS \of F, Y, h:i:s A") . ". File: " . $_SERVER['REQUEST_URI'], 1, "personaladdress@example.com", "From: help@mysite.com"); } else { // Rest of code. } } } The code works. If there's an error with mysql_connect(), mysql_select_db() or mysql_query(), I am sent an e-mail and the user is presented with a message. If the error is with mysql_connect(), the error is also logged. However, the code looks very unprofessional and over the top. It makes my scripts look complicated. What's the best way to deal with MySQL errors? Is this better? $conn = mysql_connect("localhost", "", ""); if(!$conn) { // Send yourself an e-mail. error_log("MySQL connection failed! Date: " . date("l jS \of F, Y, h:i:s A") . ". File: " . $_SERVER['REQUEST_URI'], 1, "personaladdress@example.com", "From: help@mysite.com"); // Redirect user to error page. header("Location: mysql-error.php"); die(); } $selectdb = mysql_select_db(""); if(!$selectdb) { // Send yourself an e-mail. error_log("MySQL select database failed! Date: " . date("l jS \of F, Y, h:i:s A") . ". File: " . $_SERVER['REQUEST_URI'], 1, "personaladdress@example.com", "From: help@mysite.com"); // Redirect user to error page. header("Location: mysql-error.php"); die(); } $query = mysql_query("", $conn); if(!$query) { // Send yourself an e-mail. error_log("MySQL failed failed! Date: " . date("l jS \of F, Y, h:i:s A") . ". File: " . $_SERVER['REQUEST_URI'], 1, "personaladdress@example.com", "From: help@mysite.com"); // Redirect user to error page. header("Location: mysql-error.php"); die(); }
  2. Error SQL query: # # Table structure for table `message` # CREATE TABLE `message` ( `messageid` int( 11 ) NOT NULL AUTO_INCREMENT ,`isread` char( 1 ) NOT NULL default '0', `lockstatus` char( 1 ) NOT NULL default '0', `message` longtext, `sender` varchar( 50 ) NOT NULL default '', `recipient` varchar( 50 ) NOT NULL default '', `date` timestamp( 14 ) NOT NULL , PRIMARY KEY ( `messageid` ) , KEY `sender` ( `sender` ) , KEY `recipient` ( `recipient` ) , KEY `readstatus` ( `recipient` , `isread` ) ) ENGINE = MYISAM AUTO_INCREMENT =5; MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(14) NOT NULL, PRIMARY KEY (`messageid`), KEY `sender` (`sender`), KEY' at line 12
  3. Hello, I am new to mysqli and have a little question. I have tried to find an alternative for a while now but nothing seems to work... maybe somebody could help. So my old code is this function ($email) { $query = mysql_query("SELECT COUNT(`user_id`) FROM users WHERE email = '$email'")or die (mysql_error()); return (mysql_result($query, 0) == 1) ? true : false; } after that the function is used like this : if (login_email_exists($mysqli,$_POST['email']) === true) { $errors[] = 'Sorry this email adress is already in use.'; } And my new code is this function ($mysqli,$email) { $query = $mysqli->query("SELECT COUNT(`user_id`) FROM users WHERE email = '$email'")or die (mysql_error()); return ($query == 1) ? true : false; } Now it seems to always go wrong when I want to check the result and return if it's true or false. If anybody can find an answer or alternative to my problem I would be very happy.
  4. I made a plugin for bukkit gameserver which uses java http request for mysql queries so people won't be able to see the mysql password by decompiling the java code. Then I made a php script which should instert something in a database but it says: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/u177206076/public_html/*****.php on line 7 I added this: or die("Error: ". mysql_error(). " with query ". $sql); and then it says: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/u177206076/public_html/report.php on line 7 Error: Unknown column 'mighty2361' in 'where clause' with query SELECT * FROM users WHERE username=`mighty2361` and password=`**********` (I use md5). <?php $myusername1 = $_GET['user']; $mypassword1 = md5 ($_GET['pass']); $reportedplayer = $_GET['reportedplayer']; $by = $_GET['by']; $reason = $_GET['reason']; $count=mysql_num_rows($result); $host = "mysql.0adshost.tk"; $username = ""; $password = ""; $db_name = ""; $tbl_name = "users"; mysql_connect ($host, $username, $password)or die("Cannot connect"); mysql_select_db($db_name)or die("Cannot select db"); $myusername = stripslashes($myusername1); $mypassword = stripslashes($mypassword1); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username=`$myusername` and password=`$mypassword`"; $result=mysql_query($sql) or die("Error: ". mysql_error(). " with query ". $sql); if($count==1) { mysql_query ("INSERT INTO `reports`(`user`, `reportedplayer`, `by`, `reason`) VALUES ($myusername, $reportedplayer, $by, $reason)"); } else echo mysql_error; ?> The mysql table, user and pass aren't empty. I just don't want people to see them. Please help because I'm really new to PHP and I am probably too young for it.
×
×
  • 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.