Jump to content

derekshull

Members
  • Posts

    103
  • Joined

  • Last visited

Everything posted by derekshull

  1. I have a piece of code that I'm not sure why it isn't right. I have a list of names in a SQL table and I want to see if the current username matches any of the usernames in the list and if not redirect it to another page. Here's what I have: global $user; $username = $user->name; $query = mysql_query("SELECT submittedusername FROM org"); $rows = mysql_fetch_array($query); If ($rows != $username) { $yquery = drupal_get_destination(); drupal_goto('/node/registerfirst',$yquery); } Where an i going wrong?
  2. I figured it out though.
  3. You are correct I aplogize.
  4. I have this code: <?php // template.php code function horizontal_login_block($form) { $form['#action'] = url($_GET['q'], array('query' => drupal_get_destination())); $form['#id'] = 'horizontal-login-block'; $form['#validate'] = user_login_default_validators(); $form['#submit'][] = 'user_login_submit'; $form['#prefix'] = ''; $form['#suffix'] = ''; $form['name'] = array ( '#type' => 'textfield', '#prefix' => '', '#suffix' => '', '#maxlength' => USERNAME_MAX_LENGTH, '#size' => 15, '#required' => TRUE, '#default_value' => 'Username', '#attributes' => array('onblur' => "if (this.value == '') {this.value = 'Username';}", 'onfocus' => "if (this.value == 'Username') {this.value = '';}" ), ); $form['pass'] = array ( '#type' => 'password', '#maxlength' => 60, '#size' => 15, '#required' => TRUE, '#prefix' => '', '#suffix' => '', ); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Login'); return $form; } ?> Right now the Username and Password and Login button are vertical but I want to make them horizontal. Any idea how to accomplish this? I have this calling it to the page: <?php print login_bar(); function login_bar() { global $user; if ($user->uid == 0) { $form = drupal_get_form('horizontal_login_block'); // Drupal 7 uses a new function 'render'. return render($form); } else { return t('Welcome back ') . ucwords($user->name); } } ?>
  5. Got it! Thanks!
  6. I have an issue with something. I have two records in the database. One has the "orgname" as NULL and the other has it as Syntron. I did this query: $query = mysql_query("SELECT * FROM needs WHERE orgname IS NULL AND needsusername='$username' OR workerusername='$username' ORDER BY ID"); while ($rows = mysql_fetch_array($query)) { $id = $rows['ID']; $status = $rows['status']; $firstname = $rows['firstname']; $city = $rows['city']; $state = $rows['state']; $phone = $rows['phone']; $email = $rows['email']; $typeofneed = $rows['typeofneed']; $description = $rows['description']; $workername = $rows['workername']; $workeremail = $rows['workeremail']; $workerphone = $rows['workerphone']; $completiondate = $rows['completiondate']; $needsusername = $rows['needsusername']; $workerusername = $rows['workerusername']; echo "<center> <table> <tr> <td>ID: $id</td> </tr> <tr> <td>Needs Username: $needsusername</td> <td>Worker Username: $workerusername</td> </tr> <tr> <td>Needs Phone: $phone</td> <td>Worker Phone: $workerphone</td> </tr> <tr> <td>Needs Email: $email</td> <td>Worker Email: $workeremail</td> </tr> <tr> <td>Need Contact: $firstname</td> <td>Worker Contact: $workername</td> </tr> <tr> <td>Need City & State: $city $state</td> </tr> <tr> <td>Type of Need: $typeofneed</td> </tr> <tr> <td>Description: $description</td> </tr> <tr> <td>Status of Need: $status</td> </tr> <tr> <td>Completion Date: $completiondate</td> </tr> </table> Enter completion date: <form action='reallyupdate' method='post'><input type='hidden' name='idtosubmit' value=$id>Month: <select name='month' size='1'> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> <option value='8'>8</option> <option value='9'>9</option> <option value='10'>10</option> <option value='11'>11</option> <option value='12'>12</option> </select> Day: <select name='day' size='1'> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> <option value='8'>8</option> <option value='9'>9</option> <option value='10'>10</option> <option value='11'>11</option> <option value='12'>12</option> <option value='13'>13</option> <option value='14'>14</option> <option value='15'>15</option> <option value='16'>16</option> <option value='17'>17</option> <option value='18'>18</option> <option value='19'>19</option> <option value='20'>20</option> <option value='21'>21</option> <option value='22'>22</option> <option value='23'>23</option> <option value='24'>24</option> <option value='25'>25</option> <option value='26'>26</option> <option value='27'>27</option> <option value='28'>28</option> <option value='29'>29</option> <option value='30'>30</option> <option value='31'>31</option> </select> Year: <select name='year' size='1'> <option value='2012'>2012</option> <option value='2013'>2013</option> <option value='2014'>2014</option> <option value='2015'>2015</option> <option value='2016'>2016</option> <option value='2017'>2017</option> <option value='2018'>2018</option> <option value='2019'>2019</option> <option value='2020'>2020</option> <option value='2021'>2021</option> </select><br><br> <input type='submit' value='Click to Update'></form> <br> If after contact with the other organization/individual you want to cancel the project but post it back on the website click this button: <form action='putbackonsite' method='post'><input type='hidden' name='idtoapprove' value=$id><input type='submit' value='Post Need on Website'></form> <br><br>---------------------------------------------------------<br><br></center>"; } It works fine. But then I did this (in the same script): $query = mysql_query("SELECT * FROM needs WHERE orgname IS NOT NULL AND needsusername='$username' OR workerusername='$username' ORDER BY ID"); while ($rows = mysql_fetch_array($query)) { $id = $rows['ID']; $status = $rows['status']; $firstname = $rows['firstname']; $city = $rows['city']; $state = $rows['state']; $phone = $rows['phone']; $email = $rows['email']; $typeofneed = $rows['typeofneed']; $description = $rows['description']; $workername = $rows['workername']; $workeremail = $rows['workeremail']; $workerphone = $rows['workerphone']; $completiondate = $rows['completiondate']; $needsusername = $rows['needsusername']; $workerusername = $rows['workerusername']; $orgname = $rows['orgname']; echo "<center> <table> <tr> <td>ID: $id</td> </tr> <tr> <td>Organization Name: $orgname</td> </tr> <tr> <td>Needs Username: $needsusername</td> <td>Worker Username: $workerusername</td> </tr> <tr> <td>Needs Phone: $phone</td> <td>Worker Phone: $workerphone</td> </tr> <tr> <td>Needs Email: $email</td> <td>Worker Email: $workeremail</td> </tr> <tr> <td>Need Contact: $firstname</td> <td>Worker Contact: $workername</td> </tr> <tr> <td>Need City & State: $city $state</td> </tr> <tr> <td>Type of Need: $typeofneed</td> </tr> <tr> <td>Description: $description</td> </tr> <tr> <td>Status of Need: $status</td> </tr> <tr> <td>Completion Date: $completiondate</td> </tr> </table> Enter completion date: <form action='reallyupdate' method='post'><input type='hidden' name='idtosubmit' value=$id>Month: <select name='month' size='1'> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> <option value='8'>8</option> <option value='9'>9</option> <option value='10'>10</option> <option value='11'>11</option> <option value='12'>12</option> </select> Day: <select name='day' size='1'> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> <option value='8'>8</option> <option value='9'>9</option> <option value='10'>10</option> <option value='11'>11</option> <option value='12'>12</option> <option value='13'>13</option> <option value='14'>14</option> <option value='15'>15</option> <option value='16'>16</option> <option value='17'>17</option> <option value='18'>18</option> <option value='19'>19</option> <option value='20'>20</option> <option value='21'>21</option> <option value='22'>22</option> <option value='23'>23</option> <option value='24'>24</option> <option value='25'>25</option> <option value='26'>26</option> <option value='27'>27</option> <option value='28'>28</option> <option value='29'>29</option> <option value='30'>30</option> <option value='31'>31</option> </select> Year: <select name='year' size='1'> <option value='2012'>2012</option> <option value='2013'>2013</option> <option value='2014'>2014</option> <option value='2015'>2015</option> <option value='2016'>2016</option> <option value='2017'>2017</option> <option value='2018'>2018</option> <option value='2019'>2019</option> <option value='2020'>2020</option> <option value='2021'>2021</option> </select><br><br> <input type='submit' value='Click to Update'></form> <br> If after contact with the other organization/individual you want to cancel the project but post it back on the website click this button: <form action='putbackonsite' method='post'><input type='hidden' name='idtoapprove' value=$id><input type='submit' value='Post Need on Website'></form> <br><br>---------------------------------------------------------<br><br></center>"; } It still gives me both records! whether "orgname" is NULL or not. What's up with that?
  7. $workerusername=$_POST['workerusername']; $addedtogether = intval($_POST['question1']) + intval($_POST['question2']) + intval($_POST['question3']); $query = "INSERT INTO survey (username, voted, total) VALUES ('$workerusername', '$addedtogether', '30') ON DUPLICATE KEY UPDATE `voted` = VALUES(`voted`)+$addedtogether, `total` = VALUES(`total`)+30"; mysql_query($query) or die("Query: $query Error: ".mysql_error()); echo "<center>Thank you for your feedback!</center>"; ?> Heres my current but still same issue.
  8. $workerusername=$_POST['workerusername']; $addedtogether = intval($_POST['question1']) + intval($_POST['question2']) + intval($_POST['question3']); $query = "INSERT INTO survey (username, voted, total) VALUES ('$workerusername', '$addedtogether', '30') ON DUPLICATE KEY UPDATE `voted` = VALUES(`voted`)+$addedtogether, `total` = VALUES(`total`)+30"; mysql_query($query) or die("Query: $query Error: ".mysql_error()); echo "<center>Thank you for your feedback!</center>"; ?> I have this right now but something is wrong. when i submit one survey i put 30/30 and when i look at the database it does that. Then the next survey I submit I put 0/30...it will add the 30 to the total but it changes the value of "voted" to 0....but it should be30/60. Then I submit another survey and from then on the total amount doesn't change it stays at 60 and the "voted" value is whatever I submit from that particular form. So if I submit 25/30 it would be 25/60 in the database. Then if I submit 12/30 it shows up as 12/60 in the database....what is wrong?
  9. $workerusername=$_POST['workerusername']; $q1=$_POST['question1']; $q2=$_POST['question2']; $q3=$_POST['question3']; $addedtogether = $q1 + $q2 + $q3; $query = "INSERT INTO survey (username, voted, total) VALUES ('$workerusername', '$addedtogether', '30') ON DUPLICATE KEY UPDATE `voted` = $addedtogether + VALUES(`voted`), `total` = 30 + VALUES(`total`)"; mysql_query($query) or die("Query: $query Error: ".mysql_error()); Here is what I have just one problem. When I submit a survey and send in 10's on all the questions (so it'd be a score of 30/30). Then next time that I submit a survey I give it all 0. Which means that It should be 60/30 but it makes it 60/0. So apparently it adds totals correct but not the $addtogether variable right. stumpd.
  10. What do you mean i swapped things?
  11. Nevermind I switched it back to getting $username and $values like I had it last time and it works Thanks for the code.
  12. I changed the varchar to int for the numbers...should I put that back?
  13. I got this error: Parse error: syntax error, unexpected T_STRING in/home/content/17/9932517/html/1511project/modules/php/php.module(80) : eval()'d code on line 34 Its on the $values line.
  14. I need help with this php survey script. It's supposed to check and see if there are any usernames that are already in the system and if there are then it just adds the values "voted" and "total" to the existing values that are there. If the username is not in the database it will insert that name and add the values. What I have right now is this: $workerusername=$_POST['workerusername']; $q1=$_POST['question1']; $q2=$_POST['question2']; $q3=$_POST['question3']; $values = $q1 + $q2 + $q3; mysql_query("INSERT INTO survey (username, voted, total) VALUES ($workerusername, $values, '30') ON DUPLICATE KEY UPDATE `voted` = $values + VALUES(`voted`), `total` = 30 + VALUES(`total`)"); What am I doing wrong? My primary key in the database is ID and then I have username, voted, and total as varchar.
  15. Ok I'm on the right track. It's just not working for some reason. Here's the code: $workerusername=$_POST['workerusername']; $q1=$_POST['question1']; $q2=$_POST['question2']; $q3=$_POST['question3']; $values = $q1 + $q2 + $q3; mysql_query("INSERT INTO survey (`username`, `voted`, `total`) VALUES ($workerusername, $values, '30') ON DUPLICATE KEY UPDATE `voted` = $values + VALUES(`voted`), `total` = 30 + VALUES(`total`)"); I only have 3 questions in the survey so thats why I add 30 to the total each time there is a duplicate. What am I missing? In the database I made the primary key the username of the person that is being rated....is that correct? or should I make an ID column the primary and make the username column just be normal?
  16. So i have this right now: $workerusername=$_POST['workerusername']; mysql_query("INSERT INTO `survey` (`workerusername`, `voted`, `total`) ON DUPLICATE KEY UPDATE `voted` = `voted` + VALUES(`voted`), `total` = `total` + VALUES(`total`)"); The script is getting the workers username (who is the person being rated on) and if the workerusername is already in the username column I want it to just add the "total" and "voted" values to the existing ones.... If the workerusername is not in the table I want to insert it in and add the values to "total" and "voted" does that makes sense?
  17. no it'd be 9/20 then
  18. I have a survey for the people on my site. They rate each question from 0-10 from a select drop down box. There are 5 questions. So I have a table called "survey" If the person's username is already in the table under the "username" column then I want it to add the values to the "voted" column and "total" column. So it'd be adding to whats already there. If the username is not in the "username" column then I want to insert it into the "username" column and add the values to "voted" and "total". I'm still stumped :=/
  19. Ah when I did that earlier I put GROUP BY city AND state.....when I should have put city, state. Thanks everyone!
  20. $query = mysql_query("SELECT state, city, count(city) as num, count(state) as statenum FROM needs WHERE status='posted' GROUP BY city ORDER BY state DESC"); while ($rows = mysql_fetch_array($query)): $city = $rows['city']; $state = $rows['state']; $citycount = $rows['num']; // num is holding your count by city echo " <a href='http://www.1511project.com/node/browseresults.php?city=$city&state=$state'>$city, $state ($citycount)</a><br><br>"; endwhile This is what I have right now
  21. I have one more issue So I have a record that has Jonesboro, AR and Jonesboro, GA When I do this code it groups Jonesboro, GA into Jonesboro, AR How do I get it to seperate city and state.
  22. miosko I did group by city and state and it only showed me one city...weird but the other code works thank!
  23. What do I replace that line with though? It needs to count how many records there are of each city. I'm confused how that is done.
  24. Ok i got it to show the city and show a number next to the city but even when I have multiple records for that city it only says there is one record....this is what I have: $query = mysql_query("SELECT state, city, count(city) as num FROM needs WHERE status='posted' GROUP BY city ORDER BY count(city) DESC"); $citycount = count(city); while ($rows = mysql_fetch_array($query)): $city = $rows['city']; $state = $rows['state']; echo " $city, $state ($citycount)<br><br>"; endwhile; Where am I screwing up at?
  25. I'm not trying to join them together I'm just trying to display any cities that are in the "city" column of the table called "needs" and then beside that name of the city I want it to display how many records there are of that city. Thus: Example is if there are 10 records in Jonesboro and 3 in Harrisburg then the page will look like this: Jonesboro (10) Harrisburg (3)
×
×
  • 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.