stormx Posted November 30, 2008 Share Posted November 30, 2008 Hello, I cannot pinpoint where the error is on my script: <?php error_reporting(0); session_start(); include 'my_sql.php'; $sql_users = mysql_query("SELECT `id` FROM `users`") or die("Error Selecting ID from users.</strong>"); date_default_timezone_set('Australia/Victoria'); while($id = mysql_fetch_array($sql_users)) { $plan1_sql = mysql_query("SELECT * FROM `plan` WHERE `id` = '$id[plan]'") or die("Error!"); $plans = mysql_fetch_array($plan1_sql); date_default_timezone_set('Australia/Victoria'); $plan_id = $id["plan"]; $result = mysql_query("SELECT * FROM plan WHERE id='$plan_id'"); while($plans = mysql_fetch_array($result)) { } $service_number = $id["service"]; $invoice_id = rand(); $amount = $plans['mcharge']; $userid = $id['id']; $status_pending = "PENDING"; $acc_rep = $id['representative']; $addressss = $id['address']; $acc_add_name = $acc_rep . $addressss; $today_date = date("Y-m-d"); $notes = "AWAITING AUTO DEBIT"; $month = date("F"); $year = date ("Y"); $item_desc = "Monthly Charge On Plan $plans[name] For $month $year"; mysql_query("INSERT INTO invoices (date, servicenumber, invoiceid, amount, view, userid, status, name_address, item, totalprice, notes) VALUES ('$today_date', '$service_number', '$invoice_id', '$amount', '$service_number', '$userid', '$status_pending', '$acc_add_name', '$item_desc', '$amount', '$notes')") or die(mysql_error()); ?> The issue is around the $plan1_sql = mysql_query("SELECT * FROM `plan` WHERE `id` = '$id[plan]'") or die("Error!"); $plans = mysql_fetch_array($plan1_sql); mark, it's not selecting any data at all.. Please help ??? Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 30, 2008 Share Posted November 30, 2008 Unless "plan" is a constant, you can't use $id[plan]. The index name must have quotes around it. Try this: $query = "SELECT * FROM `plan` WHERE `id` = '{$id['plan']}'" $plan1_sql = mysql_query($query) or die("Error!"); Quote Link to comment Share on other sites More sharing options...
stormx Posted November 30, 2008 Author Share Posted November 30, 2008 Hmm.. I get the Parse error: syntax error, unexpected T_VARIABLE I fixed it by adding ; on the first line But it's still not getting anything from the database and inserting it into another table:( Thanks for your help so far mjdamato Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 30, 2008 Share Posted November 30, 2008 OK, after a more thorough look at the code - it is not amkign any sense. The same query is being run twice - with nothing being doine with the results from the first query not being used. Plus, after the second query, there is a while loop that does nothing inside the loop which leaves only the last record being assinged to the array variable $plans. Then, that avaraible is only used once for $plans['mcharge']. I have no clue what is trying to be accomplished here. And, why wuld you turn off error reporting when there are problems you are trying to debug? Also, I always create my queries as string variables so I can echo them to the page when there is a problem. It helps to determine that variables have the values I expect them to. Lastly, you are running nested queries. That can be done MUCH more efficiently by using JOINs in your queries. I think much of the problem is due to the fact that the very first query is only returning the id column, but the second query is trying to use the 'plan' value. The first query will need to return that column if you want to use it. I would make an attempt at fixing the code, but again I'm not 100% sure of what the goal is. 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.