-
Posts
6,906 -
Joined
-
Last visited
-
Days Won
99
Everything posted by ginerjm
-
So many things I don't like but I took the time to re-format your code and add some comments to describe what I see wrong. <?php session_start(); // ALWAYS TURN ON ERROR CHECKING DURING DEVELOPMENT!!! error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); //*********************** if (isset($_SESSION['username'])) { if ($_SESSION['userlevel'] = '3') // ***BAD CONDITIONAL STATEMENT { $action = $_GET["action"]; ////DELETE A JOB //// if ($action == "delete") { $delid = $_GET['delid']; $query = "DELETE FROM jobs WHERE id=".$delid." LIMIT 1"; $sql = mysql_query($query); echo("Job succesfully deleted! [ <a href='add_jobs.php'>Back</a> ]"); } ////EDITING A JOB///// if ($action == "edit") { echo("<strong>Editing a Job:</strong>"); if ($_POST) // *** A POST AND A GET ARRAY IN THE SAME PROCESS ???? CONFUSING { $editid = $_GET['editid']; $job_title = htmlspecialchars($_POST['job_title']); $job_description = $_POST['job_description']; $job_type = $_POST['job_type']; $job_area = $_POST['job_area']; $hot = $_POST['hot']; $nurse_vet = $_POST['nurse_vet']; $query2 = "UPDATE jobs SET job_title='$job_title', job_description='$job_description', job_type='$job_type', job_area='$job_area', hot_job='$hot', nurse_vet='$nurse_vet' WHERE id='$editid' LIMIT 1"; $sql = mysql_query($query2) or die ('Error: '.mysql_error () . " IN $query2"); } else { $editid = $_GET['editid']; $s = "SELECT * FROM jobs WHERE id=".$editid." LIMIT 1"; $sql = mysql_query(htmlspecialchars($s)) or die ('Error: '.mysql_error () . " IN $s"); while ($row = mysql_fetch_array($sql)) { $id = $row['id']; $job_title = htmlspecialchars($row["job_title"]); $job_description = $row['job_description']; $job_type = $row['job_type']; $job_area = $row['job_area']; $hot = $row['hot']; $nurse_vet = $row['nurse_vet']; // *** YOU WILL HAVE BOTH A GET AND POST ELEMENT FOR 'EDITID' - MORE CONFUSING echo("<form name='add' method='post' action='?action=edit&editid=$id'>"); echo("<input type='hidden' name='editid' value='$editid'>"); } } } ////ADDING A JOB//// if ($action == "add") { $add = $_POST['add']; $job_title = $_POST['job_title']; $job_description = $_POST['job_description']; $job_type = $_POST['job_type']; $job_area = $_POST['job_area']; $hot = $_POST['hot']; $nurse_vet = $_POST['nurse_vet']; $id = mysql_insert_id(); // *** YOU DON'T GET THE INSERTED ID UNTIL *AFTER* THE INSERT OCCURS. $query = "INSERT INTO jobs (id, job_title, job_description, job_type, job_area, hot_job, nurse_vet) VALUES ('$id', '$job_title', '$job_description', '$job_type', '$job_area', '$hot', '$nurse_vet')"; $sql = htmlspecialchars(mysql_query($query)) or die (mysql_error()); // *** YOU'RE DOING THE HTML.. FUNCTION ON THE RESULTS OF THE QUERY, NOT ON THE STATEMENT, SILLY AS IT IS. } ///EMPTY //// if ($action == "") { $job_title=""; $job_description=""; } ?> <strong>Add A New Job!</strong> <br /> <br /> <form name='add' method='post' action='?action=add'> <input type='hidden' name='?action=add'> // *** WHAT IS THIS?? AN ELEMENT WITH A QUERY STRING FOR A NAME? Job Title:<br /> <input type='text' size='50' name='job_title' value='<?php echo htmlspecialchars($job_title); ?>'> <br /> Job Description: <br /> <textarea rows='10' cols='50' name='job_description'><?php echo $job_description; ?></textarea> <br /> Job Type: <br /> <select name='job_type'> <option>Permanent</option> <option>Locum or Contract</option> </SELECT><br /> Hot Job? <br /> Yes <input type='radio' name='hot' value='Yes'> No <input type='radio' name='hot' value='no' checked> <br /> Nurse or Vet job? <br /> Vet <input type='radio' name='nurse_vet' value='Vet'> Nurse <input type='radio' name='nurse_vet' value='Nurse' checked> <br /> Job Area: <br /> <select name='job_area'> <option>East Anglia</option> <option>All UK</option> <option>London / South East</option> <option>Midlands</option> <option>North West</option> <option>Northern Ireland</option> <option>Scotland</option> <option>South</option> <option>South West</option> <option>Southern Ireland</option> <option>Wales</option> <option>Yorkshire / North East</option> </SELECT> <br /> <input type='Submit'> // *** THIS SUBMIT HAS NO VALUE SO YOU CANNOT CHECK THAT THIS BUTTON WAS THE ONE CLICKED </div> <?php if($success == TRUE) // *** THIS VAR NOT SET IN THIS CODE { print("<strong>Success!</strong>"); } echo("<br>"); echo("</form>"); print("<strong>Existing Jobs:</strong>"); print("<br />"); print("<br />"); echo("<table class=main cellspacing=20 cellpadding=20>"); // *** CLASS='MAIN' if(isset($_GET["desc"])) { $query = "SELECT * FROM jobs WHERE 1=1 ORDER by ID DESC"; echo "<td><a href=add_jobs.php>Ref#:</td>"; echo "<td>Title:</td>"; echo "<td>Description:</td>"; echo "<td>Type:</td>"; echo "<td>Area:</td>"; echo "<td>Nurse/Vet:</td>"; echo "<td>Edit:</td>"; echo "<td>Delete:</td>"; echo "<td>Hot:</td>"; } else { // *** YOU DUPLICATE ALL THIS JUST TO SORT IN A DIFF ORDER???? SILLY $query = "SELECT * FROM jobs WHERE 1=1 ORDER by ID ASC"; echo "<td>"; echo "<a href=add_jobs.php?desc>Ref#:</td>"; echo "<td>Title:</td>"; echo "<td>Description:</td>"; echo "<td>Type:</td>"; echo "<td>Area:</td>"; echo "<td>Nurse/Vet:</td>"; echo "<td>Edit:</td>"; echo "<td>Delete:</td>"; echo "<td>Hot:</td>"; } ?> <form name='hotbox' action='hot_update.php' method='POST'> <?php $sql = mysql_query($query); while ($row = mysql_fetch_array($sql)) { $id = $row['id']; $job_title = htmlspecialchars($row['job_title']); $job_description = $row['job_description']; $job_type = $row['job_type']; $job_area = $row['job_area']; $nurse_vet = $row['nurse_vet']; $hotbox = $row['hot_job']; $position=18; $job_description2 = substr($job_description, 0, $position); // **** ALL THE FOLLOWING WOULD BE MUCH EASIER AS AN ECHO IN PHP MODE // ECHO "<td><strong>$id></strong></td>"; ?> <tr> <td><strong><?php echo $id; ?></strong></td> <td><strong><?php echo $job_title; ?></strong></td> <td><strong><?php echo $job_description2; ?>...</strong></td> <td><strong><?php echo $job_type; ?></strong></td> <td><strong><?php echo $job_area; ?></strong></td> <td><strong><?php echo $nurse_vet; ?></strong></td> <td><a href='add_jobs.php?action=edit&editid=<?php echo $id; ?>'>Edit</a></td> <td><a href='add_jobs.php?action=delete&delid=<?php echo $id; ?>'>Delete</a></td> <td><input name="ONOFF[]" type="checkbox" value="<?php echo $row['id']; ?>" <?php if($row['hot_job'] == 'YES') { echo "checked='checked' "; } ?>/></td> </tr> <?php } ?> </p> <input type='Submit' value='Update'> </form> </table> </div> <?php } else { echo'Stop hacking'; } } ?> You should really separate all that html code from the logic and just load var strings for your blocks of generated output and echo them out in the html section. Mixing the two makes it so hard to do things the easy way. My comments are all preceded with ***
-
You have the query results that come to you in array format. Why do you need to use extract() on that? Simply loop thru as you are doing and generate your html table rows. I fail to see a problem. while($row = mysqli_fetch_assoc($result)) { echo "<tr>"; foreach ($row as $k=>$v) echo "<td>$v</td>"; echo ("</tr>"; | will output all the elements from your query results in table rows.
-
Unable to unlink all images related to topic id
ginerjm replied to lovephp's topic in PHP Coding Help
Why not address what I suggested you do before asking more questions? -
Unable to unlink all images related to topic id
ginerjm replied to lovephp's topic in PHP Coding Help
Perhaps because you re-use the $result var inside your loop, thus obviating your check for num rows inside that same loop? -
Is there some reason you are making that setting in you htaccess file? It's not technically needed to do what your post title suggests. To set a session var you simply assign a value to it just as you would for any php variable. Of course, as Joel states, you have to first start the php 'session' with the session_start() command. Place this at the top of all of your scripts as a habit so that you always have access to it. <?php session_start(); .. .. .. $_SESSION['myvar'] = "this value"; .. .. That's all there is to it. There are other things that come into play when you are being extremely security conscious or need to do some kinds of deception, but for your defined needs this is all you need.
-
Good catch! Didn't even notice that...
-
I'm not comfortable with using a function in place of a variable (or object). How about simplifying your code and making the call and then using the returned variable in the bind call? You might also want to add some error checking code in your db_connect function to be sure it creates that object $db.
-
Good luck with your chosen learning curve. You're trying to read at a 12th grade level but have already stated you are a newcomer, aka, a first grader.
-
You appear to know nothing about php so why choose such a hard project? One usually chooses projects (as I said) that give you a chance to learn with less complex goals. Might I ask what you are searching for in these places you are using curl to extract?
-
Do you know why you chose such a tricky meaningless project to start to learn php and programming in general? Beginners usually start with easier tasks.
-
You got someone to write this for you? So - you just wanted to browse a bunch of websites and find some data in each of them and you got someone to write it for you cause you couldn't. And now you want US to solve your problem. Hmmm... Seems like you should get the author to help you out with this. You guys dreamed this up, not us. Or you could listen to mac_gyver and make his suggested changes
-
First let me say I have never used curl and don't fully understand it. Now - how your script operates. 1 - you setup and execute a curl call but you don't do anything with the returned value(s). 2 - you then start a loop to do more curl calls 3 - with each curl call you do some unknown function (I can't find it) named str_get_html 4 - with the results of this function you do a search and then you attempt to handle the contents found by this search. BAD CODE! What if there was nothing found? 5 - you append the just-read html (from the unknown function call) to an array as a new element. Is $data the reason for you memory overload? Since count starts at 1 and maxnumber is set to 5, you should only do this 5 times. Where is 12 coming into play as you mentioned?
-
current user entry counter gravity forms display numbers
ginerjm replied to mikedelater's topic in PHP Coding Help
1 - I usually can understand English, but I have a real problem with this statement: how can i display numbers with shortcode of submitted from gravity form only from current logged in user 2 - if this is about something called 'gravity' why not post it in a forum that covers that thing? A CMS perhaps? -
what is the name of this file?
-
You seem to be missing a quote in the body part of your html
-
I never know which line is which in these posts so it couldn't hurt to ask for help.
-
It would help if you pointed out which line in that code gave you the error so we know generally where to look
-
Why would anyone use Word to do coding???
-
As I understand sessions, the session remains open until the browser is closed, so a retyping of the url would not work.
-
F5 refresh key? You could stop that with a session var after the first vote is logged in a session.
-
Methinks you are trashing the wrong forum since we don't know what you are talking about. Good luck wherever you go with that attitude