Jump to content

NETSYNC

Members
  • Posts

    22
  • Joined

  • Last visited

    Never

Everything posted by NETSYNC

  1. I am going to try this tonight. Thanks very much for the reply and the tip! Hopefully this is it!
  2. Hey guys. I am using Usercake to build a small user login site with only 2 pages. My problem is that for some reason when I log in the first time it works. But after I submit a form which enters info into a database, upon return the session is dead. Nowhere in these files should be killing the session. Then when I login the second time and do all the same stuff it works flawlessly until I logout. My question is: How to troubleshoot sessions? How can I pinpoint where exactly the session is getting killed? I am at a loss on how to figure out where the issue is. Thanks for any tips!
  3. I figured it out actually. I simply made the second section and ELSE of the top if instead of two seperate. So if the field is empty it does not even check the database at all.
  4. Hey all. I have a simple code for verifying some data. I have two echos from if statements. The first is if the text input is empty echo: HELLO. The second is if text input data is not found in database echo: NOPE. Now in the following code the second one works fine. But the problem is if I leave the field empty BOTH echos show. So if I leave the input empty instead of saying "HELLO" it says, "HELLONOPE". Yet the second one works fine and display only "NOPE" The other thing is if I switch the two echos to die instead, they work fine. if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['id']) { echo "HELLO"; } // checks it against the database $check = mysql_query("SELECT * FROM emp WHERE id = '".$_POST['id']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { echo "NOPE"; } else { //if login good then redirect them to the members area $id = $_POST['id']; header("Location: somepage.php?id=$id"); } } else { // they are not logged in } <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <input type="text" name="id" maxlength="40"> <input type="submit" name="submit" value="Login"> </form> What am I doing wrong?
  5. Oh duh me! It works now! Thank you sir!
  6. Ok based on that I did this. Now neither validate and the script errors on submit. The error is: "Fatal error: Call to undefined function validateForm() in /nfs/c06/h02/mnt/94387/xxxxxxx/formtest.php on line 12" <?php // options for drop-down menu $choices = array('-- Choose Your Item','Anniversary Jacket', 'Anniversary T-Shirt'); $sizes = array('-- Choose Your Size','L', 'XL'); if($_SERVER['REQUEST_METHOD'] == 'GET'){ // display form when GET showForm(array()); } else{ // process form if POST $errors = validateForm(); if(count($errors)) showForm($errors); // if errors show again else print 'Form submitted succesfully!'; // no errors } // function generating form function showForm($errors){ global $choices,$sizes; // set defaults $defaults = array(); foreach($choices as $key => $choice){ if(isset($_POST['item']) && ($_POST['item'] == $key)) $defaults['item'][$key] = 'selected'; else $defaults['item'][$choice] = ''; } foreach($sizes as $key => $size){ if(isset($_POST['size']) && ($_POST['size'] == $key)) $defaults['size'][$key] = 'selected'; else $defaults['size'][$size] = ''; } // print form print "<form action='{$_SERVER['SCRIPT_NAME']}' method='post'>"; print "<div>"; print "<select name='item'>"; foreach($choices as $key => $choice){ print "<option value='{$key}' {$defaults['item'][$key]}>{$choice}</option>"; } print "</select>"; showError('item', $errors); print "</div>"; print "<div>"; print "<select name='size'>"; foreach($sizes as $key => $size){ print "<option value='{$key}' {$defaults['size'][$key]}>{$size}</option>"; } print "</select>"; showError('size', $errors); print "</div>"; print "<input type='submit'/>"; print "</form>"; } // display error function showError($type, $errors){ if(isset($errors[$type])) print "<b>{$errors[$type]}</b>"; } // $errors = array();//empty array function Validate() { if(!(isset($_POST['size']) && (array_key_exists($_POST['size'], $choices)) && $_POST['size'] != 0)) { $errors[size] = "Selet Size"; } if(!(isset($_POST['item']) && (array_key_exists($_POST['item'], $choices)) && $_POST['item'] != 0)) { $errors[item] = "Select Item"; } return $errors; } // ?> Thanks for the help! Learning as I go here.
  7. Thanks for the reply. Makes perfect sense. How would I make an errors array and then return it at the end? I know how to make arrays with just data, but how do I do that based on a condition?
  8. I am working on a script for a simple form with only 2 options that are dropdowns. I need to validate these two options that there is a selection made. I have gotten the first one to validate, but I cannot get the second one to validate. Can anyone steer me in the right direciton why only one is working? I get no errors in the script, so I assume I am just missing something. <?php // options for drop-down menu $choices = array('-- Choose Your Item','Anniversary Jacket', 'Anniversary T-Shirt'); $sizes = array('-- Choose Your Size','L', 'XL'); if($_SERVER['REQUEST_METHOD'] == 'GET'){ // display form when GET showForm(array()); } else{ // process form if POST $errors = validateForm(); if(count($errors)) showForm($errors); // if errors show again else print 'Form submitted succesfully!'; // no errors } // function generating form function showForm($errors){ global $choices,$sizes; // set defaults $defaults = array(); foreach($choices as $key => $choice){ if(isset($_POST['item']) && ($_POST['item'] == $key)) $defaults['item'][$key] = 'selected'; else $defaults['item'][$choice] = ''; } foreach($sizes as $key => $size){ if(isset($_POST['size']) && ($_POST['size'] == $key)) $defaults['size'][$key] = 'selected'; else $defaults['size'][$size] = ''; } // print form print "<form action='{$_SERVER['SCRIPT_NAME']}' method='post'>"; print "<div>"; print "<select name='item'>"; foreach($choices as $key => $choice){ print "<option value='{$key}' {$defaults['item'][$key]}>{$choice}</option>"; } print "</select>"; showError('item', $errors); print "</div>"; print "<div>"; print "<select name='size'>"; foreach($sizes as $key => $size){ print "<option value='{$key}' {$defaults['size'][$key]}>{$size}</option>"; } print "</select>"; showError('size', $errors); print "</div>"; print "<input type='submit'/>"; print "</form>"; } // display error function showError($type, $errors){ if(isset($errors[$type])) print "<b>{$errors[$type]}</b>"; } // validate data function validateForm(){ global $choices,$sizes; // start validation and store errors $error = array(); // validate drop-down if(!(isset($_POST['item']) && (array_key_exists($_POST['item'], $choices)) && $_POST['item'] != 0)) $errors['item'] = 'Select Item'; return $errors; // validate drop-down if(!(isset($_POST['size']) && (array_key_exists($_POST['size'], $choices)) && $_POST['size'] != 0)) $errors['size'] = 'Select Size'; return $errors; } ?>
  9. Any help on why this would cause an implode error? Did I separate them wrong?
  10. Here is what I am trying but it is giving me an implode error. <?php if(!empty($_POST["recip"])){ switch ($_POST["recip"]) { case 'sl': $q = "select `num` from `sprint` WHERE dept ='T_SUP' OR `dept` ='T_LEAD' OR `dept` ='M_LEAD' OR `dept` ='T_MGR' OR `dept` ='T_VP' OR `dept` ='M_MGR'"; break; case 'mgt': $q = "select `num` from `sprint` WHERE dept ='T_SUP' OR `dept` ='S_SUP' OR `dept` ='O_MG' OR `dept` ='T_MGR' OR `dept` ='S_VP' OR `dept` ='Q_SUP' OR `dept` ='S_MGR' OR `dept` ='T_VP' OR `dept` ='M_MGR'"; break; case 'sunday': $q = "select `num` from `sprint` WHERE id ='7708' OR `id` ='7743' OR `id` ='7426' OR `id` ='7479' OR `id` ='7203' OR `id` ='7231' OR `id` ='7271' OR `id` ='7221'"; break; case 'sil': $q = "select `num` from sprint WHERE `sup` ='Silvio'"; } if (get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } $_POST = array_map('stripslashes_deep', $_POST); } $ret = mysql_query($q); $emails = array(); while ($row = mysql_fetch_assoc($ret)) { $emails[] = $row['num'].'@messaging.sprintpcs.com'; } array_chunk($emails, 50); if ($emails) { foreach($emails as $mail) { $ToEmail = implode(', ', $mail); $EmailSubject = $_POST["subject"]."\r\n"; $mailheader = "From: ".$_POST["email"]."\r\n"; $MESSAGE_BODY = ($_POST["message"]); // $MESSAGE_BODY .= ($_POST["auth"]); mail($ToEmail,$EmailSubject, $MESSAGE_BODY,$mailheader) or die ("Failure"); } } $num_rows = mysql_num_rows($ret); ?>
  11. Hey all I have this code: $ret = mysql_query($q); $emails = array(); while ($row = mysql_fetch_assoc($ret)) { $emails[] = $row['num'].'@messaging.sprintpcs.com'; } if ($emails) { $ToEmail = implode(', ', $emails); $EmailSubject = $_POST["subject"]."\r\n"; $mailheader = "From: ".$_POST["email"]."\r\n"; $MESSAGE_BODY = ($_POST["message"]); // $MESSAGE_BODY .= ($_POST["auth"]); mail($ToEmail,$EmailSubject, $MESSAGE_BODY,$mailheader) or die ("Failure"); } This has worked great for a custom script that emails users the content of a form. The issue is with the number of emails. It can get up to 200 or so and when it does the emails never come. We are assuming its hitting something on the server end or after it leaves. My next idea is to break this script up so it does it in batches instead of how it is now. Where would I start on this to do the exact same thing, but do it in batches of 50 if its more than that? Thanks for any insight and help.
  12. Dang. It is a Windows server does that matter? Very confusing.
  13. Currently I am using LIKE in a query to find people by name. But it seems that if I am looking for Tony and put ton it will not find it. I am using %ton% in the query. I MUST have a capital T if the name is in the database like that. Its a mysql database. How can I make it find it regardless of case sensitivity? Thanks!
  14. Hey all. I have a query that selects data from a datbase based on a criteria. Easy enough. But now I am growing and the amount displaying is too much. How can you, via php, have a queries result be displayed only so many at a time and auto create links that show the rest? Like if query returns 82 results, I want it to display 25 immediately and create 3 links at the bottom. The next link would show 26-50. The next 51-75. And the final 76-82. etc Example: $result = mysql_query("SELECT * FROM pay"); $num_rows = mysql_num_rows($result); while($row = mysql_fetch_array($result)) { echo $row['first_name']; echo $row['last_name']; echo $row['item_name']; echo $row['option_selection1']; echo $row['payment_date']; echo $row['stat']; } This is simple. But what happens when the results are 125? I want to limit it to displaying 25 at a time. Is the only way to manually create seperate pages and have each one show 1-25, then 26-50, etc? Or is there a way to have the script do it, itself? Any tutorials out there on this specifically? Hopefully I am making sense. Thanks!
  15. NETSYNC

    If or?

    How can I add an if statement with "or" ? I have this: if ($item=="1") $pic="images/item.png"; elseif ($item=="2") $pic="images/item2.png"; elseif ($item=="3") $pic="images/item3.png"; else $pic=""; How do I add an "or" case to the item? Like if ($item=="1 OR 11 OR 121") $pic="images/item.png"; elseif ($item=="2" OR 22 or 233) $pic="images/item2.png"; elseif ($item=="3 OR 35 OR 37") $pic="images/item3.png"; else $pic=""; Is this possible?
  16. Thanks very much. I appreciate taking the time to help AND to explain it.
  17. Thanks. But the only part I am trying to understand is, what determines WHERE it splits in 2? Is that what the " " is? Saying at the first SPACE?
  18. Thanks very much for the reply and help. Let me see if I understand this. $s = 'HH:MM:SS DD Mmm YY, YYYY PST'; We are defining a variable to the data I pulled $e = explode(' ',$s,2); Are we here opening the data from above and saying at the first _space_ break it into 2? $first_part = $e[0]; $secnd_part = $e[1]; Here we are creating a variable for the first part and the second part from above. first part would be HH:MM:SS. Second part is the rest? I think I understand it. Let me know if I am on the right track. I am learning. =)
  19. Hello all. I am finishing up a paypal IPN php script and was wondering how I can take some data and cut some of it off before I enter it into the mysql database? Heres what I have. $payment_date = HH:MM:SS DD Mmm YY, YYYY PST This comes from paypal. I want to in my code take that and automatically cut off the HH:MM:SS part. So my question is, how can I take a known piece of data and automatically trim the first 9 spots off of it? Something like: $payment_date = HH:MM:SS DD Mmm YY, YYYY PST Minus 1 thru 9 of $payment_date = $result $payment_date2 = $result Any help? Thanks!
  20. Oh ok so if I add an if statement before the query I can check for null and error, else run query. Thanks!
  21. Hey all I am almost done with my custom script and need one thing. Here is my code: $con = mysql_connect(DB", "XXXX", "XXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("XXXXXXX", $con); $name = $_POST['name']; $result = mysql_query("SELECT * FROM track WHERE name LIKE '%$name%'"); $num_rows = mysql_num_rows($result); while($row = mysql_fetch_array($result)) { echo $row['id']; echo $row['name']; echo $row['phone']; } ?> The above works good but currently if the user submits the form empty it still pulls all the names in the database due to the "like" use. I need to use like in this way because I need to be able to search partial names. How can I make it stay the exact same but ignore the query results if its NULL or empty? Thanks!
×
×
  • 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.