Jump to content

FoxRocks

Members
  • Posts

    45
  • Joined

  • Last visited

Posts posted by FoxRocks

  1. Hello,

     

    I'm trying to do a simple database query and I keep getting an error saying:

     

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group='sales'' at line 1
    

     

    I am absolutely stumped, I have used this exact syntax before and it worked just fine! and it works perfectly if I take out that one section group='sales'

     

    Here is my code:

     

    $result = mysql_query("SELECT * FROM faq WHERE group='sales' ");
    

     

    I have a table, named faq with four columns in it...id, question, answer, group. I have checked to make sure I have data in the table and that all the spelling is correct and everything checks out. I have one entry in the "group" column that has "sales" in it and I'm trying to retrieve the "questions" and "answers" for a simple FAQ page.

     

    BTW, I realize this is a PHP form and I'm asking about Mysql syntax, I hope that's alright?

     

    Also, if I left something out please just let me know and I'll get right back to you.

     

    Thank you SO much for any direction or help you can give me, I'm at a complete loss!!

     

    ~FOX~

  2. After the first time you go through your while($page = mysql_fetch_array($q2)) loop, you will have exhausted all the records in that result set.  All subsequent calls to mysql_fetch_array will return false and cause the loop to exit.

     

    What you need to do is loop the result set and save the results to an array first, then use that array to match things up.

    $q1 = mysql_query("SELECT section_id , section_name FROM sections ORDER BY section_id");
    $q2 = mysql_query("SELECT page_name , page_link , section_id FROM pages ORDER BY page_id");
    
    $pages = array();
    while($page = mysql_fetch_array($q2))
    {
    $pages[] = $page;
    }
    
    while($section = mysql_fetch_array($q1))
    {
    echo $section['section_name'] . "<br>";
    foreach ($pages as $page)
    {
    	if($page['section_id'] == $section['section_id'])
    	{
    		echo $page['page_name'] . "<br>";
    	}
    }
    }
    

     

    Hi Kicken,

     

    Thank you very much, I just couldn't figure that out!!

     

    Although what you said makes sense, in that it exhausted the records, I am still unsure of why your solution works. I mean, it works and it works perfectly, I just can't make sense of it...if that makes sense.

     

    It really just tells me I've got a lot more to learn :)

     

    Thanks for the help, much appreciated.

     

    ~FOX~

  3. Hello,

     

    I've been trying to make a menu that is drawn from a mysql database. I am new to PHP and I am trying to learn it by trial and error...which I actually enjoy as I love troubleshooting and problem solving. Anyways I'm only saying that because I expect anyone with experience is going to look at my code and say "Why the eff are you doing ______"

     

    Ok, so here it is:

     

    $q1 = mysql_query("SELECT section_id , section_name FROM sections ORDER BY section_id");
    $q2 = mysql_query("SELECT page_name , page_link , section_id FROM pages ORDER BY page_id");
    
    while($section = mysql_fetch_array($q1))
    	{
    	echo $section['section_name'] . "<br>";
    		while($page = mysql_fetch_array($q2))
    			{
    				if($page['section_id'] == $section['section_id'])
    				{
    				echo $page['page_name'] . "<br>";
    				}
    			}
    	}
    

     

    The problem I'm getting is the menu is coming out like this:

     

    Section One

      Page 1

      Page 2

      Page 3

    Section Two

    Section Three

    Section Four

     

     

    But I want it to look like this:

     

     

    Section One

      Page 1

      Page 2

      Page 3

     

    Section Two

      Page 1

      Page 2

     

    ...etc.

     

    It appears as though it's ignoring the page data on the second, third and forth loop. I've tried it a few different ways and by reading through the PHP.net manuals, but I'm not getting anywhere.

     

    I can post this contents of my database, but I'm guessing it's not relevant as the field names sort of explain the structure well enough. I've got a few pages in each section and four sections.

    Let me know if you want me to post the data.

     

    Thanks for your help and your time, I appreciate it :)

     

    ~FOX~

     

  4. Fixed it :)

     

    Here is the new code:

     

    		// checks if the old password is correct
    		if (!get_magic_quotes_gpc()) 
    	{
    		$_POST['oldpass'] = addslashes($_POST['oldpass']);
    	$_POST['username'] = addslashes($_POST['username']);
    		}
    	$_POST['oldpass'] = md5($_POST['oldpass']);
    	$usercheck = $_POST['username'];
    	$passcheck = $_POST['oldpass'];
     	$result = mysql_query("SELECT password FROM admin WHERE username='$usercheck' AND password='$passcheck'")
    	or die(mysql_error());
    	$check = mysql_fetch_array($result);
    
    	//if the password does not match it gives an error
    	if ($check['password'] != $passcheck) 
    	{
    	die("<p style=\"margin:75px 0px 0px 150px;\">Sorry, the password for " . $_POST['username'] . " does not match the one you entered.<br> You will now be redirected back to the Admin page.</p>");
    	}
    
    
    

     

    This code now has the encryption included, but regardless of that, the problem was that I forgot to add the ['password'] part to where the if statement brings up $check. So before I had:

     

    if ($check != $passcheck)
    

     

    and now I have:

     

    if ($check['password'] != $passcheck)
    

     

    I'm super happy I found this, hopefully this will help someone down the road and not just end up being a useless post ;)

     

    Cheers,

    ~FOX~

  5. Hello,

     

    Thank you for your interest in my problem. I tried searching for help on this topic, but I kept getting an error saying I wasn't allowed to search (really???).

     

    Anyways, I'm trying to make a form for changing a password that checks to see if the old password is a match with the username in the database. Here is my code:

     

    		// checks if the old password is correct
    		if (!get_magic_quotes_gpc()) 
    	{
    		$_POST['oldpass'] = addslashes($_POST['oldpass']);
    	$_POST['username'] = addslashes($_POST['username']);
    		}
    	$usercheck = $_POST['username'];
    	$passcheck = $_POST['oldpass'];
     	$result = mysql_query("SELECT password FROM admin WHERE username='$usercheck' AND password='$passcheck'")
    	or die(mysql_error());
    	$check = mysql_fetch_array($result);
    
    	//if the password does not match it gives an error
    	if ($check != $_POST['oldpass']) 
    	{
    	die("<p style=\"margin:75px 0px 0px 150px;\">Sorry, the password for " . $_POST['username'] . " does not match the one you entered.<br> You will now be redirected back to the Admin page.</p>");
    	}
    
    

     

    I've been trying to get it to work this way so I can make sure it's not the encryption screwing me up. I manually entered a user and non encrypted password into the db for testing.

     

    I've tried this a few different ways. On the "create" admin form I have it so it encrypts it in md5 before entering into the db, so at one point I had this:

     

    		// checks if the old password is correct
    		if (!get_magic_quotes_gpc()) 
    	{
    		$_POST['oldpass'] = addslashes($_POST['oldpass']);
    	$_POST['username'] = addslashes($_POST['username']);
    		}
    	$usercheck = $_POST['username'];
    	$passcheck = ($_POST['oldpass'] = md5($_POST['oldpass']));
     	$result = mysql_query("SELECT password FROM admin WHERE username='$usercheck' AND password='$passcheck'")
    	or die(mysql_error());
    	$check = mysql_fetch_array($result);
    
    	//if the password does not match it gives an error
    	if ($check != $passcheck) 
    	{
    	die("<p style=\"margin:75px 0px 0px 150px;\">Sorry, the password for " . $_POST['username'] . " does not match the one you entered.<br> You will now be redirected back to the Admin page.</p>");
    	}
    
    

     

    I also tried this...

     

    // checks if the old password is correct
    		if (!get_magic_quotes_gpc()) 
    	{
    		$_POST['oldpass'] = addslashes($_POST['oldpass']);
    	$_POST['username'] = addslashes($_POST['username']);
    		}
    	$usercheck = $_POST['username'];
    	$_POST['oldpass'] = md5($_POST['oldpass']);
                    $passcheck = $_POST['oldpass'];
     	$result = mysql_query("SELECT password FROM admin WHERE username='$usercheck' AND password='$passcheck'")
    	or die(mysql_error());
    	$check = mysql_fetch_array($result);
    
    	//if the password does not match it gives an error
    	if ($check != $passcheck) 
    	{
    	die("<p style=\"margin:75px 0px 0px 150px;\">Sorry, the password for " . $_POST['username'] . " does not match the one you entered.<br> You will now be redirected back to the Admin page.</p>");
    	}
    

     

    Here is the entire code for the page:

     

    <?php 
    	//This makes sure they did not leave any fields blank
    
     	if (!$_POST['username'] | !$_POST['oldpass'] | !$_POST['pass'] | !$_POST['pass2']) 
     	{
    	die("<p style=\"margin:75px 0px 0px 150px;\">You did not complete all of the required fields.<br> You will now be redirected back to the Admin page.</p>");
    		}
    
    		// checks if the username is in use
    		if (!get_magic_quotes_gpc()) 
    	{
    		$_POST['username'] = addslashes($_POST['username']);
    		}
    	$usercheck = $_POST['username'];
     	$result = mysql_query("SELECT username FROM admin WHERE username='$usercheck'") 
    	or die(mysql_error());
     	$check = mysql_num_rows($result);
    
    	//if the name does not exist it gives an error
    	if ($check == 0) 
    	{
    	die("<p style=\"margin:75px 0px 0px 150px;\">Sorry, the username <strong>\"" . $_POST['username'] . "\"</strong> is not listed as an admin.<br> You will now be redirected back to the Admin page.</p>");
    	}
    
    	//this makes sure both new passwords entered match
    	if ($_POST['pass'] != $_POST['pass2']) 
    	{
    	die("<p style=\"margin:75px 0px 0px 150px;\">Sorry, the new passwords you entered did not match.<br> You will now be redirected back to the Admin page.</p>");
    	}
    
    		// checks if the old password is correct
    		if (!get_magic_quotes_gpc()) 
    	{
    		$_POST['oldpass'] = addslashes($_POST['oldpass']);
    	$_POST['username'] = addslashes($_POST['username']);
    		}
    	$usercheck = $_POST['username'];
    	$passcheck = $_POST['oldpass'];
     	$result = mysql_query("SELECT password FROM admin WHERE username='$usercheck' AND password='$passcheck'")
    	or die(mysql_error());
    	$check = mysql_fetch_array($result);
    
    	//if the password does not match it gives an error
    	if ($check != $_POST['oldpass']) 
    	{
    	die("<p style=\"margin:75px 0px 0px 150px;\">Sorry, the password for " . $_POST['username'] . " does not match the one you entered.<br> You will now be redirected back to the Admin page.</p>");
    	}
    
    	// here we encrypt the password and add slashes if needed
    	$_POST['pass'] = md5($_POST['pass']);
    
    	if (!get_magic_quotes_gpc()) 
    	{
    	$_POST['pass'] = addslashes($_POST['pass']);
    	}
    
    	// now we insert it into the database
    	$newpass = $_POST['pass'];
    	$user	= $_POST['username'];
    	mysql_query("UPDATE admin SET password='$newpass' WHERE username='$user'");
    	$result = mysql_query("SELECT password FROM admin WHERE username='$user'");
    	$success = mysql_fetch_array($result);
    		if ($success == $newpass)
    		{
    		echo "<div id=\"login\">";
    		echo "<h1 style=\"color:#000000;\">Complete</h1>";
    		echo "<p>You have successfully changed" . $_POST['username'] . "'s password to" . $_POST['pass'] . ".</p>";
    		echo "<p>You will now be redirected back to the Admin page.</p>";
    		echo "</div><!--close login-->";
    		}
    		else
    		{
    		die(mysql_error());
    		}
    
    ?>
    
    

     

    Everything else seems to work, it sees when the user is or isn't in the db, it sees when the new passwords don't match, but it always produces the error "Sorry, the password for 'username" does not match the one you entered. You will now be redirected back to the Admin page."

     

     

    I would appreciate any help or hints as to what I'm doing wrong.

     

    Thanks :)

    ~FOX~

     

  6. Hi Barand,

     

    Thanks for the reply, I was actually working on this to try and find a solution for myself before turning to outside help...and I'm feeling really good about myself right now because I was able to get it figured out. I had to look to see how to echo the status back to the radio button, but other than that I got it to work. So happy :)

     

    Not sure, but just in case someone else finds this thread looking for an answer, here is the just of what I did:

     

    Form:

     

    <form action="update.php">
    <input type="radio" name="ABC_Status" value="aog" <?php if ($Status['aircraft_status'] == 'aog') {echo "checked";} ?>></input>
    

     

    update.php:

     

    $Status = $_POST['ABC_Status'];
    

     

    UPDATE db:

     

    mysql_query("UPDATE database_name SET aircraft_status='$Status' WHERE aircraft_reg='ABC'");
    

     

    FETCH from db:

     

    $result = mysql_query("SELECT aircraft_status FROM database_name WHERE aircraft_reg='ABC'", $connection);
    $Status = mysql_fetch_array($result);
    

     

    Then on the display table I did this:

     

    CSS:
    
    tr.aog {background-color:#FF0000;}
    tr.offline {background-color:#FFFF00;}
    tr.online {background-color:none;}
    
    Table:
    
    <table>
    
    <tr class="<?php echo($Status['status']); ?>">
    <td></td>
    </tr>
    
    </table>
    
    

     

    I think that covers it. I know I've searched a hundred times looking for an answer, only to find that when the poster got it figured out they simply said "Yep! I figured it out." but didn't say how, so hopefully this helps someone.

     

    Cheers,

    ~FOX~

  7. Hello,

     

    Thank you for your interest in my problem. I have an input form for a mySQL db and then another form that displays the stored data. That part I got figured out (I'm still very new to PHP and mySQL) but this second part I am not sure how to attack.

     

    What I have is 21 records containing aircraft schedules. The aircraft column in the db never changes, they are pre populated with the aircraft id. Then there are two other columns that do change depending on the schedule and date. So I made my db so it only updates the current records.

     

    What I want to do is have another option that will change the <tr> background color of a certain row depending on a radio button selection. I've got three radio buttons for each aircraft, one for "AOG" one for "Offline" and one for "Online".  I want the user to be able to select the status of the aircraft by using these radio buttons, and as a result, have the display form pull that status from the db and display the <tr> color accordingly.

     

    How I picture this working is by having the radio button enter a "true or false" statement into the db by either a "1 or 0" and then on the other end the display form would query the column, and through an if/else statement, select the <tr> color to use.

     

    I've got to be honest, even after typing that I'm confused and can't quite get my head around it. I really want to learn this myself so for right now I would really appreciate just a rough direction to take and to let me know if I'm on the right track or not.

     

    Also, please let me know if you need more info and I apologize in advance if I didn't make any sense :)

     

    Cheers,

     

    ~FOX~

  8. Hi litebearer,

     

    I wanted to drop in a quick post just so you I'm not one of those people who ask for help never to be heard from again.

     

    I am working on this project with little time remaining until the deadline. Because of this I have done everything (I'm sure) the hard way for now just so it works, but I do plan to clean everything up once I meet the objective. Thanks again for your help, I'll post back when this becomes a priority again.

     

    Cheers,

     

    ~FOX~

  9. Hi Litebearer,

     

    Thank you for your interest in my challenge.

    I didn't mention this before as I didn't think it was relevant, but my db is never expanding in that the records are always being updated and my php table (my display table) is a of a fixed size with all the rows predetermined...meaning It will always have 21 rows with each row being dedicated to one particular aircraft.

    With this in mind, does your layout model support that structure? I only ask because I am so very new to php that I don't want to confuse myself trying to implement something that will never work.

    Regardless I still appreciate your help and your time :)

     

    Cheers,

    ~FOX~

  10. Ok, I was so excited I forgot about a second question I have.

     

    I want to change the background color of the <tr> depending on the overall status of the airplane. I sort of got it to work on the form side with some javascript to change the colors, but I'm totally clueless when it comes to storing a <tr> "state" into a db and then retrieving that "state" on the display table side.

     

    I realize this is probably best to start a new thread on, but I just thought I would ask in case it was something easy (for someone who knows what they're doing) to do.

     

    Thanks again :)

  11. Silkfire...you have no idea how happy you've made me! I just did a "WooHoo" out loud in my office :)

     

    Unfortunately for me I always decide to learn by trial and error, so I chalk this up to a very good lesson learned!!

     

    I do have a follow up question as well as a request if you don't mind.

     

    My request is, can you walk me through the "list" section of that code? I understand everything else, and that part sort of makes sense, but I want to make sure I "get it".

     

    My follow up question is, as you can probably tell this is for some of the company aircraft, of which we have 21 machines. How would I go about producing this same result for each aircraft in the database? If I were to guess at it I would probably say that I would have to name each query result variable a different name and then repeat it for each aircraft. The reason I doubt that is the best way is...well...because I can image how much code would be involved for this little project, never mind one that is much bigger.

     

    You kick ass, thank you so much for helping me out, I'm grinning ear to ear right now!

     

    ~FOX~

  12. Hello,

     

    I'm very hesitant to post this as I just know it's sure to be an easy fix, but after searching and troubleshooting for most of the afternoon, I just can't stand it anymore.

    I've created an html form that posts to a MySql db. That part is working great. The problem is trying to get the record back out of the db to display on my html/php table.

     

    Here is the code for the file the form gets posted to (aircraftupdate.php)

     

    <?php
    $OEQ_Sched = $_POST['OEQ_Sched'];
    $OEQ_EMMA = $_POST['OEQ_EMMA'];
    
    $con = mysql_connect ("localhost","user","pass");
    if (!$con)
      {
      die('Could not connect: ' .mysql_error());
      }
    mysql_select_db("fox_aircraft_status",$con);
    
    mysql_query("UPDATE Aircraft_Daily_Status SET Schedule='.$OEQ_Sched.',EMMA='.$OEQ_EMMA.' WHERE Aircraft='8Q-OEQ'");
    
    mysql_close($con);
    
    header( 'Location: http://www.andrewfox.ca/MAT/index2.php' ) ;
    ?>
    

     

    Then that redirects to this page where I want to display the record:

     

    <div id="aircraft_status">
    
    <a name="aircraft_status">
    
    <table cellpadding="0" cellspacing="0" border="2" class="font18black">
    
    <tr align="center" style="background:#FFF; font-weight:bold;" height="22">
    
    <td>
    A/C REG</td>
    
    <td>
    SCHEDULE</td>
    
    <td>
    EMMA</td>
    </tr>
    
    <tr>
    <td id="cell1display">8Q-OEQ</td>
    <?php
    $con = mysql_connect("localhost","fox_mat","10845");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    mysql_select_db("fox_aircraft_status", $con);
    mysql_query("SELECT * FROM Aircraft_Daily_Status");
    
    echo"<td id="cell2display">".$OEQ_Sched."</td>";
    echo"<td id="cell3display">".$OEQ_EMMA."</td>";
    
    mysql_close($con);
    ?>
    </tr>
    </table>
    

     

    With the code shown above I was getting an "unexpected T_STRING, expecting ',' or ';' " error. So I removed the id's from the two cells and that error went away. Trouble is the record didn't display either. Most of my information has come W3 Schools.

     

    Thank you for any help

  13. Hello,

     

    Thank you for your interest in my problem. I've started to make an html form that posts to a php script that updates a mysql database and I'm getting the mentioned error. Here is my code:

     

    <?php
    $OEQ_Sched = $_POST['OEQ_Sched']
    $OEQ_EMMA = $_POST['OEQ_EMMA']
    
    $con = mysql_connect ("localhost","fox_mat","10845");
    if (!$con)
      {
      die('Could not connect: ' .mysql_error());
      }
    mysql_select_db("fox_aircraft_status",$con);
    
    mysql_query("UPDATE Aircraft_Daily_Status SET Schedule='.$OEQ_Sched.',EMMA='.$OEQ_EMMA.' WHERE Aircraft='8Q-OEQ'");
    
    mysql_close($con);
    ?>
    

     

    It does say "line 3" in the error and I've tried a few things with no luck. Any help would be appreciated :)

     

    ~FOX~

  14. Hello,

     

    Thank you for your interest in my problem. I have a basic php form using the table element consisting of over 50 rows and 4 columns. I have 2 check boxes associated with each row that, when checked, changes the background color of that row. One check box toggles red, the other yellow. I've managed to find out how to accomplish that task with the help of some internet searching as I am brand new (read: started yesterday) to the world of PHP.

    So. That form, when posted, goes to a table on the same page that displays the results. What I would like to do is have the row color that was selected on the form show up on the posted table. This is do not know how to do and I have been trying to self learn with a lot of failure so far...I'm hoping you can help :)

     

    Here is my script:

     

    function changeColor(){
    if(document.inform.chk1.checked){
    document.getElementById("tr1").style.backgroundColor="#FF0000"
    } 
    else if(document.inform.chk2.checked){
    document.getElementById("tr1").style.backgroundColor="#FFFF00"
    } 
    else { document.getElementById("tr1").style.backgroundColor="white"}
    }
    
    

     

    Here is my form:

     

    <form action="index.php" method="post" name="inform">
    
    <table cellpadding="2" cellspacing="0" border="2">
    
    <tr class="font14white" align="center" style="background:#C0C0C0;">
    
    <td id="cell1input">
    Unit
    </td>
    
    <td id="cell2input">
    Schedule
    </td>
    
    <td id="cell3input">
    EMMA
    </td>
    
    <td id="cell4input">
    Status
    </td>
    
    </tr>
    
    <tr id="tr1" name="tr1">
    
    <td id="cell1input">
    OEQ
    </td>
    
    <td id="cell2input">
    <input type="text" name="OEQ_Sched" size="15" value="<?php echo $_POST["OEQ_Sched"]; ?>"></input>
    </td>
    
    <td id="cell3input">
    <input type="text" name="OEQ_EMMA" size="8" value="<?php echo $_POST["OEQ_EMMA"]; ?>"></input>
    </td>
    
    <td id="cell4input">
    <input type="checkbox" name="chk1" onclick="changeColor()"></input><font style="background-color:#FF0000;">RED</font><br>
    <input type="checkbox" name="chk2" onclick="changeColor()"></input><font style="background-color:#FFFF00;">YELLOW</font>
    </td>
    </tr>
    </table>
    </form>
    
    

     

    Here is my table:

     

    <table cellpadding="2" cellspacing="0" border="2">
    
    <tr class=".font14black" align="center" style="background:#FFF;" height="18">
    
    <td>
    Unit
    </td>
    
    <td>
    SCHEDULE
    </td>
    
    <td>
    EMMA
    </td>
    
    </tr>
    
    <tr>
    
    <td id="cell1display">
    OEQ
    </td>
    
    <td id="cell2display">
    <?php echo $_POST["OEQ_Sched"]; ?>
    </td>
    
    <td id="cell3display">
    <?php echo $_POST["OEQ_EMMA"]; ?>
    </td>
    
    </tr>
    
    </table>
    
    

     

    Thank you for any help you can provide.

     

    ~FOX~

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