notacoder Posted August 28, 2010 Share Posted August 28, 2010 Hello, I defnitely don't consider myself a coder but have been installing and troubleshooting pre-made php scripts for a few years now and figure now is a good time to learn as I'm quite sick of having to rely on outsourced help I am currently trying to create a simple (hope so) script that will run on a cron every other minute to insert a specific piece of data each time a new member joins and it should only insert the data once based on criteria. Here's what I'm trying to do exactly with a php script check members table if field signup_date is TODAY's Date and if user_balance field is 0.00 then alter/update user_balance field 25.00 Now, I've hit a bit of a roadblock with getting the MySQL query format correct. The SIGNUP_DATE field in the database is DATETIME format and the like with wildcard thing isn't working for me. Is there anyone who can point me in the right direction with the proper wildcard date format? It'd be a great help. Anything at all is massively appreciated. Here's the code I have so far...the echo is in there so I can see if it's working correctly. I'm pretty sure I haven't got the right function to display the result of the query either but I think I can figure that out pretty easily. <?php $today = date("Y-m-d"); mysql_connect("localhost", "DBUSER", "DBUSER") or die(mysql_error()); mysql_select_db("DBNAME") or die(mysql_error()); $sql1 = mysql_query("SELECT USER_NAME FROM members WHERE SIGNUP_DATE LIKE '$today%"); if($sql1 == false) { user_error("Query failed: " . mysql_error() . "<br />\n$query"); } elseif(mysql_num_rows($sql1) == 0) { echo "<p>Sorry, no rows were returned by your query.</p>\n"; } $memberseligible = mysql_fetch_array($sql1); echo "$memberseligible"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/211973-little-push-in-the-right-direction-with-my-simple-php-script/ Share on other sites More sharing options...
Rifts Posted August 28, 2010 Share Posted August 28, 2010 what error are you getting Quote Link to comment https://forums.phpfreaks.com/topic/211973-little-push-in-the-right-direction-with-my-simple-php-script/#findComment-1104692 Share on other sites More sharing options...
notacoder Posted August 28, 2010 Author Share Posted August 28, 2010 Here's the current one I'm getting... Catchable fatal error: Object of class stdClass could not be converted to string in /home/****/public_html/datetest.php on line 22 Quote Link to comment https://forums.phpfreaks.com/topic/211973-little-push-in-the-right-direction-with-my-simple-php-script/#findComment-1104697 Share on other sites More sharing options...
notacoder Posted August 28, 2010 Author Share Posted August 28, 2010 I've also received several others with other small modifications to the query. Of course, I've received mysql query syntax errors. I've received Resource id #3. Which I think mean's there was no matching queries. However, I'm looking at the entries inside of the database and the date matches today's date and everything else is right so it's a problem with the mysql wildcard query not being the right one and not matching the appropriate criteria. Quote Link to comment https://forums.phpfreaks.com/topic/211973-little-push-in-the-right-direction-with-my-simple-php-script/#findComment-1104698 Share on other sites More sharing options...
jcbones Posted August 29, 2010 Share Posted August 29, 2010 I would run the sql as: $sql1 = mysql_query("SELECT USER_NAME FROM members WHERE SIGNUP_DATE = CURDATE()); You will also get an error on the last line: echo "$memberseligible"; As that variable is an array. You will need to implode() the data, or run it through a foreach() construct. My question is. How is this any better than just setting the default value of user_balance to 25.00 in the database? Then once a user signs up, they will start off with a balance of 25.00. Edit: I think that query may need to be: $sql1 = mysql_query("SELECT USER_NAME FROM members WHERE DATE(SIGNUP_DATE) = CURDATE()); Quote Link to comment https://forums.phpfreaks.com/topic/211973-little-push-in-the-right-direction-with-my-simple-php-script/#findComment-1104749 Share on other sites More sharing options...
notacoder Posted August 29, 2010 Author Share Posted August 29, 2010 I appreciate the reply JCBones and I am going to give that query a shot in a few seconds. And the reason I can't set the default signup balance to $25 is that I can't view or edit the source code unfortunately. So, I can't quite see or edit where the account gets "setup" and have to edit the db manually. I'll get back to you shortly with results of that edit. Quote Link to comment https://forums.phpfreaks.com/topic/211973-little-push-in-the-right-direction-with-my-simple-php-script/#findComment-1104753 Share on other sites More sharing options...
notacoder Posted August 29, 2010 Author Share Posted August 29, 2010 Thanks again jcbones! That helped immensely. Quote Link to comment https://forums.phpfreaks.com/topic/211973-little-push-in-the-right-direction-with-my-simple-php-script/#findComment-1104769 Share on other sites More sharing options...
jcbones Posted August 29, 2010 Share Posted August 29, 2010 I appreciate the reply JCBones and I am going to give that query a shot in a few seconds. And the reason I can't set the default signup balance to $25 is that I can't view or edit the source code unfortunately. So, I can't quite see or edit where the account gets "setup" and have to edit the db manually. I'll get back to you shortly with results of that edit. Your welcome, as a side note, you can alter the database table (only if you are comfortable doing so). $sql = "ALTER TABLE members ALTER user_balance SET DEFAULT '25.00'"; mysql_query($sql); I would like to add, that this is only if the user of the database has the ability to alter tables. Quote Link to comment https://forums.phpfreaks.com/topic/211973-little-push-in-the-right-direction-with-my-simple-php-script/#findComment-1104772 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.