Jump to content

ginerjm

Members
  • Posts

    6,906
  • Joined

  • Last visited

  • Days Won

    99

Everything posted by ginerjm

  1. Since the manual says you can use a string as the pattern you certainly could use a file to provide that string. Easy-peasy. But - you want to do a 'search' for hundreds of items? That could take some time don't you think? Are you sure you really need to do this thing?
  2. Run your query (I used pdo) and then do the following: $row_size = 3; $cnt = 0; echo "<table><tr>"; while($row = $pdo->fetch()) { if ($cnt == $row_size) { echo "</tr><tr>"; $cnt = 0; } echo "<td>{$row['item']}</td>"; $cnt++; } echo "</tr></table>";
  3. What do you think that explode is doing for you? Did you echo out your user and uid values after the explode Here is what I get: $data = "foo:home,food,brand:tulasi"; list($user, $uid) = explode(":", $data); echo "user is $user and uid is $uid"; exit();
  4. FYI - the code above is missing a couple of semicolons Note how the code was written without leaving PHP mode and thus avoids the messy way of having to code your p tag so clumsily. AND - if this is not the sole contents of your php script then leave out the ?> tag. It is not required nor is it needed to end a script. Entering and leaving php mode is not a practical way of coding a php script. Sure - you may have some block of JS code so you can do it but when all you are doing is running php logic and then assembling php results with html code use the echo and double quotes and avoid the in-and-out style of coding php results. Just my $.02
  5. I think you misunderstood my question. What makes you think that they are hitting your site at all? Some of your logs maintained by your domain? Do you have a few domain names of these sites that are in your logs that are clearly xxx sites?
  6. So you are telling us that you can see in some log of your site's activity that porn sites are trying to see your pages? That does seem odd... It is usually the other way around.
  7. Having not used the empty function much (ever?), I re-read the manual and like what I see there. And found out why the OP reported a problem with it when the input was a '0'.
  8. Here's is how you could handle the problems that people are mentioning. Just a quick "how I would do it": $errmsg = ''; if ($_GET['id'] == '') $errmsg .= 'Missing id value<br>'; else { $q = "SELECT * FROM peminjaman WHERE id_peminjaman='" . $_GET['id'] . "'"; if (!$get = mysqli_query($con, $q)) $errmsg .= "Query failed to run<br>Query was:<br>$q<br>"; } if ($errmsg <> '') { // show the errmsg and let the user know he has // a problem and stop this script } // continue on with query results $fetch = mysqli_fetch_array($get); $nama_pegawai = $fetch['nama_pegawai']; $tanggal_pinjam = $fetch['tanggal_pinjam']; $tanggal_kembali = $fetch['tanggal_kembali']; // no need to do the above 'assignments' when you can simply // use the values from the fetched array You really should check the results of your query since any error in your statement or possibly with your db server will cause issues.
  9. Actually I should have said - "create the SAME single entry in an array". Which kind of makes it a needless function.
  10. Can I ask - why do you need this function? All it does is create a single entry in an array and never anything else. What's the point? You could simply place this code in your mainline code and not have to create a function.
  11. It's an .html file is the problem
  12. I find it funny when I see people using sprintf/printf to display something that a simple echo accomplishes. I NEVER use those 2 functions. Don't understand.
  13. $root is the path to your domain's root. As in: $root = $_SERVER['DOCUMENT_ROOT'] . "/"; Sorry - didn't see that was in there. And don't "put tags around" the code. All one ever needs is the <?php tag. As already mentioned the ?> tag is not needed. And don't forget to add the lines that enable error checking to this as I noted.
  14. Don't you want to use two dots to reference the styles folder if you are already down in the includes folder? Personally I store my 'project' stuff in a specific folder for that project and don't have to worry about all that. If I really needed to separate project-specific files into their own sub folders then that is exactly what I would have - sub-folders under the project-specific folder rather than folders in a parallel structure. And if I have certain files that are global to much of my work (such as a db connection file) those I store in an upper level folder (outside of the web-accessible tree) where all my projects can reference them with a root-level path conjoined to that folder.
  15. I use a little stub of a script to debug those errors that prevent a script from running. if (isset($_GET['call'])) { // test the script named as the 'call' arg in the url $call = $_GET['call']; require $root . $call; } else { echo "Must supply a call= argument for the script to be tested"; echo "root is $root<br>"; } //******************************** exit(); Be sure to add the error setting lines at the top of this and then save it. I call mine 'redirect.php' and add a ?call=scriptname in the command line when I use it. Note that it won't run if you already have get parms in your problem script so simply provide only the script name.
  16. Did a quick (Really quick!) lookup and found this. You have the wrong syntax so apparently you did not do your homework. INSERT INTO destination_table_name(column_1, column_2) SELECT column_1,column_2 FROM source_table WHERE condition;
  17. Try this to see if there are some issues: $q = "INSERT INTO a SELECT * FROM b WHERE id='" . $_POST["id"] . "'"; if (mysqli_query($conn, $q)) echo "Insert query successful"; else { echo "Insert query failed. Query is<br>$q<br>"; exit(); } $q = "DELETE FROM b WHERE id='" . $_POST["id"] . "'"; if (mysqli_query($conn, $q)) echo "Delete query successful"; else { echo "Delete query failed. Query is<br>$q<br>"; exit(); } echo json_encode(true); // Not sure what this is. If you get a failure try adding the mysqli error reporting function to it as already suggested. This will give you at least some indication. Suggestion - IMHO it is good practice to NOT bury a query statement inside of another function as you are doing. By assigning it to a variable it makes it easy to echo out your query string should you want to analyze it during any debugging you may need to do as in this case perhaps.
  18. Should of noticed your use of "C:" and realized that you are running your own server. So I think you are getting good advice to getting your .ini file setup. I'll leave this topic to the pros.
  19. Are you running your own server(s) for this? Or do you have a host managing your PHP install? If the latter then you may already have pdo installed and using it is simply a matter of looking up PDO in the reference section and doing a little light reading and viewing the many samples. PDO is really the simple way of querying a db. $q = "select ........ where fld1=:arg1 and fld2=:arg2"; $qst = $pdo->prepare($q); $parms = array( 'arg1'=>"$myvalue1", 'arg2'=>"$myothervalue" ); if (!$qst->execute($parms)) { (handle an error condition for your user) } while($row = $qst->fetch(PDO::FETCH_ASSOC)) [ (handle a row of your results until all processed) } (move onto other logic)
  20. And have you written this "mysqli" class and included it in your script?
  21. HTH.. Stay in touch!
  22. Follow-up If the class you posted is EXACTLY the same as what you are executing I think you either botched the html that references it or you messed up the css portion of your script. I pasted it into my script (that I gave you) and the submit tags show up nicely formatted.
  23. I hope you meant to say "scripts" and not "forms". Show us where you assign this class in this script. Perhaps the entire <head> and <form> portions of the file even. And as a habit I do think that pretty much all code you write will go into a filename ending in php. Only if it has no php at all would you use a JS or HTML extension.
  24. Ok - it appears that you are really new to this since it takes you a long time to read and respond to my posts. That's ok but I thought I would give you a full picture tutorial that might help you see how it could be done. My coding style may have its critics but it is not totally 'bad' and does work well for what you seem to desire to accomplish. Study it please (more than the posts you have already glossed over) and learn from it. (clicking on the <> icon Now!) <?php /* * form_sel.php - allow the user to select which * page to display next * */ // turn on/off error reporting error_reporting(E_ALL); ini_set('display_errors', '1'); // 1 = on; 0 = off; $errmsg = ''; // // See if the form has been submitted yet // if ($_SERVER['REQUEST_METHOD'] == 'POST') { $formname = ''; if (isset($_POST['form_sel'])) { if ($_POST['form_sel'] == '1') $formname = 'form1.php'; if ($_POST['form_sel'] == '2') $formname = 'form2.php'; if ($formname <> '') { // The next line will jump to the selected page // uncomment when ready // header("Location: $formname"); // for testing this out // remove next 2 lines when done testing $errmsg = "You have chosen to see page $formname"; DisplayPage(); exit(); } else $errmsg = 'You must select a form to be shown'; } else $errmsg = 'You must select a form to be shown'; DisplayPage(); exit(); } else { // // first time for this form // DisplayPage(); exit(); } //**************** //**************** //**************** function DisplayPage() { // define vars that have been created outside of functions global $errmsg; // output the header portion of the html page echo " <!DOCTYPE html> <html> <head> <title>Choose a Form</title> <!-- ****** CSS GOES HERE ******* --> <!-- ****** CSS GOES HERE ******* --> <!-- ****** CSS GOES HERE ******* --> <style type='text/css'> #err_box { position:relative; float:left; margin:1% 3%; width:40%; border:2px solid black; padding:10px; color:red; } #form_box { position:relative; float:left; clear:left; margin:1% 3%; width:40%; border:2px solid blue; padding:10px; } </style> </head> <body> "; // check if there is an error message if ($errmsg) echo " <div id='err_box'> $errmsg </div> "; // // now begin the meat of the page // echo " <div id='form_box'> <form method='POST' action=''> Choose which form you want to see by clicking on a button. <br><br> <label>Show Form #1 <input type='radio' name='form_sel' value='1'> </label> &nbsp;&nbsp;&nbsp; <label>Show Form #2 <input type='radio' name='form_sel' value='2'> </label> <br><br> <center> <input type='submit' name='btn' value='Show Form'> &nbsp;&nbsp;&nbsp; <input type='submit' name='btn' value='Return to Caller'> </center> </form> </div> "; // // now output the tail end of the html page // echo " </body> </html> "; return; // return to the mainline portion of this script } You can take this entire block of code and save it as a .php file and upload it to your server and call it to see how it works. Call it a xmas present.
×
×
  • 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.