Jump to content

futrose

Members
  • Posts

    64
  • Joined

  • Last visited

    Never

Everything posted by futrose

  1. ahhhh... nice. Changing to str_replace took care of the the "[]" problem. Thanks a lot.
  2. thanks, I went with str_replace and it got rid of the errors. I now have this line $body=preg_replace("[date]",$showDateS,$body); on the output it is placing the "[" and "]" around my date. How do I make that go away?
  3. I have this bit of code that was originally ereg but needed changed to preg_match. I'm just not sure where to put the delimiter in these two lines. $ee[$i]=preg_match('-','/',$ee[$i]); and $es[$N]=preg_match('-','/',$es[$N]); thanks.
  4. I have these links where the value of $id is pulled from my database, <a href='javascript: window.document.Vids<?php echo $id; ?>.submit();'>Watch</a> and I would like it to open the video in a separate window. Any idea how to make that happen? Thanks
  5. thanks jcbones. Worked perfectly. I thought i might be something like that but wasn't sure how to implement it.
  6. I have three tables I am using to loop through and get results, ELDERS, ELDERCATEGORY, ELDERCAT. Elders has all the profile of the staff. Eldercat is just a list of staff positions. Eldercategory link the two together by their id's. Here is the whole code, I'll post the snippet in question below. <?php ini_set("display_errors", "1"); error_reporting(-1); $result = mysqli_query($link, 'SELECT * From eldercat'); if (!$result) { $error = 'Error getting elder categories: ' . mysqli_error($link); include 'error.php'; exit(); } while ($row = mysqli_fetch_array($result)){ $eldercat[] = array('id' => $row['id'], 'category' => $row['category']); } foreach ($eldercat as $cat): echo "<div style='font-weight:bold; clear:both'>"; echo $cat['category']; echo "</div>"; $result2 = mysqli_query($link, "Select * from elders inner join eldercategory on elders.id = elderid inner join eldercat on eldercatid = eldercat.id where eldercatid = " . $cat['id'] ." order by orderby"); if (!$result2) { $error = 'Error getting elders in the category: ' . mysqli_error($link); include 'error.php'; exit(); } while ($row2 = mysqli_fetch_array($result2)) { if (($row2['avail']) =='Y') { echo '<div class="smallelderblock">'; echo '<img src = "http://www.bbcpa.org/images/' . ($row2['image']) . '" alt="' . ($row2['LastName']) . ' elders photo" class="elderimg" />'; echo $row2['position'] . '<br />'; echo "<a href='javascript: window.document.LastName" . $row2['id'] . ".submit();'>" . $row2['HFirst']; if (($row2['HFirst'] !="") && ($row2['WFirst'] !="")) { echo ' &amp '; } echo $row2['WFirst'] . " " . $row2['LastName'] . "</a>"; echo "<form name='LastName" . $row2['id'] . "'" . " " . "action='staff-details.php' method='post'>"; echo "<input value='" . $row2['id'] . "'" . "type='hidden' name='ElderDetails' />"; echo "</form>"; echo '</div>'; } } endforeach; ?> $result2 = mysqli_query($link, "Select * from elders inner join eldercategory on elders.id = elderid inner join eldercat on eldercatid = eldercat.id where eldercatid = " . $cat['id'] ." order by orderby"); I am getting the output that I want except for the $row2['id'] lines are displaying the id from the wrong table. I need the id from the elders table but I am getting the id from the eldercat table instead. Any ideas?
  7. I got it to work... thanks for your help guys. I appreciated the examples. I just had to tweak them a bit but all is good for now. Maybe one day I'll have answers to post instead of just questions.
  8. I think I may have been a little confusing. Let me explain better. I have 2 files, index.php and elders_modify.php Here is the code from index.php as I have it right now. $result = mysqli_query($link, "Select * from eldercategory where elderid = '$id'"); if (!$result) { $error = 'Error fetching elder details ' . mysqli_error($link); include '../../includes/error.php'; exit(); } while ($row = mysqli_fetch_array($result)) { if($id != $row['elderid']) { $selected = '0'; } else { $selected[] = array('eldercatid' => $row['eldercatid']); } } the $id is pulled when an admin clicks on a staff member to edit this code tells the elders_modify.php file which categories in the drop down menu to mark as "selected". The code works fine when a staff member has a category assigned to them already. If a staff member does not have a category assigned yet than $selected is empty because $eldercatid is empty. here is the code from elders_modify.php ... <td>Staff Category:</td><td><select name="eldercatid[]" multiple> <?php foreach ($eldercat as $ec): ?> <option value="<?php echo $ec['id']; ?>" <?php if ($action == 'elder_edit') { foreach ($selected as $s); if ($ec['id'] == $s['eldercatid']) { echo 'selected = "yes"'; } } echo '>'; echo $ec['category']; ?></option> <?php endforeach; ?> </select> all I need to do is give $selected a value to carry over from index.php to elder_modify.php when a staff member has no category assigned yet. For some reason my $selected = '0'; isn't recognized.
  9. can you give me an example...? I understand the logic behind your answer but I'm not sure what the code would be to do it.
  10. I have been trying to fix this code snippet because I need to do something different if my variable is empty. $result = mysqli_query($link, "Select eldercatid from eldercategory where elderid = '$id'"); if (!$result) { $error = 'Error fetching elder details ' . mysqli_error($link); include '../../includes/error.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $selected[] = array('eldercatid' => $row['eldercatid']); } here is the code being used on the page using the variable foreach ($selected as $s); if ($ec['id'] == $s['eldercatid']) { echo 'selected = "yes"'; } I need my $selected variable to be equal to anything if $row['eldercatid'] is blank or empty because on the next page I have a call to use $selected but I am getting an error that says undefined variable: selected. I have tried all kinds of lines using if empty and if ($row['eldercatid'] != '') among other stuff but haven't had any luck. I know this probably pretty basic stuff, I just don't know it well enough yet. Thanks for your help.
  11. Got it all sorted out. Code is working as it should. Thanks for your help mjdamato. Had to adjust the line of code to $result = mysqli_query($link, $deleteSql) or die(mysqli_error());
  12. Thanks for the help with this code. I'm pretty close to getting it. I had a question about this line... I think I am missing a '(' somewhere. Is that right? $result = mysql_query($insertSql) or die mysql_error()); also I am using mysqli so I changed the line to this $result = mysqli_query($insertSql) or die mysqli_error()); but I'm still not sure about the '(' issue.
  13. I took a look at the values that were created in the eldercategory table. The INSERT code that you suggested only creates 1 row with an elderid and an eldercatid. What I need it to do is if multiple options are selected create a row for each of the options selected, in the eldercategory table, set the elderid = the new elder id, and the eldercatid to one of the selected categories. So if a staff member is selected to be part of three categories (ie Pastor, Elder, Board member) then there should be 3 rows created like so elderid eldercatid 28 2 28 3 28 7 anyone know how to do that?
  14. Thanks mjdamato for that. Works great. Can you show me what the UPDATE version would be for the same code? I did something like this but it didn't work. //Process each value in the array into a complete UPDATE value $values = array(); foreach($_POST['eldercatid'] as $eldercatid) { $eldercatid = intval($eldercatid); $values[] = "('$eldercatid', '$id')"; } //Create the SQL statemetn using implode on the values $implodearray = implode(', ', $values); $sql = ("Update eldercategory where elderid = $id set $implodearray");
  15. What I am trying to do is take the id's selected from a drop down list (which is populated from table ELDERCAT) and join them together with the id being edited/created from a second table ELDERS. I am doing this by creating a 3rd table ELDERCATEGORY where the eldercatid and eldersid fields are matched up making an elder related to a category. I don't know how to get the information out of the array I have created to insert into the ELDERCATEGORY table where the id is equal to the elder being created/edited. Here is the code I have so far. *note: I can make it work when only one option is selected from the dropdown (a string) list but not when multiple options are selected (as an array). index.php - code snippet to ADD new elder ELDERS table, code to edit is similar so if I can get this I can fix the edit section on my own include '../../includes/db.inc.php'; //other variables ... $eldercatid = mysqli_real_escape_string($link, $_POST['eldercatid']); //I know mysqli_real_escape_string wont work on array but not sure how to fix that $sql = "Insert into elders set image = '$uploadname', LastName = '$LastName', HFirst = '$HFirst', WFirst = '$WFirst', position= '$position', email = '$email', email2 = '$email2', bio = '$bio', avail = '$avail', orderby = '$orderby'"; if (!mysqli_query($link, $sql)) { $error = 'Database error storing elder download!'. mysqli_error($link); include '../../includes/error.php'; exit(); } $result = mysqli_query($link, 'Select id from elders order by id DESC LIMIT 1'); //selects id from elder just created in ELDERS table if (!$result) { $error = 'Error fetching elder id: ' . mysqli_error($link); include '../../includes/error.php'; exit(); } while($row = mysqli_fetch_array($result)) { $id = ($row['id']); } $sql = "Insert into eldercategory set eldercatid = '$eldercatid', elderid = '$id'"; if (!mysqli_query($link, $sql)) { $error = 'Database error storing elder and category id!'. mysqli_error($link); include '../../includes/error.php'; exit(); } elders_modify.php - page with drop down list passes variables back to index.php ... <form action="?<?php htmlout($action); ?>" method="post" enctype="multipart/form-data"> <table cellspacing="5" cellpadding="1" border="0"> <tr> <td>Staff Category:</td><td><select name="eldercatid[]" multiple> <?php foreach ($eldercat as $ec): ?> <option value="<?php echo $ec['id'] ; ?>" <?php if ($action == 'elder_edit') { foreach ($selected as $s): if ($ec['id'] == $s['eldercatid']) { echo 'selected = "yes"'; } endforeach; } echo '>'; echo $ec['category']; ?></option> <?php endforeach; ?> </select> </td> </tr> ... Thanks for any help.
  16. Here is the set up. I have 3 tables elders with id/elder fields (and other fields but not important for question), eldercat with id/category fields, and eldercategory with elderid/eldercatid fields. The id's from the elders and eldercat tables are joined/associated in the eldercategory table. Ok, so this is what I am trying to do. I have a drop down list populated from my eldercat table at the top of my form showing available elder categories. The form is used to add new staff/elders members to the churches database. I am able to add an elder to the database and have them associated with 1 category. I'm not sure how to set it up so that if multiple categories are selected it will add the staff member id to the eldercategory table and associate it with both staff categories selected. Here is the code snippets. index.php include '../../includes/db.inc.php'; $uploadname = mysqli_real_escape_string($link, $_FILES["file"]["name"]); $LastName = mysqli_real_escape_string($link, $_POST['LastName']); $HFirst = mysqli_real_escape_string($link, $_POST['HFirst']); $WFirst = mysqli_real_escape_string($link, $_POST['WFirst']); $position = mysqli_real_escape_string($link, $_POST['position']); $email = mysqli_real_escape_string($link, $_POST['email']); $email2 = mysqli_real_escape_string($link, $_POST['email2']); $bio = mysqli_real_escape_string($link, $_POST['bio']); $avail = mysqli_real_escape_string($link, $_POST['available']); $orderby = mysqli_real_escape_string($link, $_POST['orderby']); $eldercatid = mysqli_real_escape_string($link, $_POST['eldercatid']); $sql = "Insert into elders set image = '$uploadname', LastName = '$LastName', HFirst = '$HFirst', WFirst = '$WFirst', position= '$position', email = '$email', email2 = '$email2', bio = '$bio', avail = '$avail', orderby = '$orderby'"; if (!mysqli_query($link, $sql)) { $error = 'Database error storing elder download!'. mysqli_error($link); include '../../includes/error.php'; exit(); } $result = mysqli_query($link, 'Select id from elders order by id DESC LIMIT 1'); if (!$result) { $error = 'Error fetching elder id: ' . mysqli_error($link); include '../../includes/error.php'; exit(); } while($row = mysqli_fetch_array($result)) { $id = ($row['id']); } $sql = "Insert into eldercategory set eldercatid = '$eldercatid', elderid = '$id'"; if (!mysqli_query($link, $sql)) { $error = 'Database error storing elder and category id!'. mysqli_error($link); include '../../includes/error.php'; exit(); } header('Location: .'); exit(); } elders_modify.php <form action="?<?php htmlout($action); ?>" method="post" enctype="multipart/form-data"> <table cellspacing="5" cellpadding="1" border="0"> <tr> <td>Staff Category:</td><td><select name="eldercatid" multiple> <?php foreach ($eldercat as $ec): ?> <option value="<?php echo $ec['id']; ?>"><?php echo $ec['category']; ?></option> <?php endforeach; ?> </select></td> </tr> <tr> <td>Husband Name:</td><td> <input type="text" name="HFirst" id="HFirst" value="<?php htmlout($HFirst); ?>" size="30" /></td> </tr> <tr> <td>Wife Name:</td><td> <input type="text" name="WFirst" id="WFirst" value="<?php htmlout($WFirst); ?>" size="30" /></td> </tr> <tr> <td>Last Name:</td><td> <input type="text" name="LastName" id="LastName" value="<?php htmlout($LastName); ?>" size="30" /></td> </tr> <tr> <td>Active:</td><td> <select name ="available"> <option value="Y">Yes</option> <option value="N">No</option> </select> </td> </tr> <tr> <td>Order By:</td><td> <input type="text" name="orderby" id="orderby" value="<?php htmlout($orderby); ?>" size="2" /></td> </tr> <tr> <td>Position: </td><td><input type="text" name="position" id="position" value="<?php htmlout($position); ?>" size="30" /> <br /> </td> </tr> <tr> <td>Email: </td><td><input type="text" name="email" id="email" value="<?php htmlout($email); ?>" size="20" /> <br /> </td> </tr> <tr> <td>Email2: </td><td><input type="text" name="email2" id="email2" value="<?php htmlout($email2); ?>" size="20" /> <br /> </td> </tr> <tr> <td>Bio: </td><td><textarea name="bio" id="bio" rows="13" cols="70"><?php htmlout($bio); ?></textarea></td> </tr> <tr> <td>Select image to upload: </td> <td> <input type="file" id="file" name="file" value="<?php htmlout($image); ?>"/> </td> </tr> <tr> </td> <td> <input type="hidden" name="id" value="<?php htmlout($id); ?>" /> <input type="submit" name="<?php htmlout($button); ?>" value="<?php htmlout($button); ?>" /></td> </tr> </table> </form> any help would be appreciated.
  17. I am trying to pull some data from the database but I want the output to be the first row of data in a <div> then the second row of data in the next <div> Then I want the 3rd and 4rth rows each in their own <div> but be able to have <div> 3 and 4 clear the first two <div> Basically creating a table like layout with two columns. Here is what I have so far for the output. I'm not sure what code I need to make it work. $result = mysqli_query($link, 'SELECT * From elders order by orderby'); if (!$result) { $error = 'Error getting elders: ' . mysqli_error($link); include '/includes/error.php'; exit(); } while ($row = mysqli_fetch_array($result)) { if (($row['avail']) =='Y') { echo '<div style="clear:both">'; echo '<div class="elderblock">'; echo '<img src = "http://www.bbcpa.org/images/' . ($row['image']) . '" alt="' . ($row['LastName']) . ' elders photo" class="elderimg" />'; echo ($row['HFirst']) . " " . ($row['WFirst']) . " " . ($row['LastName']) . '<br />'; echo ($row['position']) . '<br />'; echo ($row['email']) . '<br />'; echo ($row['email2']) . '<br />'; echo '<div style="clear:both">'; echo '<span class="elderbio">' . ($row['bio']) . '</span>'; echo '</div>'; echo '</div>'; echo '<div class="elderblock">'; echo '<img src = "http://www.bbcpa.org/images/' . ($row['image']) . '" alt="' . ($row['LastName']) . ' elders photo" class="elderimg" />'; echo ($row['HFirst']) . " " . ($row['WFirst']) . " " . ($row['LastName']) . '<br />'; echo ($row['position']) . '<br />'; echo ($row['email']) . '<br />'; echo ($row['email2']) . '<br />'; echo '<div style="clear:both">'; echo '<span class="elderbio">' . ($row['bio']) . '</span>'; echo '</div>'; echo '</div>'; echo '</div>'; } } The class=elderblock sets the width of the div and floats it left. I get the layout to look correct but it is repeating the 1st row from the database 2 times. So the same data is output side by side then the next row has the next line from the database 2x and so on. I'm not sure how to make it pull only the info 1 time then move to the next row in the database and placing the info in the next div. I hope this makes sense.
  18. Can someone tell me why this gives me undefined variables? The $id variable is showing up fine in this bit of code. When I click the link it is supposed to pull the data from the database related to the $id. <a href='javascript: window.document.Vids<?php echo $id; ?>.submit();'>Watch</a> <form name="Vids<?php echo $id; ?>" action="<?php echo $PHP_SELF; ?>" method="post"> <input value="<?php echo $id; ?>" type="hidden" name="Vids" /> </form> here is the code which is supposed to display the info. if (isset($_POST['Vids'])) { $result = mysqli_query($link, "SELECT * FROM vidaud where id =".$_POST['Vids']); echo $id; the error i get is I'm just not sure why the $id variable isn't being posted by my form and read by the code. Thanks.
  19. thanks, i'll do that.
  20. Sorry if this is the wrong spot for this topic, since I don't know how it is implemented into a site I didn't know where to put it. I have a site where the backend is going to be used by people who have no clue about HTML/PHP or any other coding language. I have a "description" field for each of the pages on the site but I need to allow some formatting in that field in case they need to create a new paragraph header, something bold, text size, or something like that. How do I add a WYSISYG option so they can do that without knowing html tags? I guess similar to the buttons used on this forum to add formatting. Thanks.
  21. I tried retyping the line... no luck. For some reason I decided to try restarting apache which solved the problem. Thanks for trying to help out.
  22. Can anyone see what might be wrong with this? I am getting this error. here is the file <?php //include $_SERVER['DOCUMENT_ROOT'] . '/dbinfo.inc.php'; //$link = mysqli_connect($host, $user, $password); $link = mysqli_connect('ipaddress', 'root', '****'); if (!$link) { $error = 'Unable to connect to the database server.'; include 'includes/error.php'; exit(); } if (!mysqli_set_charset($link, 'utf8')) { $error = 'Unable to set database connection encoding.'; include 'includes/error.php'; exit(); } if (!mysqli_select_db($link, 'biblebaptist')) { $error = 'Unable to locate the database.'; include 'includes/error.php'; exit(); } ?> it was working fine before, now it isn't. I have the php.ini file set to mysqli by removing the ; from the line. I'm not sure what else to check. This is on my local machine (testing server) if that matters.
  23. I have no idea how you saw that but thank you. That took care of that issue. Quick question. Is there any reason that the 2 lines of code you gave me to use ini_set("display_errors", "1"); error_reporting(-1); are making my pages not load correctly on my localhost testing server? Does it just have to do with the ini and config settings? I can remove the lines from the files on my local computer, it isn't a big deal. I'm just getting different errors live than I am on the local machine. Is that a problem you think? For example on my local machine I get Fatal error: Call to undefined function mysqli_connect() in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\includes\db.inc.php on line 2 but on the live server I don't get that error.
×
×
  • 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.