Defining vars for database - php

I have worked with MySQL before but it has been a LONG time ago. Now I am trying to set up a database using phpMyAdmin.
I am trying to setup this database for the Article Friendly script. The instructions state that you need to use a little script that they have furnished:
define("DB_NAME","a6852953_article");
define("SERVER_NAME","'mysql12.000webhost.com'");
define("USER_NAME","a6852953_article");
define("PASSWORD","*********");
$dbhost=SERVER_NAME;
$dbuser=USER_NAME;
$dbpasswd=PASSWORD;
$dbname=DB_NAME;
It chokes on the first line, and if I remove that it chokes on whatever is there.
The syntax looks correct to me with what little I remember and I also checked the manual for 5.1 which is what my host uses.
Can anyone spot anything wrong?

Looks like it might actually be choking on the second line...
define("SERVER_NAME","'mysql12.000webhost.com'");
... likely because you have single quotes inside the double quotes. Try changing the line to this:
define("SERVER_NAME","mysql12.000webhost.com");
If it is the first line however, make sure that the database you listed already exists -- if not, you should be able to login to phpMyAdmin and run:
CREATE DATABASE a6852953_article
:)

Related

Something seems to fail after 1622 characters(null values)

I'm having this issue with the JSONAPI for minecraft. http://mcjsonapi.com/
I am trying to use the method "files.write" or "setFileContents" to replace the contents of a file. The website states this about the method.
Pretty simple. Just rewrites the file right? Yeah but this is proving to be more difficult then I thought. At first attempt, I was trying to set 3450 characters to the file "groups.yml" on the minecraft server. Here's the code I ran in PHP:
var_dump(
$api->call("files.write", array("plugins/GroupManager/worlds/world/groups.yml", (string)$yaml))
);
The var_dump is supposed to either return a success statement or an error describing what went wrong. But instead all I get is "null". This isn't right, and I know $yaml is being casted to a string, which isn't the issue. So I decide to start testing around. After much testing, I find that the character length of what I can set is exactly 1622. Adding another space or anything causes null, otherwise, it works. This is the modified file that is below 1622 characters I tested with.
So great, you found the issue, right? No, I didn't. I thought 1622 was an odd number to stop working, so I did some further testing. I tried to set 3000 characters I generated from just smashing my keyboard, and it worked! So what's going on here?
This and this works, but this doesn't. Why is this? This app called Adminium runs this exact API, and includes a file management system inside the app which I am assuming uses the same methods I am using, but it doesn't have a problem.
I have a forum post here that I also asked on, and still haven't gotten to an answer yet.

Trouble with this "Update" command

