Jump to content

ginerjm

Members
  • Posts

    6,906
  • Joined

  • Last visited

  • Days Won

    99

Posts posted by ginerjm

  1. Searches and stuff? As in 'do your own research'? Asking for help on a forum is not what I would call research.

     

    Hints - a flaw in your logic in your while loop for one problem. A mis-type of something is your second problem which, if you had turned on error checking, would have been pointed out. Did your instructor not tell you about enabling error checking when developing? See my signature.

  2. You should also work on using proper array notation..A reference to $array[index] causes unnecessary work for the php interpreter as it searches for the correct element in the array. It usually works but can fail if your index name matches some other declared constant value.

     

    Proper array syntax if $array['index'].

  3. 1 - do you have error checking turned properly so that errors can be shown to you?

     

    2 - "this one doesn't". Just what does that mean? white screen? no json returned? something else?

     

    3 - and what if $_GET['what'] is not equal to 'legale'? What query are you going to be preparing then?

  4. Your code is out of context as posted (BESIDES being posted here incorrectly to boot) so it makes it hard to tell you what to change. Show us some more code before this so we may see what mode you are in and what this line should therefore look like.

     

    You don't tell us what is making you think it is wrong in the first place. We don't know if you have error checking turned on and are seeing a message or if you don't and are seeing a blank screen or if you are simply 'seeing' the php code on the screen because you are outside of php mode. At first glance the problem here is that you are burying php code inside your html code (bad practice - verrry bad) which is causing it to be not recognized as php.

  5. iarp gave you some good examples of how to do this but did include a small error in his code.

     

    The form he coded up for you uses the POST method. Notice? Then in the ensuing PHP code he showed you how to capture the contents of the dropdown (from the name attribute of the select tag) by grabbing the element from the GET superglobal. Problem is the data will not be in GET since your form is doing a POST. Swap out his use of $_GET for $_POST.

    • Like 1
  6. 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 ***

  7. 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.

  8. 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.

  9. 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.

  10. 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?

  11. 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

×
×
  • 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.