Jump to content

chaking

Members
  • Posts

    68
  • Joined

  • Last visited

Everything posted by chaking

  1. I'm using tinymce text editor to populate a mysql database and then calling the content in a new page with an echo statement. The problem I'm running into is trying to store php code in mysql and have it execute after it's called within an echo statement like so... $content = "<p>Hello<?php echo "John" ?></p>"; <?php echo "$content" ?> Currently this only prints out "Hello" - Any ideas on how to proceed? Thanks for your time -
  2. Yeah good point - It's alright though because this is not on a public server and I know who will be using it (so no worries about javascript) - Thanks
  3. That would work too - Thanks I did find the javascript solution though. Why should I not use javascript? Because of usability reasons only? (i.e. some people might not have js enabled?) here it is: Throw this in the file: <script type="text/javascript"> function nav() { var w = document.bldg_form.bldg_list.selectedIndex; var url_add = document.bldg_form.bldg_list.options[w].value; window.location.href = url_add; } </script> Then the function: <?php function drop_down(){ include "cxn.php"; $cxn = mysqli_connect($host, $user, $passwd, $dbname) or die(mysqli_error()); $list_one = "SELECT facility_code FROM facilities ORDER BY facility_code"; $list = mysqli_query($cxn, $list_one) or print(mysqli_error()); while($row_list = mysqli_fetch_assoc($list)){ echo "<option name=\"bldg\" value=\"../../index2.php?bldg=$row_list[facility_code]\">$row_list[facility_code]</option>\n"; } echo "</select>\n\n"; } ?> Then the form: <form name="bldg_form"> <p>Jump To Facility:<br> <select name="bldg_list" onChange="nav()"> <option value="NONE">Select Facility</option> <?php drop_down(); ?></p> </select> </form> This takes the value you select and directs you to it immediately -
  4. I'm trying to create a drop down menu from a table that when submitted will put the value on the end of a url and then go to that url. So, the drop down menu would have values like = pac,blr,hyd etc.. Those values need to be put on the end of ex: http:/xxx.com/index2.php?bldg="VALUE" I have built the query to grab the values, and I have the values inserted into a drop down list, but I don't know how to go to a url like I described on submit? Any help would be appreciated - This is what I have so far: function drop_down(){ include "cxn.php"; $cxn = mysqli_connect($host, $user, $passwd, $dbname) or die(mysqli_error()); $list_one = "SELECT facility_code FROM facilities ORDER BY facility_code"; $list = mysqli_query($cxn, $list_one) or print(mysqli_error()); while($row_list = mysqli_fetch_assoc($list)){ echo "<option name=\"bldg\" value=\"$row_list[facility_code]\">$row_list[facility_code]</option>\n"; } echo "</select>\n\n"; } And then the form: <p>Select Facility:<br> <form> <select name="bldg" > <option value="NONE">Select Facility</option> <?php drop_down(); ?></p> <input type="button" value="Submit"> </form> Thanks
  5. This is not a problem with the mysql statement, as I always get the right info stored in the dB... But when I go to display it, well that's the problem. And that can be a big problem because at times I call the column's value to put into a form's field so that the user can update the stored value. The problem is that it looks like the value is cut off whenever you put an apostrophe, and so if the user doesn't refill the form's value, then the wrong value gets updated in the dB. Here's what I'm doing: // Check that an email address was submitted if (empty($_POST['email'])) { echo "You need to input the email address! That's the thing that tells the data apart!!!"; } else { $em2 = trim($_POST['email']); } $fn2 = trim($_POST['firstname']); $ln2 = trim($_POST['lastname']); $ti2 = trim($_POST['title']); $op2 = trim($_POST['officephone']); $cp2 = trim($_POST['cellphone']); $hp2 = trim($_POST['homephone']); $pa2 = trim($_POST['pager']); if (get_magic_quotes_gpc( )) { //guard against SQL injection $em2 = stripslashes($em2); $fn2 = stripslashes($fn2); $ln2 = stripslashes($ln2); $ti2 = stripslashes($ti2); $op2 = stripslashes($op2); $cp2 = stripslashes($cp2); $hp2 = stripslashes($hp2); $pa2 = stripslashes($pa2); } // have to filter the same values through to escape the strings $em2 = mysqli_real_escape_string($cxn,$em2); $fn2 = mysqli_real_escape_string($cxn,$fn2); $ln2 = mysqli_real_escape_string($cxn,$ln2); $ti2 = mysqli_real_escape_string($cxn,$ti2); $op2 = mysqli_real_escape_string($cxn,$op2); $cp2 = mysqli_real_escape_string($cxn,$cp2); $hp2 = mysqli_real_escape_string($cxn,$hp2); $pa2 = mysqli_real_escape_string($cxn,$pa2); Then I throw the values in a form: echo "<h3>Please Update the information needed here:</h3>"; echo "<form action='update2.php' method='post'>"; echo "First name: <input type='text' name='firstname2' value='$fn2' />"; echo "Last name: <input type='text' name='lastname2' value='$ln2' /><br><br>"; echo "Login/Email: <input type='text' name='email2' value='$em2' /> <br><br>"; echo "Title: <input type='text' name='title2' value='$ti2' /><br><br>"; echo "Office Phone: <input type='text' name='officephone2' value='$op2' /><br><br>"; echo "Cell Phone: <input type='text' name='cellphone2' value='$cp2' /><br><br>"; echo "Home Phone: <input type='text' name='homephone2' value='$hp2' /><br><br>"; echo "Pager: <input type='text' name='pager2' value='$pa2' /><br><br>"; echo "<input type='submit' name='UPDATE HERE' />"; echo "</form>"; So two questions - 1) How do I prevent the value in the dB from killing the line (properly escape it) 2) Am I going through magic quotes and mysqli_real_escape in the most efficient way? Thanks for your time EDIT: Split post into own topic. Don't post your problem in someone's (old) thread.
  6. I think this is a simple answer, but it seems too simple... maybe you know this already, maybe not. You should use something like notepad (if you use windows). Don't use wordpad. Use notepad, put all the code in there, go to 'save as' and select 'All Files' instead of .txt files. Then save the file as whatever.php (make sure you have selected "All Files"). That's the plain text editor they're talking about anyway.
  7. thanks phpsensei - I thought I might have to go that route.
  8. right, I understand how to include a file. My question is: Is there a way to only include variables from a file instead of all the code? Because when I include all of the code from that file, it shows the form I created in the included file on the new page. ---OOps, ok you updated your response while I was responding. So the isset function merely checks if the variable is already in use, correct? I don't have a problem with passing the variable's value, I have a problem with the rest of the code of the included file being displayed in my final result.
  9. I have a file I'm trying to: include "update.php"; update.php has some echo statements if it functions properly, but it also sets the values of a lot of variables. when I include update.php into update2.php, all the variables are passed very nicely, but it also prints out the rest of update.php (I have a form in update.php, so everytime I run update2.php it prints the update.php form AND the update2.php form)... Basically, is there a way to only include the variable values in update2.php instead of the whole file?
  10. Oh - well now I see what's wrong - This: ' Does NOT equal This: ` Never even realized that was that before
  11. Thank you thorpe - I seriously read roopurt's reply about 20 times. I'm sorry, but I don't understand php completely yet and I didn't understand his reply even after reading it thoroughly. Also, I didn't think the quotes were problematic because in Chris' response above, he gave me code with quotes around the field names and the code worked. But you were absolutely right, I took them out and now it functions as it is supposed to. So thank you, and I'm sorry I'm dumb - but hey, I'm dumb, what can I do? Also, in the 3 books I've read to try and learn php (O'Reilly, PHP For Dummies, and ... ahh I forget the name) they seem to put single quotes around the field names. This is why I get so confused, a quote here or there can throw it all off. I should learn how to read errors better, but they are confusing to me for now. Thanks anyway
  12. I'm sorry, I don't quite understand why the mysqli_error function would need a parameter? I thought it's function was merely to print the error message. So, instead of putting "die" before the mysqli_error (), I put "print" --- I read that this will let it continue and show what's going on... I now get this Warning: Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in.... And then it refers to this line of code: $array_facilitycode = mysqli_fetch_assoc($result_facilitycode); Does this mean I'm receiving a true or false statement instead of an array? Possibly because it's not matching my query with a valid result? So I guess my question would be: How am I formatting the request wrong? Because I know the values match the values in the db, so if it can match it in the db it must be my formatting. You mentioned that maybe the $cxn was the problem? But I use the exact same $cxn settings in another page and it works fine. I'm sorry to be a pain, but I can't help it =/
  13. I'll give 5 bucks to anyone that can help me =))
  14. Ah ok - I ran into another problem I'm not seeing an immediate answer to: I try to pass the variable through the url like this: test.php?bldg=A2Z Then I write this: [pre]<? $bldg_current = $_GET['bldg']; $cxn = mysqli_connect($host, $user, $passwd, $dbname) or die(mysqli_error()); $facilitycode = "SELECT * FROM 'facilities' WHERE 'facility_code' = '$bldg_current'"; $result_facilitycode = mysqli_query($cxn, $facilitycode) or die(mysqli_error()); $array_facilitycode = mysqli_fetch_assoc($result_facilitycode); if ( empty($array_facilitycode) ) { die("nothing found in the database"); } else { extract($array_facilitycode); } ?>[/pre] My error is coming up: Warning: mysqli_error() expects exactly 1 parameter, 0 given It's referring to this line: $result_facilitycode = mysqli_query($cxn, $facilitycode) or die(mysqli_error()); I guess the $facilitycode isn't passing any information? Any help would ver much be appreciated - thanks
  15. ah - thanks so much! It worked =) A n00b's joy is still joy
  16. Thanks for the quick reply chris - Unfortunately I'm getting the last die error - nothing found in the database... With this code: $cxn = mysqli_connect($host, $user, $passwd, $dbname) or die(mysqli_error()); $primary_email = "SELECT `email` FROM `responders` WHERE `id` = 'a2z_primary'"; $result_first = mysqli_query($cxn, $primary_email) or die(mysqli_error()); $array_first = mysqli_fetch_assoc($result_first); $primary_responder = "SELECT * FROM `contacts` WHERE `email` = '{$array_first['email']}'"; $result = mysqli_query($cxn, $primary_responder) or die(mysqli_error()); $array = mysqli_fetch_assoc($result); $row = mysqli_fetch_array($array); if ( empty($row) ) { die("nothing found in the database"); } else { extract($row); } I receive this error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, array given in E:\xampp-win32-1.6.5\xampp\htdocs\amazon\a2z.php on line 42 nothing found in the database
  17. Very new to writing php and I'm trying to work through the errors but I don't know what I'm doing wrong here: $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die('Couldnt connect to server'); $primary_email = 'SELECT email FROM responders WHERE (id="a2z_primary")'; $result_first = mysqli_query($cxn,$primary_email) or die('Couldn’t execute query'); $primary_responder = 'SELECT * FROM contacts WHERE (email="$result_first")'; $result = mysqli_query($cxn,$primary_responder) or die("Couldn't execute query2"); $row = mysqli_fetch_array($result); extract($row); The error I receive is: Warning: extract() [function.extract]: First argument should be an array in E:\xampp-win32-1.6.5\xampp\htdocs\amazon\a2z.php on line 42 It doesn't look like $row is actually holding any information - in fact if I make an if statement of: if ($row == "") {echo "nothing here"} and put it before the last line in the code, then I get "nothing here" - Any help would be very much appreciated, 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.