Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    Regular Coder
    Join Date
    Jul 2006
    Posts
    168
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Code goes Backwards

    I have a code that was working (for a short period), but now for some reason, it all seems backwards.... where I am suppose to have ", I need to remove them, and where they shouldn't be, I have to put them. Have you ever heard of this kind of thing happening. I am putting a couple of examples below.....

    [CODE]Site:<input type="text" value=<?php echo mysql_result($query, 0,
    Code:
    'Site')?>  "size="10" id="Site">"
    Unit Serial #:<input type="text" value="<? echo mysql_result($query, 0, 'Serial') ?>" size="10" id="Serial">
    Unit Hours:<input type="text" value="<? echo mysql_result($query, 0, 'Hours') ?>" size="10" id="Hours">
    The first example (site) works as a php code, and the other two don't, based on what the editor shows me. (I am new to this, so am a bit confused.)

    I am also getting this error and not sure why it has popped up all of a sudden...
    Code:
    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\wamp\www\BenProject\womanager.php on line 22
    It goes with this bit of code. I did have the ending in there about die if not correct, but I was getting an error and the only way to get rid of it was to remove it.

    Code:
    $query=mysql_query('SELECT Work, Sched, Name, Site, Serial, Hours, Starts, Issue, Severity,
    Resolution, Assistance, PartsA, PartsB, PartsC, PartsD, PartsE, PartsF, PartsG,
    Safety, Image1, Image2, Image3, Image4 FROM workorder WHERE Contact=$Work');
    Thanks,

    Ken

  • #2
    New Coder
    Join Date
    Mar 2006
    Location
    In an apartment.
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your first code snip is garbled but I think you could try this:
    Code:
    Site:<input type="text" value="<?php echo mysql_result($query, 0, 'Site')?>" size="10" id="Site">" 
    
    Unit Serial #:<input type="text" value="<?php echo mysql_result($query, 0, 'Serial') ?>" size="10" id="Serial"> 
    
    Unit Hours:<input type="text" value="<?php echo mysql_result($query, 0, 'Hours') ?>" size="10" id="Hours">
    I don't think it's advisable to use <? to open a php tag unless you are certain that short_open_tag is turned on. <? is, generally, reserved for XML. That might be your problem.

  • #3
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The 'invalid result' problem means your query is failing for some reason. The error you were getting that forced you to remove your die() call was also caused by that, which brings us to an important lesson: removing the notification of an error does not fix the error.

    Put your die() back in with a mysql_error() call to see what the server's error message is. Also, echo out your query so you can see exactly what the server's getting. Chances are, something's wrong with the 'WHERE Contact=$Work' part -- $Work isn't set (which will raise a syntax error) or it's a string and needs to be single-quoted (which will raise an unknown column error).

  • #4
    New Coder
    Join Date
    Aug 2006
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $query=mysql_query('SELECT Work, Sched, Name, Site, Serial, Hours, Starts, Issue, Severity,
    Resolution, Assistance, PartsA, PartsB, PartsC, PartsD, PartsE, PartsF, PartsG,
    Safety, Image1, Image2, Image3, Image4 FROM workorder WHERE Contact=$Work'
    ); 
    Should be

    PHP Code:
    $query=mysql_query('SELECT Work, Sched, Name, Site, Serial, Hours, Starts, Issue, Severity,
    Resolution, Assistance, PartsA, PartsB, PartsC, PartsD, PartsE, PartsF, PartsG,
    Safety, Image1, Image2, Image3, Image4 FROM workorder WHERE Contact="$Work"'
    ); 
    That should fix the problem, variables always need to be in ' or " in querys. It doesnt matter if its '$Work' or "$Work" [although in this case '$Work' would be invalid beacuse thats what you used to contain the query].

    Either way, it needs to be contained, the query is being read as WHERE Contact=Bobby Joe');

    You cant have the string uncontained .
    Last edited by guelphdad; 08-09-2006 at 01:26 PM. Reason: added php tags

  • #5
    Regular Coder
    Join Date
    Jul 2006
    Posts
    168
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That solved the problem of it not loading, and causing an error.

    Now when the page loads up it gives me the following in all the fields.
    Code:
    <? echo mysql_result($query, 0, 'PartsA') ?>
    I know this is the code that I have written for the various fields, but am not sure what would be causing that.

    It has been suggested that I need to set the variable..... but I am not sure what that means or how to do it.

    Thanks,

    Ken

  • #6
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Brokenhope
    It doesnt matter if its '$Work' or "$Work"
    If your server's running in ANSI mode, it does. For maximum compatibility with other MySQL servers and db's, use the SQL standard single quotes for strings instead of doubles.

    For your latest problem, make sure your server supports short tags, and put semicolons at the end of all your PHP statements.

  • #7
    New Coder
    Join Date
    Mar 2006
    Location
    In an apartment.
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Kid Charming is right about the semi-colons (and the short tags!). That code I posted before would work better like this:

    Code:
    Site:<input type="text" value="<?php echo mysql_result($query, 0, 'Site'); ?>" size="10" id="Site">" 
    
    Unit Serial #:<input type="text" value="<?php echo mysql_result($query, 0, 'Serial'); ?>" size="10" id="Serial"> 
    
    Unit Hours:<input type="text" value="<?php echo mysql_result($query, 0, 'Hours'); ?>" size="10" id="Hours">
    For setting the variable, you need to define the value of "$Work" within the php. For instance you could have something like
    PHP Code:
    <?php $Work 'sucks'?>
    or
    PHP Code:
    <?php $Work mysql_result($query0'Work'); ?>
    The second example would probably get you into trouble if you actually used it (I'm not sure how MySQL deals with recursion of that sort) but the point is that you have to define "$Work" somewhere before you use it in "$query".

  • #8
    Regular Coder
    Join Date
    Jul 2006
    Posts
    168
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This Crazy Canadian is about to be admitted to the physciatric unit of the local hospital....

    I have adjusted the code and it is now showing up properly as far as the php tags. When i run this program, I am getting a warning, on each line that says

    Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 4 in C:\wamp\www\BenProject\womanager.php on line 21
    The line number increases by one for each line.

    Here is the code, as it currently exists....

    Code:
    <form action="" method="post" enctype="multipart/form-data">
    <div>Work Order #:<input type="text" value=<?php echo mysql_result($query, 0, 'Work');echo mysql_error() ?> size="10" id="Work">
    Date:<input type="text" value=<?php echo mysql_result($query, 0, 'Sched');?> size="10" id="Sched">
    Technician:"<input type="text" value=<?php echo mysql_result($query, 0, 'Name'); ?> size="10" id="Name"> <BR><BR>
    Site:<input type="text" value=<?php echo mysql_result($query, 0, 'Site'); ?> size="10" id="Site">
    Unit Serial #:<input type="text" value=<?php echo mysql_result($query, 0, 'Serial'); ?> size="10" id="Serial">
    Unit Hours:<input type="text" value=<?php echo mysql_result($query, 0, 'Hours'); ?> size="10" id="Hours">
    <BR></><BR></>
    The text that I have put in bold (each line does it) shows up on the page after the text field box. In the text field box there is a <br
    The only satisfaction about this is when I put that code into a google page, the first copule pages of results are of pages that have that error on their site..... so I guess it ain't that uncommon, maybe just not that easy to solve.

  • #9
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I'm pretty sure you are getting that error because your query didn't work. Do you have any code that checks to see if the query worked? You do that by saying
    PHP Code:
    $query mysql_query("query text goes here");
    if (!
    $query) {
        echo 
    "YOU HAVE AN ERROR IN YOUR QUERY!<br>\n";
        echo 
    mysql_error();


  • #10
    Regular Coder
    Join Date
    Jul 2006
    Posts
    168
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I put that code in my query and it runs the same as it did before I had it in there. It says it is a warning, not an error, not sure if that makes a difference. I am getting ready to give up and just delete the whole thing off my computer....

    If other pages are working, I am assuming it is safe to believe that my WAMP setup is correct.

    Does this look like this would be the correct setup for my variable
    $Contact = $_POST['Work'];
    I am including the code at the beginning of this script, just to be sure that part is right, and then I will move down the script line by line. If I figure out the first line, I will have them all solved.....

    Code:
    <?php
    include_once "myconnect.php";
    $Contact = $_POST['Work'];
    $query=mysql_query("SELECT Work, Sched, Name, Site, Serial, Hours, Starts, Issue, Severity,
    Resolution, Assistance, PartsA, PartsB, PartsC, PartsD, PartsE, PartsF, PartsG,
    Safety, Image1, Image2, Image3, Image4 FROM workorder WHERE Work='$Contact'");
    if (!$query) {
        echo "YOU HAVE AN ERROR IN YOUR QUERY!<br>\n";
        echo mysql_error();
    }
    ?>
    <?php
    // WorkOrder.php
    if (!isset($_POST['Submit'])){
    ?>

  • #11
    Regular Coder
    Join Date
    Jul 2006
    Posts
    168
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I should have included this line, although I am almost positive it is correct.....

    <form action="" method="post"enctype="multipart/form-data">
    I am grasping at straws, but is it possible that in the line below the Input Type is something other than text since it is being called and not something that we are inputting?

    Code:
    <div>Work Order #:<input type="text" value=<?php echo mysql_result($query, 0, 'Work');?> size="10" id="Work">
    Sorry to be a pain, but would really love to figured out.

    Ken

  • #12
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    PHP Code:
    $Contact $_POST['Work']; 
    will work fine as long as you have an element in your form named "Work".

    So your query is indeed working? You did not get the "ERROR IN QUERY!" message?

    Ya know if this were me coding this, I would just add
    PHP Code:
    $workorderInfo mysql_fetch_assoc($query); 
    right after you execute the query, then simply use this syntax to imbed the values in your form input elements:
    PHP Code:
    Site:<input type="text" value="<?php echo $workorderInfo['Site']; ?>" size="10" id="Site">
    The main reason is, this way you put all your database functions in one spot. You assign the results of your query to an array, then you can just use the array where you need it down the line. But that's just me.

    If you want to post your entire code, I can help you with that.

  • #13
    Regular Coder
    Join Date
    Jul 2006
    Posts
    168
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The Work Order #, which is automatically generated by combining the month and time is called Work. It would be 08071515 for August, 7:15:15 in the morning.

    Sorry, but no error code came up at all. The page loads, with all that warning stuff.

    I will post the entire code, but no laughing as it isn't pretty looking.... I am just starting out.

    Here is the entire code. I have a form called workorder.php which is the original form that people fill out. This is the one the manager will look at, and add comments and a purchase order # (these comments and the Purchase Order # don't appear on the original form) Here goes:

    Code:
    <head>
    <!--<link href="ge.css" rel="stylesheet" type="text/css"> -->
    <title>GE Work Order</title>
    </head>
    <BODY BGCOLOR="gainsboro">
    <?php
    include_once "myconnect.php";
    $Contact = $_POST['Work'];
    $query=mysql_query("SELECT Work, Sched, Name, Site, Serial, Hours, Starts, Issue, Severity,
    Resolution, Assistance, PartsA, PartsB, PartsC, PartsD, PartsE, PartsF, PartsG,
    Safety, Image1, Image2, Image3, Image4 FROM workorder WHERE Work='$Contact'");
    if (!$query) {
        echo "YOU HAVE AN ERROR IN YOUR QUERY!<br>\n";
        echo mysql_error();
    }
    $workorderInfo = mysql_fetch_assoc($query);
    ?>
    <?php
    // WorkOrder.php
    if (!isset($_POST['Submit'])){
    ?>
    <form action="" method="post"enctype="multipart/form-data">
    <div>Work Order #:<input type="text" value=<?php echo mysql_result($query, 0, 'Work');?> size="10" id="Work">
    Date:<input type="text" value=<?php echo mysql_result($query, 0, 'Sched');?> size="10" id="Sched">
    Technician:"<input type="text" value=<?php echo mysql_result($query, 0, 'Name'); ?> size="10" id="Name"> <BR><BR>
    Site:<input type="text" value=<?php echo mysql_result($query, 0, 'Site'); ?> size="10" id="Site">
    Unit Serial #:<input type="text" value=<?php echo mysql_result($query, 0, 'Serial'); ?> size="10" id="Serial">
    Unit Hours:<input type="text" value=<?php echo mysql_result($query, 0, 'Hours'); ?> size="10" id="Hours">
    <BR></><BR></>
    Unit Starts:<input type="text" value=<?php echo mysql_result($query, 0, 'Starts'); ?> size="10" id="Starts">
    Severity:<input type="text" value=<?php echo mysql_result($query, 0, 'Severe'); ?> size="10" id="Severe">
     Safety:<input type="text" value=<?php echo mysql_result($query, 0, 'Safety'); ?> size="10" id="Safety">
    </div> <BR>
    <div><B>Description of Issue:</B><BR><input type="textarea" value=<?php echo mysql_result($query, 0, 'Issue'); ?> size="155" id="Issue">
    </div><BR>
    <div><B>Possible Resolution</B><BR><input type="textarea" value=<?php echo mysql_result($query, 0, 'Resolve'); ?> size="155" id="Resolve">
    </div><BR>
    <div><B>List of Parts Required (one part per line)</B>:</div>
    <div><input type="textarea" value=<?php echo (mysql_result($query, 0, 'PartsA')); ?> size="155" maxlength="155 id="PartsA"><BR>
    <input type="textarea" value=<?php echo mysql_result($query, 0, 'PartsB'); ?> size="155" maxlength="155 id="PartsB"><BR>
    <input type="textarea" value=<?php echo mysql_result($query, 0, 'PartsC'); ?> size="155" maxlength="155 id="PartsC"><BR>
    <input type="textarea" value=<?php echo mysql_result($query, 0, 'PartsD'); ?> size="155" maxlength="155 id="PartsD"><BR>
    <input type="textarea" value=<?php echo mysql_result($query, 0, 'PartsE'); ?> size="155" maxlength="155 id="PartsE"><BR>
    <input type="textarea" value=<?php echo mysql_result($query, 0, 'PartsF'); ?> size="155" maxlength="155 id="PartsF"><BR>
    <input type="textarea" value=<?php echo mysql_result($query, 0, 'PartsG'); ?> size="155" maxlength="155 id="PartsG"><BR>
    </div><BR>
    <div><B>Request for Assistance:<BR><input type="textarea" value=<?php echo mysql_result($query, 0, 'Assist'); ?> size="155" id="Assist">
    </div></B><BR><BR>
    
    <div>
    <div><center><B>Send this form to:<BR>
    <?php
    $result = mysql_query("SELECT * FROM employees") or die(mysql_error());
    echo "<select name='Tech'multiple>";
    while($row=mysql_fetch_array($result))
    {
      echo"<option>$row[Name]</option>";
    }
      echo"</select>";
    ?></select>
    <BR><div>Hold The Control Key down to select multiple names</b></div><BR><BR>
    
    
    <!--Work Order # <?php $_POST["Work"];?> was opened on <?php $_POST["Sched"];?> by
    <?php $_POST["Tech"];?>.<br><br>
    The Unit is located in<?php $_POST["Site"]?> with serial number <?php $_POST["Serial"]?>
    and this unit has <?php $_POST["Hours"]?> Hours on it.
    The Reported level of Severity is<?php $_POST["Severe"];?>and the Safety Level is<?php $_POST["Safe"];?>. <BR>
    
    Additional Details on this equipment failure are as follows:<BR><BR>
    <B>Description of Issue:</B><BR>
    <?php $_POST["Issue"]?><BR><BR>
    <B>Possible Resolution</B><BR>
    <?php $_POST["Resolve"]?><BR><BR>
    <B>Request for Assistance:</B><BR>
    <?php $_POST["Assist"]?><BR><BR>
    Parts Required: (that the technician is currently aware of)
    <?php $_POST["PartsA"]?><BR>
    <?php $_POST["PartsB"]?><BR>
    <?php $_POST["PartsC"]?><BR>
    <?php $_POST["PartsD"]?><BR>
    <?php $_POST["PartsE"]?><BR>
    <?php $_POST["PartsF"]?><BR>
    <?php $_POST["PartsG"]?><BR><BR>
    The following images have been uploaded:<BR>
    <?php $_FILE["Image1"]?><BR>
    <?php $_FILE["Image2"]?><BR>
    <?php $_FILE["Image3"]?><BR>
    <?php $_FILE["Image4"]?><BR>
    -->
    
    
    </div><BR><BR>
    
    <div><B>Image Name: (Maximum of 4 images)</B>:</div>
    <div><input type="text" value=<?php echo mysql_result($query, 0, 'Image1'); ?> size="40" maxlength="40 id="Image1"><BR>
    <input type="text" value=<?php echo mysql_result($query, 0, 'Image2'); ?> size="40" maxlength="40 id="Image2"><BR>
    <input type="text" value=<?php echo mysql_result($query, 0, 'Image3'); ?> size="40" maxlength="40 id="Image3"><BR>
    <input type="text" value=<?php echo mysql_result($query, 0, 'Image4'); ?> size="40" maxlength="40 id="Image4"><BR>
    </div>
    
    <BR><BR>
    <div><input type="submit" name="Submit" value="Update Work Order"></div>
    <input type="hidden" name="doupload" value="Submit">
    </form>
    <?php
    exit();
    
    } else
    {
    $Work = $_POST["Work"];
    $Sched = $_POST["Sched"];
    $Name = $_POST["Tech"];
    $Site = $_POST["Site"];
    $Serial = $_POST["Serial"];
    $Hours = $_POST["Hours"];
    $Starts = $_POST["Starts"];
    $Issue = $_POST["Issue"];
    $Severity = $_POST["Severe"];
    $Resolution = $_POST["Resolve"];
    $Assistance = $_POST["Assist"];
    $PartsA = $_POST["PartsA"];
    $PartsB = $_POST["PartsB"];
    $PartsC = $_POST["PartsC"];
    $PartsD = $_POST["PartsD"];
    $PartsE = $_POST["PartsE"];
    $PartsF = $_POST["PartsF"];
    $PartsG = $_POST["PartsG"];
    $Safety = $_POST["Safe"];
    $Image1 = $_FILE["Image1"];
    $Image2 = $_FILE["Image2"];
    $Image3 = $_FILE["Image3"];
    $Image4 = $_FILE["Image4"];
    
    
    
    mysql_query("INSERT INTO `workorder`(Work, Sched, Name, Site, Serial, Hours, Starts, Issue,
    Severity, Resolution, Assistance, PartsA, PartsB, PartsC, PartsD, PartsE, PartsF, PartsG,
    Safety, Image1, Image2, Image3, Image4)
    VALUES ('$Work', '$Sched', '$Name', '$Site', '$Serial', '$Hours', '$Starts', '$Issue',
    '$Severity', '$Resolution', '$Assistance','$PartsA', '$PartsB', '$PartsC', '$PartsD',
    '$PartsE', '$PartsF', '$PartsG', '$Safety','$Image1', '$Image2', '$Image3', '$Image4')")or die(mysql_error());
    
    echo "Your Work Order has been posted successfully";
    
    }
    ?>
    <?php
    //echo print_r($_POST)
    ?>
    </BODY>
    </HTML>

  • #14
    New Coder
    Join Date
    Mar 2006
    Location
    In an apartment.
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You don't need to check in anywhere, probably just a stiff drink.

    The problem with the display of the page is because you're getting an error back from your MySQL query.

    Once you fix the query the display should look fine.

    If it makes you feel any better, I'm getting the same result trying to use mysql_result() to echo values that way.

    I came up with this:

    PHP Code:
    <?php 
        $query 
    mysql_query("SELECT * FROM workorder WHERE Work='" $Contact "'");
        
        if (
    mysql_num_rows($query) > 0) {
              
    $finished_query mysql_fetch_array($queryMYSQL_ASSOC);
              
    $Sched $finished_query['Sched'];
              
            } 
    //end if 
            
        
    ?>
    It might be overkill, but once you've set this up with a line like
    PHP Code:
    $Sched $finished_query['Sched']; 
    for each of the entries you want to display, you can just use code like
    PHP Code:
    echo $Sched
    and you won't get all the weird characters in your HTML.

  • #15
    Regular Coder
    Join Date
    Jul 2006
    Posts
    168
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't actually know if there is an error or a warning. When I run it with the
    if (!$query) {
    echo "YOU HAVE AN ERROR IN YOUR QUERY!<br>\n";
    echo mysql_error();
    }

    code in there, no error comes up. You and me and hald the world have this problem. When I typed it into google, it is amazing how many pages have this error on them, and people either don't know or don't care.

    I tried putting a couple of the fields into the code you gave me, but get an error. I am not sure if the code you are talking about and the one fumigator is talking about is the same idea..... It is possible that I don't have te code you suggested in the right place, but I think I do....Here is what i have done...

    Code:
    <?php
    include_once "myconnect.php";
    $Contact = $_POST['Work'];
    $query=mysql_query("SELECT Work, Sched, Name, Site, Serial, Hours, Starts, Issue, Severity,
    Resolution, Assistance, PartsA, PartsB, PartsC, PartsD, PartsE, PartsF, PartsG,
    Safety, Image1, Image2, Image3, Image4 FROM workorder WHERE Work='$Contact'");
    if (mysql_num_rows($query) > 0) {
              $finished_query = mysql_fetch_array($query, MYSQL_ASSOC);
              $Sched = $finished_query['Sched'];
              $Work = $finished_query['Work'];
            } //end if
    ?>
    <?php
    // WorkOrder.php
    if (!isset($_POST['Submit'])){
    ?>
    <form action="" method="post"enctype="multipart/form-data">
    <div>Work Order #:<?php echo ['$Work'];?>size="10" id="Work">
    Date:<input type="text" value=<?php echo [$Sched]; ?> size="10" id="Sched">
    Technician:"<input type="text" value=<?php echo ['Tech']; ?> size="10" id="Tech"> <BR><BR>
    And the Error

    Parse error: parse error, unexpected '[' in C:\wamp\www\BenProject\womanager.php on line 23


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •