jmrothermel Posted December 15, 2008 Share Posted December 15, 2008 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] Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 15, 2008 Share Posted December 15, 2008 $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. Quote Link to comment Share on other sites More sharing options...
jmrothermel Posted December 15, 2008 Author Share Posted December 15, 2008 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted December 15, 2008 Share Posted December 15, 2008 Then change the date format in your form. Quote Link to comment Share on other sites More sharing options...
jmrothermel Posted December 15, 2008 Author Share Posted December 15, 2008 Im sorry to be stupid - I thought I did. Isnt the capital Y the php code for the 4 digit year format? $date = date("Y-m-d"); Quote Link to comment Share on other sites More sharing options...
fenway Posted December 15, 2008 Share Posted December 15, 2008 Apparently.... Quote Link to comment Share on other sites More sharing options...
corbin Posted December 15, 2008 Share Posted December 15, 2008 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.