I was given an sql database that I was supposed to do some stuff on, and I want to clean it up, given that they have stuff with "special characters" as values, such as carcaças. Notice the `ç.
My Update command just simply doesn't want to work. I've checked in a million times and the weird part is on the webservice that I'm creating using that database the line seems to do nothing, but when I go on phpmyadmin it works perfectly. It has nothing to do with permissions given that its all being hosted on my computer.
So here you go the code:
function filter($stockconn){
mysqli_query($stockconn,"UPDATE produtos SET familiaprod='Carcacas' WHERE familiaprod='Carcaças'") or die(mysql_error());
mysqli_close($stockconn);
}
So far its all very simple, simple connection file (which is working correctly 100%) being pulled towards that function.

PHP button delete row from table not working

I am having the simple php code that shows columns in table test (delete.php & delete_ac.php), when click on delete button this suppose to delete the respective column. But it is displaying error occurred and the table HTML showing blank. Not sure which steps i was wrong. Any help are very appreciated.!
http://pastebin.com/9Zz217Bn
I suggest using
echo mysqli_error();
to see what the error is.
Also you don't seem to be setting $id.
From your responses it seems that you have an error in the sql. The error might be from the way you are sending your data to the script. Tangentially you are encountering an error because you have not in any way checked the input which could be anything and are trusting that it is valid data. It helps to assume that all users are mean and want to cause damage.
So I would recommend at least an if and a test for the data being numeric. Then you could see if you were passing bad data. This might help you troubleshoot and will make your code more robust against attack, user error and things like that. You would not want someone manually typing the URL and putting id=>-1 as that would delete everything.
Like the one you commented:
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 'id']; ?>'' at line 1 mysql version is 5.6.12
However what you might need to do (as others have pointed out) is echo the sql and paste it into something like phpmyAdmin or some MySQL GUI and see what it you get back. The (more than likely) error may help you identify the cause of your problems. It looks like you might have ended up with the php code in the query string.
If you have short tags off then the short php you have use will not work and will end up in the link which it does seem to have done. Try:
<?php echo $rows['id']; ?>
Which I think will work for you much better.
If in doubt go back to the earlier suggestion (not just from me) to echo out the generated sql which I would expect will not look right.
While you are at it can I recommend you consider using "LIMIT 1" at the end of your SQL once you have it working? Then if anything goes wrong you only dropped the one row.
One last thing it makes folks here much happier if you just paste the code into the question.
I hope I helped you.
The problem lies in your Querystring of delete button use fuller
Thanks a lots for all answers, i am really appreciated your helpful tips. i have checked the syntax :
<td bgcolor="#FFFFFF">delete</td>
which is missing php line, after filled php line, the code working well:
<td bgcolor="#FFFFFF">delete</td>
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 'id']; ?>'' at line 1 mysql version is 5.6.12

FuelPHP update of ORM results in " instead of " sporadically

I'm using PHP 5.4.4 and I'm getting very strange behavior with the FuelPHP ORM save and update functions.
I'm trying to save either serialized or JSON data to a field in the database so something like {"name":"michael"}. When I use the model->save() directly after Model::forge() it seems to work fine 100% of the time and the string you see is the one that gets stored in the MySQL db.
However, if I immediately change something like model->property = 'new property' (not the JSON or serialized data property) and then do another model->save() it will 90% of the time turn all my " into "
It seems that when I debug the issue and step through line by line, it will not reproduce this problem! It will make through the entire script and still have the correct " instead of "
This problem is driving me nuts. I would assume its a configuration thing or there would be a lot more complaints, but I can't find the right switch. I've set both
php_flag magic_quotes_gpc Off and php_flag magic_quotes_runtime Off in my .htaccess (although it shouldn't be needed in PHP 5.4+) and verified that both are false.
I'm out of ideas here. Anything to investigate would be really helpful.
Your ORM maybe using some sort of escape function to save your json string. This is a security feature to prevent sql injection attacks. Use a noSql solutions like MongoDB or CouchDB if you need to store json. Otherwise you'll need to cleanup your json strings after they come out of mysql and before you decode them.
http://dev.mysql.com/doc/refman/5.0/en/string-literals.html
Try adding some "echo" statements to print out your variables so that you can figure out where its happening. That usually goes a long way toward finding out why.
You might also try adding something like double_encode for the html entities to stop it from encoding them.
if " are converted to " in database then its not a problem. Its for security. If you render the output on browser it will come up as " again.
And if its your browser displaying " as " then you need to decode the value before printing .

phpmyadmin show full sql output

Seems phpmyadmin trims the end of the sql output when running operation commands ..
I really need phpmyadmin to show the full output
Any Ideas?
After a quick search on Google i found this: http://wiki.phpmyadmin.net/pma/Config#MaxCharactersInDisplayedSQL
It seems that you just have to edit the config file of PHPmyadmin and set $cfg['MaxCharactersInDisplayedSQL'] = 1000; to the value you want.
My problem was even more simple. I was using "show create table", but the result was truncated after a handful of chars.
PHPMyAdmin actually has a small "+options" link over the results, with simple options like "truncate results". Just needed to untick that !
If you want to edit the files mentionned by Torr, look for :
config.default.php, in 'librairies" folder, which contains existing parameters
config.inc.php, where you should copy/paste the ones you need to.

Categories