Jump to content

DataSpy

Members
  • Posts

    54
  • Joined

  • Last visited

    Never

Posts posted by DataSpy

  1. Here's a revision of the above code for the edit items page, this code lets you know if the update was successful, this will show you how to use one page to display, edit, and then update the data in one page :)

     

    <?php
    include("../../Connections/db_connection.php");
    
    // if update button has been pressed, this updates the db
    if(isset($_POST['update']))
    {
    // assign vars
    $Asset = mysqli_real_escape_string($con, trim($_POST['Asset']));
    $Manufacture = mysqli_real_escape_string($con, trim($_POST['Manufacture']));
    
    $query = "UPDATE shop_inventory SET Manufacture='$Manufacture', ect... WHERE Asset = '$Asset'";
    
    $result = mysqli_query($con, $query) or die(mysqli_error($con));
    
    if($result)
    { 
    ?>
    
    	<script language = "javascript">
    	alert('Update Successful');
    	</script>	
    
    <?php
    }
    else
    {
    ?>
    	<script language = "javascript">
    	alert('Update Failed');
    	</script>	
    
    <?php
    }
    }
    
    //this is the data you got from status page
    $Asset = mysqli_real_escape_string($con, trim($_GET['Asset']));
    
    $query = "SELECT * from shop_inventory WHERE Asset = '$Asset'";
    
    $result = mysqli_query($con, $query) or die(mysqli_error($con));
    
    if($result)
    {
       $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
       echo"
       <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
    <html xmlns=\"http://www.w3.org/1999/xhtml\">
    <head>
    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
    <title>Add Items</title>
    </head>
       <body>
       <form name=\"myForm\" action=\"$_SERVER[php_SELF]\" method=\"post\">
       Asset Number: $row[Asset]<br />
       Manufacture: <input type=\"text\" name=\"Manufacture\" value=\"$row[Manufacture]" /><br />
       <input type=\"hidden\" name=\"Asset\" value=\"$row[Asset]" />
       <input type=\"submit\" name=\"update\" value=\"Update\">
       </form>
       </body>
       </html>
       ";
    }
    ?>
    

  2. I wrote a nice long reply but I got distracted so the page timed out and I lost everything I wrote :(

     

    Anyways, you want to pass the data in the URL and then retrieve it on the next page using the GET method

     

    Status Page

     

    Instead of this

    echo "<td> <button onClick=../subpages/edititems.php>" . $row['Asset'] . "</button> </td>";
    

     

    use this, I'm using a link instead of a button but you can change it to meet your needs

    <a href=\"edititems.php?Asset=$row[Asset]\" target=\"_blank\">Edit</a>
    

     

    Edit Items page

    //this is the data you got from status page
    $Asset = mysqli_real_escape_string($con, trim($_GET['Asset']));
    
    $query = "SELECT * from shop_inventory WHERE Asset = '$Asset'";
    
    $result = mysqli_query($con, $query) or die(mysqli_error($con));
    
    if($result)
    {
       $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
       echo"
       <form name=\"myForm\" action=\"afteredititems.php\" method=\"post\">
       Asset Number: <input type=\"tex\t" name=\"Asset\" value=\"$row[Asset]" />
       ";
    }
    
    

     

     

     

     

     

  3. I'm using system() to run NMAP and then display the output but it's one big string, how can I format it to look like what I see in the command line?

     

    web app output:

    Starting Nmap 5.00 ( http://nmap.org ) at 2012-03-21 18:44 CDT Interesting ports on localhost (127.0.0.1): Not shown: 993 closed ports PORT STATE SERVICE 80/tcp open http 111/tcp open rpcbind 139/tcp open netbios-ssn 443/tcp open https 445/tcp open microsoft-ds 631/tcp open ipp 3306/tcp open mysql Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds 0

     

    command line output:

    Starting Nmap 5.00 ( http://nmap.org ) at 2012-03-21 18:48 CDT

    Interesting ports on localhost (127.0.0.1):

    Not shown: 993 closed ports

    PORT    STATE SERVICE

    80/tcp  open  http

    111/tcp  open  rpcbind

    139/tcp  open  netbios-ssn

    443/tcp  open  https

    445/tcp  open  microsoft-ds

    631/tcp  open  ipp

    3306/tcp open  mysql

     

    Nmap done: 1 IP address (1 host up) scanned in 0.45 seconds

     

    <?php
    // path to NMAP
    $Path = '/usr/bin/nmap';
    
    if(isset($_POST['scan']))
    {
    $IP = $_POST['IP'];
    $ScanType = $_POST['ScanType'];
    
    echo "<br /><u>Results for NMAP Scan</u> <br />";
    
    system("$Path $ScanType $IP 2>&1", $Output);
    
    echo $Output;
    }
    ?>
    

     

    any help would be greatly appreciated, thanks in advance!!

  4. Thanks for all of the replies!!!  I used if () instead, sorry about being a dumbass :P.  I was looking at an example of something but I changed a lot of code and in the end didn't need to use preg_match.

     

    Thanks!!!!!!!!!

  5. This is my first time using preg_match and I'm a little confuesed :(  I'm trying to match an array against zero but I keep getting the error: Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in

     

    $IP = implode('.',$Start);
    $Command = shell_exec("ping -c 1 -w 1 $IP");
    $data = explode(',',$Command);
    $data = $data[1];
    
    if(preg_match("0", '$data'))
    {
    echo "$IP online <br />";
    }
    

     

    any help would be greatly apprenticed, thanks in advance!!!

  6. What I want is to have a button and when the button is pressed it creates a drop down menu and if it's pressed again then it creates a second drop down menu.  I've been googling but haven't found anything yet if someone has an idea or a tutorial that they could direct me to that would be awesome!!!!

     

    Any help is greatly appreciated, thanks in advance!!!

  7. I'm not sure how this would be done with php or something else, what I want is to have a button and when the button is pressed it creates a drop down menu and if it's pressed again then it creates a second drop down menu.  I've been googling but haven't found anything yet if someone has an idea or a tutorial that they could direct me to that would be very helpful!!!!

     

    Any help is greatly appreciated, thanks in advance!!!

  8. This works :)

     

    $(document).ready(function() {
    var focusables = $(":input").not('[type="image"]').not('[type="submit"]');
    
      focusables.keydown(function(e) {
        if (e.keyCode == 13) {
          e.preventDefault();
          var current = focusables.index(this),
                  next = focusables.eq(current + 1).length ? focusables.eq(current + 1) : focusables.eq(0);
          next.focus();
        }
      });
    });
    
    

  9. I have a search form (phone or name), the search form is submitted with an onblur and then processed by php and returned to  the same page with ajax.  In the original page (index.php) I include a file (add_reservation.php) which holds the Search form, the output of the search for goes to a div with the results from ajax.

     

    I'm not even sure if this is possible or if I'm going about this the right way but what I want to happen is when the search form is submitted I want to hide the included file (add_reservation.php) because I don't want two tables to show up with with search form and results.

     

    you can see an example of what I'm talking about @ www.data-spy.net/test/ type 000-000-0000 into the phone field or type bank into the name field and tab through both input boxes, the result creates a second table (and an output of my sql query) which is the one I want to keep since the previous table has no data in it, if neither field is filled out it just echos back the sql query.

     

    Index.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>Reservations</title>
    <script type="text/javascript" src="jquery-1.6.2.js"></script>
    <script>
    function get_customer_info()
     {
    	 $.post('get_customer_info.php', 
    		 { 
    			 customer_number: $('form[name=add_reservation_form] input[name=number]').val(), 
    			 customer_name: $('form[name=add_reservation_form] input[name=name]').val() 
    		 },
    		 function(output)
    			 {
    				 $('#number_div').html(output).show();
    			 });
     }
    </script>
    </head>
    <body>
    <?php
    require("add_reservation.php");
    ?>
    <div id="number_div"></div>
    </body>
    </html>
    

     

    add_reservation.php

    <?php echo'
    <form name="add_reservation_form">
    <table width="50%" border="1" align="center">
    <tr>
       <td colspan="2" align="center">
       Search
       </td>
    </tr>
    <tr>
    <td>
    Phone
    </td>
    <td colspan="2">
    <input type="text" name="number" size="22"/>
    </td>
    </tr>
    <tr>
    <td>
    Name
    </td>
    <td colspan="2">
    <input type="text" name="name" onblur="get_customer_info();" size="22"/>
    <input type="hidden" name="submitted" value="yes"/>
    </td>
    </tr>
    <tr>
       <td colspan="3" align="center">
       Customer Info
       </td>
    </tr>
    <tr>
    <td>
    Home
    </td>
    <td>
     
    </td>
    </tr>
    </table>
    </form>';
    ?>
    

     

    get_customer_info.php

    <?php
    require("config.php");
    
    require("dbconnect.php");
    
    $customer_number = mysqli_real_escape_string($con, trim($_POST['customer_number']));
    $customer_name = mysqli_real_escape_string($con, trim($_POST['customer_name']));
    
    if(!empty($customer_name))
    $customer_name = "%$customer_name%";
    else 
    $customer_name = $customer_name;
    
    $query_get_customer_info = "SELECT
    customers.customer_homenumber,
    customers.customer_email,
    customers.customer_firstname,
    customers.customer_lastname,
    customers.customer_address,
    customers.customer_zipcode,
    cities.city_name,
    states.state_name
    FROM customers
    LEFT JOIN cities ON customers.customer_city_id = cities.city_id
    LEFT JOIN states ON customers.customer_state_id = states.state_id
    WHERE customer_lastname LIKE '$customer_name'
    OR customer_homenumber = '$customer_number'
    OR customer_mobilenumber = '$customer_number'
    OR customer_worknumber = '$customer_number'";
    
    $result_get_customer_info = mysqli_query($con, $query_get_customer_info) or die(mysqli_error($con));
    
    $num_rows = mysqli_num_rows($result_get_customer_info);
    
    if($num_rows == 0)
    {
    echo $query_get_customer_info;
    }
    else
    {	
    while($row = mysqli_fetch_array($result_get_customer_info))
    	{
    	echo"
    	<form name=\"add_reservation_form\">
    	<table width=\"50%\" border=\"1\" align=\"center\">
    	<tr>
    	   <td colspan=\"2\" align=\"center\">
       		   Search
       		   </td>
    	</tr>
    	<tr>
    	   <td>
    	   Phone
    	   </td>
    	   <td colspan=\"2\">
    	   <input type=\"text\" name=\"number\" size=\"22\"/>
    	   </td>
    	</tr>
    	<tr>
    	   <td>
    	   Name
    	   </td>
    	   <td colspan=\"2\">
    	   <input type=\"text\" name=\"name\" onblur=\"get_customer_info();\" size=\"22\"/>
    	   </td>
    	</tr>
    	<tr>
    	   <td colspan=\"3\" align=\"center\">
       		   Customer Info
       		   </td>
    	</tr>
    	<tr>
    	   <td>
    	   Home
    	   </td>
    	   <td>
    	   $row[customer_homenumber]
    	   </td>
    	</tr>
    	</table>
    	</form>";
       	}
    	echo $query_get_customer_info;
    }
    ?>
    

     

    Any help greatly appreciated, thanks in advance!!!!!!!!!!!!

     

  10. I'm wondering if it's possible to have one row in a table have one column, another row have 3 columns, and a third row have two columns?

     

    row 1 = 1 col

    row 2 = 3 col

    row 3 = 2 col

     

    example on my website here == http://www.data-spy.net/columns.html

     

    as you can see in the example the last column doesn't go all the way over :(

     

    <html>
    <head>
    <title>Columns suck!</title>
    </head>
    <body>
    <table width="50%" border="1">
    <tr>
       <td colspan="3">
       row 1 - 1 column - c1
       </td>
    </tr>
    <tr>
       <td>
       row 2 - 3 columns - c1
       </td>
       <td>
       c2
       </td>
       <td>
       c3
       </td>
    </tr>
    <tr colspan="2">
       <td>
       row 3 - 2 columns - c1
       </td>
       <td>
       c2
       </td>
    </tr>
    </table>
    </body>
    </html>
    

     

    Any help greatly appreciated, thanks in advance!!!!!!!!!!!!!

  11. I'm very new to ajax and javascript in general so hopefully this isn't a stupid question.  What I want to happen is when a drop down box is changed I want a form to materialize, obviously a different form for a different selection.

     

    flow chart kind of thing

    drop down box >> make selection (onchange) >> build form without refreshing page

  12. Problem:

    I want to convert the enter key to a tab key, so when a user hits enter it acts like tab.

     

    Solution:

    I found the javascript to fix my problem but it's not work, I have very little experience with javascript :(

     

    Where I found the code: http://stackoverflow.com/questions/4494552/change-enter-from-submission-to-tab

     

    Demo of the code online: http://jsfiddle.net/GRtQY/19/

     

    I know it uses Jquery and I do have that included in my script, I'm including the javascript in the head of my web page, I'm wondering if that's the problem.  Right above the framework option on http://jsfiddle.net/GRtQY/19/ there's an option (I'm assuming) of how to include the script, if I use "no wrap (head)" the script won't work but if I use "onLoad" it does.

     

    On my webpage:

     

    (in between head tags)

    $("input").bind("keydown", function(event) {
        if (event.which === 13) {
            event.stopPropagation();
            event.preventDefault();
            $(this).nextAll("input").eq(0).focus();
        }
    });

     

     

    (in between body tags)

    <form action="#">
        <input name="field-one"/>
        <div>asdadsa</div>
        <input name="field-two"/>
        <input type="submit" value="submit"/>
    </form>

     

    Any help greatly appreciated, Thanks in advance!!!

  13. Exactly, the problem is I'm stupid  While I may know PHP and MySQL, I've never really used Javascript before so I'm definitely having a hard time!

     

    lol...i'm sure you aren't stupid  ;D

    well the AJAX link that I gave you will give you a step by step on creating an AJAX xhr and will give examples of sending data to a php file via the get and post methods

     

    Thanks for all of your help!!!  I'll definitely look into that!

  14. basically you will want to use an onblur event that will call an AJAX/Jquery function that will get the customer data from your php file

    Exactly, the problem is I'm stupid :)  While I may know PHP and MySQL, I've never really used Javascript before so I'm definitely having a hard time!

     

    I'm currently watching a very informative video and it explains at least half of what I want, I still have to work on the onblur function but that'll come after I can actually read data from the db :)

     

    Video http://www.tut-cast.com/jquery/php-tutorials-get-data-from-mysql-database-without-refreshing-jquery-video_6cfbfd766.html

     

    Thanks :)

  15. The javascript function to use is onblur, that's what will retrieve the data after hitting tab.  I'm still looking for a tutorial to explain exactly what I'm looking for though :(

     

    I couple that I've found that help are:

    http://www.w3schools.com/php/php_ajax_database.asp

    http://roshanbh.com.np/2008/04/check-username-available-ajax-php-jquery.html

     

    I think I'll be able to figure it out but it's going to take some time to combine these two tutorials!

     

    Thanks for the help!  If anyone knows of a tutorial that will retrieve data from a database and populate other fields with an onblur function I would greatly appreciate it!

  16. Hello, I'm a total newbie with ajax and was wondering if anyone could point me in the right direction of a tutorial that would help me accomplish what I'm looking to do.  I want to be able to type a phone number into a text field, then hit tab and have the customer info populate from the phone number.

     

    Any help greatly appreciated,

    thanks in advance!!!!

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