mysql query will only return results if i hard code the text in the database - mysql

I have a MYSQL database with a query. The query only works if I manually type in the data with MYSQL Admin or with the following statement $sn="x-xxx"; It will not return results if i pass $sn to the database from a form even though the $sn get inserted into the database just fine. I can look at the database and see that it's there. Not sure if why the query would only pull down the records I manually imputed.

Thanks for the help guys. I found that by passing the variable from page to page that a space was being added to the variable. I used:
$sn=preg_replace('/\s+/', '', $sn); and var_dump($sn); to strip the space and to check what was being posed. Wow 5 full days trying to find this. Thanks to everybody who answered.

Related

Converting SQL server query to its equivalent MySQL for trigger

In SQL Server, we can get the last inserted record using inserted table in triggers. I know the equivalent MySQL statement is NEW. But the question is how to implement that.
A snippet is attached herewith what it shows in SQL Server. I want the very same thing in MySQL. Will it be possible to do that?
I want the output as:
Please give the total implementation. I've tried NEW in different ways those didn't work out.
Thanks.

Wordpress 4.2.2 update - failing wpdb->insert

context
I have been working on a new wordpress blog as a personal website. Part of it, I have a custom contact form where people put in their details to get in touch with me.It has been working good till morning, after which I have updated to 4.2.2v citing security reasons.
problem
After the update, the form is failing to save any of the information into the DB. The $wpdb->insert_id is returning 0. The query is the same, the page is the same, everything is just the same. The only change is I have upgraded to 4.2.2v from 4.2.1v.
Is there any issue with the recent update or do I have to do any more steps after the word press manual update ?
debugging done...
I have ensured that the DB version is updated. It is showing 31535. When debugging using the $wpdb->lastquery and $wpdb->print_error() I get
WordPress database error: []
SHOW FULL COLUMNS FROM `wp_tst_tbl_contacts`
?
I could not understand what is wrong here. If I run the same insert query, as well as the above show full columns on command line using the same user wp user credentials, it works perfectly.
note: If there is anymore information needed, please ask.
I found the problem cause. Its due to a column width limitation.
I have a VARCHAR(9) column and I was sending data that is 16 char length. The new change in the 4.2.2 gets the table meta and crops the data such that it fits properly into the size of the column as defined in DB. And it also compares the pre-crop and post-crop data. If they don't match, it is failing.
The problem is, its failing silently with no error thrown. I have found this via debugging the wpincludes/wp-db.php file.
Please check your column limit and the column data length you send.
Once I have increased the column width (as the data will definitely be more than 9 chars), the issue got resolved.
I was experiencing this same issue and it turned out to be some unescaped values being pushed into the database from a csv import function.
I applied the proper esc_url() and / or esc_attr() and / or esc_html() where appropriate to sanitize the values pre-insertion and then the query ran successfully.

phpMyAdmin table search returning empty result but SQL select works for specific table

It is very strange what is happening, I have never seen this before and I am pretty familiar with mysql.
When searching a table using the phpMyAdmin table search feature, the result is empty no matter what I put. For example, searching 77 in the ID column returns empty result. However if I run an SQL query also in phpMyAdmin, and then there is the result. For example, select * from table1 where id = ‘77’;
What is even more strange is this only happens on one table, all other tables the search feature is working fine.
I tried repairing the table but empty result still occurs.
I couldn’t find this happening anywhere to any one online…..
Also restarted sql server.
Are you using cPanel - if yes I just described how to fix the problem on cPanel forums:
http://forums.cpanel.net/f5/unable-use-phpmyadmin-search-users-table-313381.html
If your table has a large number of fields an update via the phpMyAdmin interface can exceed the value for the PHP setting 'max_input_vars'. When this happens some of the internal form fields that phpMyAdmin is expecting to receive on the page your update is being posted to are truncated which causes phpMyAdmin to fail, unfortunately silently, and the page redirects with no warnings back to the blank search form. The default for 'max_input_vars' is 1000. I upped mine in my php.ini file to 5000 with no negative side affects and it solved this problem for me.
The setting 'max_input_vars' has a mode of PHP_INI_PERDIR so if you don't have access to your php.ini file then you may be able to set it in an .htaccess file, your httpd.conf file or your .user.ini (since PHP 5.3) file if you have one. I'm not sure exactly what code you would need for an htaccess file but the PHP code to do it is below.
ini_set('max_input_vars', '5000');
Hopefully that should get you started in the right direction.
Very easy. Go to the table and expose max number of rows as much as is showed in the dropdown. Then you are able to search per big pages. It doesnt fetch text through all the table. It plays only with a page of the table.

MySQL Error 2013 after a failed attempt to import

I was importing one table in a MySQL Server when the power went down. After this event I tried to query the table I was importing, but got the error 2013, only when I'm querying this table (the others work just fine).
I have physical access to the server, tried to execute any query from there (tried to SELECT, and even DROP TABLE) but still got the same error.
Does anybody know a solution where I can re-build only the table (without building the whole schema from scratch?)
I'm adding this as an answer rather than having lots of comments underneath. I must state in advance that I've not used MySQL but I have used SQL server a lot so I'm hoping that something I say may help.
You say the table is still there. Was it created as part of the operation you were doing or had it been there for a while?
What happens if someone else or a different account tries to access this table?
Is there anything on this page that is relevant to your problem?
http://dev.mysql.com/doc/refman/5.0/en/gone-away.html

Query a online database

I know very little about databases. Is it possible to make a query to a sql server with a URL? if yes, can you provide a sample explanation.
Also another question, what is the best way to handle this situation in code?
No, it is not possible to query a database via URL. But you can build one on your own.
On your server, receive the query via URL and run the query and return the output of the query to the user.
But this is highly discouraged, as anyone can access your database, unless you add security measures, by asking for username/password in the URL itself.
ya you can do so by passing thee sql query as get value of the link
eg. http://www.site.com/?query=Select * from tbl
n then use that query inside of the page
by just connecting db n executing it..
you will get your ans as json object
thats it