Jump to content

Little Push In The Right Direction With My Simple PHP Script


notacoder

Recommended Posts

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";

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.