Jump to content

gBase

Members
  • Posts

    32
  • Joined

  • Last visited

    Never

Posts posted by gBase

  1. Hi, I have a PHP/MySQL app that users login to with a server-side login (not application-side.)  What would be the best way to have them logout?  I would like to have a link to a 'logout.php' page (easy enough,) but what is the proper php code to say 'if the user hits the back button, they will be redirected to the opening page' (and therefore prompted to login again.)  Since the login is server-side (.htaccess,) hitting any pages within the directory of the application will need a login the same as the home page.  Thanks for any help.  :)
  2. [quote="fenway"]At this point, you could have re-written the entire 10-line script already....[/quote]

    Do I need to?  I was under the impression I had something that was pretty close to working.
  3. Ok, cool...now it works (sort of.)  it displays the correct fields (ID, Name, Organization, etc.) but with no values attached to them, not matter what name I search for.  Any thoughts?

    In other words, I get:
    ID:
    Name:
    Organization:
    Title:
    Street:
    City:
    State:
    Zip:
  4. Ok...tried that, searched again and got

    [code]
    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 21
    [/code]
  5. Sure...here's my form:

    [code]
    <p><b><font color="blue">Search Records:</b><br /></font>
    <form action="search.php" method="post" >
    Name:<br /> <input type="text" name="Name" /><br />
    <input type="submit" value="Submit" />
    <input type="reset" value="Reset">
    </form></p>
    [/code]


    and here's the php file:

    [code]
    <?php
    include('db_login.php');
    $connection = mysql_connect($db_host, $db_username, $db_password);
    $db_select = mysql_select_db($my_database);

        $db = "my_database";
        mysql_select_db($db) or die("Could not select the database '" . $db . "'.  Are you sure it exists?");
    if (!$connection)
    {
    die ("Could not connect to the database: <br />". mysql_error());
    }

    $request = mysql_query("SELECT ID, Name, Organization, Title, Street, City, State, Zip FROM table01 WHERE ID LIKE '%$_POST['Name']%'");

    // Loop through the results.
    while ($result_row = mysql_fetch_row(($result)))
    {
    echo 'ID: '.$result_row[0] . '<br />';
    echo 'Name: '.$result_row[1] . '<br />';
    echo 'Organization: '.$result_row[2]. '<br />';
    echo 'Title: '.$result_row[3]. '<br />';
    echo 'Street: '.$result_row[4] . '<br />';
    echo 'City: '.$result_row[5]. '<br />';
    echo 'State: '.$result_row[6]. '<br />';
    echo 'Zip: '.$result_row[7]. '<br /><br />';
    }
    // free the results
    mysql_free_result($request);


    // Close the connection
    mysql_close($connection);
    ?>
    [/code]
  6. Yes, I'm using a form which takes the 'Name' string from the user and passes it to a php file that's supposed to find the IDs in the database that correspond to that name and display the records.  Thanks, I tried $_POST['Name'] but still am getting a blank result when I try to search for a Name.
  7. Right now I have this:

    [code]
    $request = mysql_query("SELECT ID, Name, Organization, Title, Street, City, State, Zip FROM table01 WHERE ID LIKE '%$Name%'");
    [/code]

    I want the search string to be someone's Name, and the code to find the IDs (primary key) in my database that correspond with that name and display the available records...
  8. [code]
    <?php
    include('db_login.php');
    $connection = mysql_connect($db_host, $db_username, $db_password);
    $db_select = mysql_select_db($my_database);

        $db = "my_database";
        mysql_select_db($db) or die("Could not select the database '" . $db . "'.  Are you sure it exists?");
    if (!$connection)
    {
    die ("Could not connect to the database: <br />". mysql_error());
    }

    $request = mysql_query("SELECT ID, Name FROM tableName WHERE colName LIKE '%$searchTerm%'");

    echo '
    <table>';

    // Loop through the results.
    while ($row = mysql_fetch_assoc($request))
    echo '
    <tr>
    <td>', $row['ID'], '</td>
    <td>', $row['Name'], '</td>
    </tr>';

    // free the results
    mysql_free_result($request);

    echo '
    </table>';
    }
    // Close the connection
    mysql_close($connection);
    ?>
    [/code]
  9. Hmmm...I'm not sure if this is doing what I need it to do...I want the user to be able to search for strings for fields like 'Name,' and this code will query the database for the ID (primary key) of any records with that 'Name', and display the records.  Is there a query that would work better?  Thanks!  :)
  10. Hey, I'm getting a syntax error with a php file I'm creating to make my database searchable:

    [code]
    $query = "SELECT * FROM 'table01' NATURAL JOIN 'ID' WHERE 'table01'.'Name' like '%$qstring%'";
    [/code]

    Is this outdated syntax?  I'm using PHP 5.  Tried googling with little success.  Thanks for any help.
  11. Ok thanks...one more question.  Is it possible to write a query in my php insert file that will show an error if the user leaves any of the fields blank when they try to insert a new record?
  12. Hmm...yes the column is auto-increment, but I tried removing ID from the query and went to try my form and it added a new record with a blank ID.  Do you have a sample query I could try?  Thanks, I have to run to class...
  13. Ohhh ok.  Thanks for clearing that up.  I was going to post a new thread but I didn't want to junk up the board...I have another question based on the fact that I'm using ID as my primary key.  Currently, I have a form on my app that inserts new records into my database...only problem is that currently you have to enter in the new ID manually.  Is there a way to clean this up so it updates the ID automagically?  ;)

    Here's my code:

    [code]
    $sql="INSERT INTO table01 (ID, Name, Organization, Title, Street, City, State, Zip)
    VALUES
    ('$_POST[ID]','$_POST[Name]','$_POST[Organization]','$_POST[Title]','$_POST[Street]','$_POST[City]','$_POST[State]','$_POST[Zip]')";

    $result = mysql_query("SELECT ID, Name, Organization, Title, Street, City, State, Zip FROM table");

    if
    (!mysql_query($sql,$connection))
      {
      die ('Error: ' . mysql_error());
      }
    echo "1 record added";
    [/code]
  14. RIGHT...I was about to try something similar...$sql = "DELETE FROM table WHERE ID = '$ID'";

    But yours worked great and I think I may have gotten a syntax error with the 's.  Thanks!  :)
  15. Hi, I am implementing a form in my database to allow the user to remove records by ID # (which is the primary key for the table.)  The form calls to a php file that has this code:

    [code]
    $sql="DELETE FROM table (ID, Name, Organization, Title, Street, City, State, Zip)
    VALUES
    ('$_POST[ID]','$_POST[Name]','$_POST[Organization]','$_POST[Title]','$_POST[Street]','$_POST[City]','$_POST[State]','$_POST[Zip]')
    WHERE ID='$ID'";
    [/code]

    Will this work as intended?  Just want to get another pair of eyes to check this over before I try it.  I am working with a live database and while I'm trying to remove a non-used record, I don't want to risk any of the other data.
  16. New problem: the script that the previous script uses to update the table is giving me an error (weird because it worked before):

    Here's my code:

    [code]
    <?php
    foreach($HTTP_POST_VARS as $varname => $value)
            $formVars[$varname]=$value;
    require_once("config.php");
    $db1=mysql_connect($dbhost, $dbuname, $dbpass);
    mysql_select_db("sysops");
    echo "Record updated<br><a href=\"sysdocupdate.html\">click here</a> to update another record<br>";
    $query="UPDATE systemsdoc set ".
    "manu= \"".$formVars["manu"]."\",".
    "model= \"".$formVars["model"]."\",".
    "addr= \"".$formVars["addr"]."\",".
    "zip= \"".$formVars["zip"]."\",".
    "phone= \"".$formVars["phone"]."\",".
    "deploy_date= \"".$formVars["deploy_date"]."\",".
    "sernum= \"".$formVars["sernum"]."\",".
    "assetnum= \"".$formVars["assetnum"]."\",".
    "machname= \"".$formVars["machname"]."\",".
    "sysversion= \"".$formVars["sysversion"].
    "\" WHERE UID = \"".$formVars["UID"]."\"";
    mysql_query($query);
    mysql_close($db1);
    ?>
    [/code]

    and here's my error:

    [code]
    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /postdocupdate.php on line 12
    [/code]

    EDIT: Nevermind, figured it out -- took out
    echo "Record updated<br><a href=\"sysdocupdate.html\">click here</a> to update another record<br>";
    and put that message into the HTML instead.  The form works perfectly.  Thanks!
×
×
  • 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.