Jump to content

Queries Dont Work on New Server - Worked on Old?


jmrothermel

Recommended Posts

So I moved servers from a shared C-Panel plan to a VDS server (we were too large for the shared plan)  Since then, basic queries that USED to work dont work anymore?  But if I execute them directly in phpmyadmin they work just fine.  For example:

 

if($a == 'feed') {	
$user = $_GET['$username'];
$date = date("y-m-d");

$check= mysql_query("SELECT * FROM pets WHERE `user`='$username'");
$check_num= mysql_num_rows($check);

if ($check_num == "0"){
print "Record could not be found";
}else{

mysql_query("UPDATE `pets` SET `lastfed`='$date' WHERE `user`='$username'") or die (mysql_error());
printf ("Pets Fed: %d\n", mysql_affected_rows());
}}

 

It will return the next page with Pets Fed: 0.  But if I go into the database and go to SQL and type

UPDATE `pets` SET `lastfed`='2008-12-15' WHERE `user`='username'

It will return 143 affected rows.

 

As I stated this worked just fine on the old server, the only thing different is the new server.  No coding was changed.  I am having this problem with ALOT of queries that I execute, so Im wondering if something needs to be added with the new server?

 

Here is my information:

 

Server version: 5.0.67
Protocol version: 10
Server: Localhost via UNIX socket
User: h321760w@localhost 
MySQL charset: UTF-8 Unicode (utf8) 

phpMyAdmin - 2.10.1
MySQL client version: 5.0.24
Used PHP extensions: mysqli
[ChangeLog] [subversion] [Lists] 

Link to comment
Share on other sites

 

$user = $_GET['$username'];

 

Your query is using $username, not $user, so given that code, the only way it ever worked was if register_globals were ON.

 

For that specific piece of code, try -

 

$username = $_GET['$username'];

 

Don't turn register_globals on (even if your web host allows you to) because they have been completely removed in php6 and your code must be updated to work without them.

 

Your code should also be validating all external data (to make sure it even has something in it) and you must use mysql_real_escape_string() on string data that comes from outside your script to prevent sql injection.

Link to comment
Share on other sites

I made the change to the user line as you stated along with changing the date to

 

$date = date("Y-m-d");

 

Because I want a 4 digit year - month - day output.  When I click the dropdown referral link and it processes I get this:

 

feedall.php?action=feed&username=jmrothermel&date=08-12-15

 

Its only giving me a two digit year output.  Why is that?  Obviously I get a 0 lines affected because the date is the improper format.

 

I will also start tidying up my code to start preventing SQL injection - something I hadnt really thought about before now.

Link to comment
Share on other sites

Make sure to put:

 

error_reporting(E_ALL);

and ini_set('display_errors', '1'); in your script to see if any errors are there.

 

 

I would imagine the MySQL queries are failing for some reason or other.  Could be the date, or something else.  What datatype is that column?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.