Jump to content

IreneLing

Members
  • Posts

    60
  • Joined

  • Last visited

    Never

Posts posted by IreneLing

  1. an aside...

     

    It may be better to create your queries as strings. Doing that allow you to echo the queries when checking to ascertain that produce values you are expecting. AND, for me atleast, makes it easier to use single and double quotes.

     

    ie...

     

    $query = "something";

    $result = mysql_query($query);

     

    Thanks for your advice , I will take note of it , thank you.

  2. In php a string in single quotes is a constant value ( is exactly what you write ) and a string in double quotes is a dynamic string ( checks for variables and escaping values ).

     

    so

     

      mysql_query('UPDATE table SET Status=1,Sending=Done,SentAt='$date' WHERE ID IN ('.implode(',', $done).')'); 

     

    Won't work as the value of '$date' is breaking the syntax as you have closed the string had no operation then added a variable then opened a new constant string.

     

    To fix this you can simply do :

     

      mysql_query('UPDATE table SET Status=1,Sending=Done,SentAt=' . $date . ' WHERE ID IN ('.implode(',', $done).')'); 

     

    Notice the . either side of the $date variable which concatenates string values. Another way would have been to use double quotes e.g. :

     

      mysql_query( "UPDATE table SET Status=1,Sending=Done,SentAt='$date ' WHERE ID IN ( " . implode(',', $done) . ')' ); 

     

    Both should work.

     

     

    Thank you so much, yes it works.Really thanks to your solution and explanations.

  3. I'm so sorry for this question but I not really know how to play with single and double quote.

     

    If I have a query like this:

     

      mysql_query('UPDATE table SET Status=1,Sending=Done WHERE ID IN ('.implode(',', $done).')');

     

    And I wish to add

    SentAt='$date'

    in the query as well , and I try this:

     

      mysql_query('UPDATE table SET Status=1,Sending=Done,SentAt='$date' WHERE ID IN ('.implode(',', $done).')');

     

    Not working...how should I write it?

     

    Thank you.

  4. Really thanks for your code requinix , I tried to understand it ( a little hard for me) and try it , but here is the errors:

     

    Warning: array_combine() [function.array-combine]: Both parameters should have an equal number of elements

    Warning: array_merge() [function.array-merge]: Argument #2 is not an array

    Warning: array_combine() [function.array-combine]: Both parameters should have an equal number of elements

    Warning: array_merge() [function.array-merge]: Argument #2 is not an array

     

    INSERT INTO UserAddedRecord (lastname, firstname, ceLL, group) VALUES (NULL, NULL, NULL, NULL), (NULL, NULL, NULL, NULL)

     

    $additional_columns = array("group");

     

    If I change 'group' to other column name that do not exist in my table then it will just insert data in csv file and works fine , but if I put existed column name then everything will become NULL , and I have problem in trying to solve it since do not really understand the error..

     

  5. Hi all.

    Here is the code:(thanks to jcbones)

        if (($handle = fopen($source_file, "r")) !== FALSE) {
            $columns = fgetcsv($handle, $max_line_length, ",");
            foreach ($columns as &$column) {
                $column = str_replace(".","",$column);
            }
            while (($data = fgetcsv($handle, $max_line_length, ",")) !== FALSE) {
                while(count($data) < count($columns)) {
    			array_push($data, NULL);
    		}
    		$c = count($data);
    		for($i = 0; $i < $c; $i++) {
    			$data[$i] = "'{$data[$i]}'";
    		}
    
    		$sql[] = '(' . implode(',',$data) . ','.$_POST[group].')';
            }
                    $sql = implode(',',$sql);
    
    	$query = "INSERT INTO mytable (".mysql_real_escape_string(implode(",",$columns)).",Custgroup,user_id) VALUES " 
                              . $sql . "\n";
    	mysql_query($query) or trigger_error(mysql_error());
    
            fclose($handle);
        }
    } 
    
    

     

    If my csv file is:

    lastname,firstname,gender

    bob,ah,male

     

    So now the query will be :  INSERT INTO mytable (lastname,firstname,gender) VALUES ('bob',ah','male').

    But how if I want to insert extra data into mysql together with the data in csv file?

    Such as I have a value $_POST['group'] = 'family', so I tried:

    $sql[] = '(' . implode(',',$data) . ','.$_POST[group].')';
    
    $query = "INSERT INTO $target_table (".mysql_real_escape_string(implode(",",$columns)).",custgroup) VALUES " 
                              . implode(',',$sql) . "\n";
    

     

    But in the query it will become :  INSERT INTO mytable (lastname,firstname,gender,custgroup) VALUES ('bob',ah','male',family).

    It didn't have single quote , so I have error to insert the record.Can I know how to solve this problem?

     

    Thanks.

  6. Here is a user supplied function from the php manual page (slightly modified), and it should fit your use.

     

    Right now, it just prints to the page to show you what the query will look like, just remove the comment marks on the query line to insert it.

     

    jcbones , I really wish can treat you to lunch if I live near your place , yes it fit my use , and it works like a charm.

     

    Thank you so much , I really appreciate your help.

  7. Thanks for your reply.

    So now I try something like this...

     

    if (isset($_POST['submit'])) {
    
    if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
    	echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "<br></h1>";
    	echo "<h2>Displaying contents:</h2>";
    	readfile($_FILES['filename']['tmp_name']);
    	echo "<br>";
    	echo $headers;
    }
    
    
    $handle = fopen($_FILES['filename']['tmp_name'], "r");
    
    $header = fgetcsv($handle);
    
    
    while(! feof($handle)){
    
    
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    
                        $num = count($data);
    
                       mysql_select_db("EMC", $db);
    
                       $sql = "SELECT * from CSVtest";
                       $result = mysql_query($sql,$db);
    
                           while ($user_table_property = mysql_fetch_field($result)) 
                                    {
    
                          for($i=0; $i<$num; $i++){
                             
                                          if($header[$i] == $user_table_property->name )
                                                       {
    
                                                        $import = "insert into CSVtest ( `" . $header[$i] . "`) values ('" . $data[$i] . "')";
    
                                                       }
    
    
    
                                                   }
    
                                      mysql_query($import) or die(mysql_error()) ; 
                                    }
                                                   
                                
    
    
    
                                                           } 
    
        
                       }
    

     

    The column is correct , but each data will inserted into different rows,and some will duplicate....

  8. Hello all.

     

    Here is my script...

     

    if (isset($_POST['submit'])) {
    if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
    	echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "<br></h1>";
    	echo "<h2>Displaying contents:</h2>";
    	readfile($_FILES['filename']['tmp_name']);
    	echo "<br>";
    	echo $headers;
    }
    
    
    $handle = fopen($_FILES['filename']['tmp_name'], "r");
    
    $header = fgetcsv($handle);
    
    while(! feof($handle)){
    
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    	$import="INSERT into CSVtest($header[0],$header[1],$header[2],$header[3],$header[4]) 
                             values
                             ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')";
    
    	mysql_query($import) or die(mysql_error());
    }
    
    }
    
    fclose($handle);
    
    echo "Done";
    
    }

     

    This is the way how I insert data into database according to header even it's not arranged same as the table column.

    If the csv has only "cell,firstname,lastname,," (and my table has only these 3 columns as well)  then it still working...but if there are "cell,address,company,firstname,lastname" then it will show me unknown column error.

     

    Actually I wish to have a function that even there are many columns in csv that not exist in the table it still can just pick the right column and insert into table.

    Can anyone give me hints on how to change my script?I know there are many errors...it's really embarrassed to show my low standard script...

     

    Thanks in advance.

  9. Thank you so much for the links xyph , I'm just wondering how to turn it off before I start google it .

    Thanks again and wish you have a nice day .

     

     

    PS: Thanks for the link in your signature too , my coding have major sql injection problem now and gotta solve it.

  10. Hi all.

    When I typed symbol ' in my textarea , after I submit it and view for what I typed , it will automatically add a slash in front of the ' .

     

    Such as the message is "I'm fine" , then it will turn out as "I\'m fine". Can I know what is the problem ? and how can I solve it?

     

    Thanks for every reply .

  11. I have a function which is use to check chinese input in a textarea then set the maximum length , it works with IE , Opera , Chrome except firefox .

    Is there any way to solve this problem ?

     

    Just in case....I will put my function here....

     

    function testChinese() {
    countA = 0;
    for(var i=0; i<bulksend.inputtext.value.length; i++)
    {
    	curText = bulksend.inputtext.value.charCodeAt(i);
    	if(curText > 127)
    	{	
    		countA += 1;
    	}
    }
    if(countA>0)
    	return true;
    }
    
    
    
    function setlength(){
    
    min = 0;
    limit = 0;
    
    
    if(testChinese() == true) {
    	min = 70;
    	limit = 66;
    }
    else {
    	min = 160;
    	limit = 156;
    }
    
    
    var typedtext = document.getElementById('inputtext').value;
    
           .........continue.......
    
    

     

    Thanks for every reply .

  12. Thanks for your reply Drummin , actually there are 2 forms in this page , above is to insert data , and below is display and delete.

     

    <form name="frmSearch" method="post" action="insert-add.php">
      <table width="599" border="1">
    
    <tr>
    <td>  Mobile Phone: </td>
    <td>  <input name="cell" type="text" id="cell" > </td>
    </tr>
    
    <tr>
    <td>Mobile Company:</td>
    <td><select name="mobilecompany">
    <option>A</option>
    <option>B</option>
    <option>C</option>
    </select>
    </td>
    </tr>
    
    <tr>
    <td>  First Name: </td>
    <td>  <input name="firstname" type="text" id="firstname" > </td>
    </tr>
    
    <tr>
    <td>  Last Name: </td>
    <td>  <input name="lastname" type="text" id="lastname" > </td>
    </tr>
    
    <tr>
    <td>Work Phone:</td>
    <td><input style="text" name="workphone"></td>
    </tr>
    
    <tr>
    <td>Fax:</td>
    <td><input style="text" name="fax"></td>
    </tr>
    
    <tr>
    <td>Email:</td>
    <td><input style="text" name="email"></td>
    </tr>
    
    <tr>
    <td>Gender:</td>
    <td><select name="gender">
    <option>Male</option>
    <option>Female</option>
    </select>
    </td>
    </tr>
    
    <tr>
    <td>Birthday:</td>
    <td>
    
    <input name="birthday" value="<?php echo htmlentities($disp_birthday) ?>">
    <input type=button value="select" onclick="displayDatePicker('birthday', this);">
    
    </td>
    </tr>
    
    
    
    <tr>
    <td>  ID: </td>
    <td>  <input type="text" name="user_id" value="<?php echo $id;?>"></td>
    </tr>
    
    
    <tr>
    <td><input type="submit" value="Add" name="add"></td>
    </tr>
    
    
      </table>
    </form>
    

     

    Some other codes...then continue...

     

        <table width="600" border="1">
          <tr>
            <th width="50"> <div align="center">#</div></th>
            <th width="91"> <div align="center">ID </div></th>
            <th width="198"> <div align="center">First Name </div></th>
            <th width="198"> <div align="center">Last Name </div></th>
            <th width="250"> <div align="center">Mobile Company </div></th>
            <th width="100"> <div align="center">Cell </div></th>
            <th width="100"> <div align="center">Workphone </div></th>
            <th width="100"> <div align="center">Group </div></th>
          </tr>
    
        <?
    
    echo "<form name='form1' method='post' action=''>";
    
        while($objResult = mysql_fetch_array($objQuery))
        {
    
    
    echo "<tr>";
       echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>";
       echo "<td>$objResult[addedrec_ID] </td>";
       echo "<td>$objResult[FirstName]</td>";
       echo "<td>$objResult[LastName] </td>";
       echo "<td>$objResult[MobileCompany] </td>";
       echo "<td>$objResult[Cell] </td>";
       echo "<td>$objResult[WorkPhone] </td>";
       echo "<td>$objResult[Custgroup] </td>";
    
    echo "</tr>";
    
        }
    
    
    echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">";
    
    if (isset($_POST['delete']) && isset($_POST['checkbox'])) // from button name="delete"
         {
    $checkbox = ($_POST['checkbox']); //from name="checkbox[]"
             $countCheck = count($_POST['checkbox']);
    
    
    for($d=0;$d<$countCheck;$d++)
             {
    $del_id = intval($checkbox[$d]);
    
    $sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id";
    
    $result2=mysql_query($sql)  or trigger_error(mysql_error());;;
    
             }
                 if($result2)
             {    
                  $fgmembersite->GetSelfScript();
                 }
                 else
                 {
    echo "Error: ".mysql_error();
                 }
         }
    
    echo "</form>";
    
        ?>
        </table>
    
    

     

     

     

  13. Hi all.

    Here is my scripts which allow user to check multiple rows of data and delete it , but it require select data and click for twice to delete the rows , what should be the error?

     

    <form name="frmSearch" method="post" action="insert-add.php">
    
    <table width="600" border="1">
      <tr>
        <th width="50"> <div align="center">#</div></th>
        <th width="91"> <div align="center">ID </div></th>
        <th width="198"> <div align="center">First Name </div></th>
        <th width="198"> <div align="center">Last Name </div></th>
        <th width="250"> <div align="center">Mobile Company </div></th>
        <th width="100"> <div align="center">Cell </div></th>
        <th width="100"> <div align="center">Workphone </div></th>
        <th width="100"> <div align="center">Group </div></th>
      </tr>
        </form>
    <?
    
        echo "<form name='form1' method='post' action=''>";
    
    while($objResult = mysql_fetch_array($objQuery))
    {
    
    
        echo "<tr>";
        echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>";
        echo "<td>$objResult[addedrec_ID] </td>";
        echo "<td>$objResult[FirstName]</td>";
        echo "<td>$objResult[LastName] </td>";
        echo "<td>$objResult[MobileCompany] </td>";
        echo "<td>$objResult[Cell] </td>";
        echo "<td>$objResult[WorkPhone] </td>";
        echo "<td>$objResult[Custgroup] </td>";
    
       echo "</tr>";
    
    }
    
    
    echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">";
    
    if (isset($_POST['delete']) && isset($_POST['checkbox'])) // from button name="delete"
    {
    $checkbox = ($_POST['checkbox']); //from name="checkbox[]"
         $countCheck = count($_POST['checkbox']);
    
    for($d=0;$d<$countCheck;$d++)
         {
             $del_id  = $checkbox[$d];
    
    $sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id";
    
    $result2=mysql_query($sql)  or trigger_error(mysql_error());;;
    
         }
             if($result2)
         {  
              $fgmembersite->GetSelfScript();
             }
             else
             {
    echo "Error: ".mysql_error();
             }
    }
      echo "</form>";
    

     

    Thanks for every reply.

  14. Sorry again , but it seems I still have some problem with my $_GET.

     

    Here is the error I get:

     

    Notice: Undefined variable: id in /opt/lampp/htdocs/EMC/customer-search.php on line 248

    Notice: Undefined index: Page in /opt/lampp/htdocs/EMC/customer-search.php on line 255

    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /opt/lampp/htdocs/EMC/customer-search.php on line 302

     

    And my code for second error:

    	$Per_Page = 2;   // Per Page
    
    $Page = isset($_GET["Page"]);
    if (!$_GET["Page"])
    {
    	$Page=1;
    }

     

    I'm not really sure what's the problem with my first and third error so I will post the whole code here:

    <?php
    
    require_once("./include/fg_membersite.php");
    require_once("./include/membersite_config.php"); 
    
    
    
    $objConnect = mysql_connect("localhost","root","") or die(mysql_error());
    $objDB = mysql_select_db("EMC");
    
    $haha = $fgmembersite->UserEmail();
    $_SESSION['storedemail']= $haha;
    
    $query4 = mysql_query("SELECT * FROM Register WHERE Email= '$haha'");
    while ($row4 = mysql_fetch_array($query4)){
    
        $id = $row4['ID'];
    }
    mysql_free_result($query4);
    
    ?>
    
    <html>
    
    <body>
    
    
    <form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
      <table width="599" border="1">
        <tr>
          <th>Keyword
          <input name="txtFirstName" type="text" id="txtFirstName" value="<?= isset($_GET["txtFirstName"]) ;?>">
          <input name="txtLastName" type="text" id="txtLastName" value="<?= isset($_GET["txtLastName"]) ;?>">
          <input name="txtCell" type="text" id="txtCell" value="<?= isset($_GET["txtCell"]) ;?>">
    
    
    
    
    <?
    
         $opselect="SELECT DISTINCT Custgroup FROM UserAddedRecord";
    
    $result = mysql_query ($opselect);
    
    while($nt=mysql_fetch_array($result))
    {
    ?>
    <option><?= $nt[Custgroup]?></option>";
    
    <?
    }
    ?>
    
    </select>
          <input type="submit" value="Search">
        </tr>
      </table>
    </form>
    <?
    if (isset($_GET["txtFirstName"]) != "" || isset($_GET["txtLastName"]) != "" || isset($_GET["txtCell"]) != "" || isset($_GET["txtGroup"]) != "")
    {
    $objConnect = mysql_connect("localhost","root","") or die(mysql_error());
    $objDB = mysql_select_db("EMC");
    // Search By Name or Email
    $strSQL = "SELECT * FROM UserAddedRecord WHERE (FirstName LIKE '%".$_GET["txtFirstName"]."%' and LastName LIKE '%".$_GET["txtLastName"]."%' and Cell LIKE '%".$_GET["txtCell"]."%' and Custgroup LIKE '%".$_GET["txtGroup"]."%')";
    $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
    $Num_Rows = mysql_num_rows($objQuery);
    
    
    $Per_Page = 2;   // Per Page
    
    $Page = isset($_GET["Page"]);
    if (!$_GET["Page"])
    {
    	$Page=1;
    }
    
    $Prev_Page = $Page-1;
    $Next_Page = $Page+1;
    
    $Page_Start = (($Per_Page*$Page)-$Per_Page);
    if($Num_Rows<=$Per_Page)
    {
    	$Num_Pages =1;
    }
    else if(($Num_Rows % $Per_Page)==0)
    {
    	$Num_Pages =($Num_Rows/$Per_Page) ;
    }
    else
    {
    	$Num_Pages =($Num_Rows/$Per_Page)+1;
    	$Num_Pages = (int)$Num_Pages;
    }
    
    
    $strSQL .=" order  by addedrec_ID DESC LIMIT $Page_Start , $Per_Page";
    $objQuery  = mysql_query($strSQL);
    
    ?>
    <table width="600" border="1">
      <tr>
    	<th width="50"> <div align="center">#</div></th>
    	<th width="91"> <div align="center">CustomerID </div></th>
    	<th width="98"> <div align="center">Name </div></th>
    	<th width="198"> <div align="center">Email </div></th>
    	<th width="97"> <div align="center">CountryCode </div></th>
    	<th width="59"> <div align="center">Budget </div></th>
    	<th width="71"> <div align="center">Used </div></th>
      </tr>
    <?
    while($objResult = mysql_fetch_array($objQuery))
    {
    ?>
      <tr>
    	<td><div align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?=$objResult["addedrec_ID"];?>"></div></td>
    	<td><div align="center"><?=$objResult["addedrec_ID"];?></div></td>
    	<td><?=$objResult["FirstName"];?></td>
    	<td><?=$objResult["LastName"];?></td>
    	<td><div align="center"><?=$objResult["MobileCompany"];?></div></td>
    	<td align="right"><?=$objResult["Cell"];?></td>
    	<td align="right"><?=$objResult["Workphone"];?></td>
      </tr>
    <?
    }
    ?>
    </table>
    <br>
    Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
    <?
    if($Prev_Page)
    {
               if($_GET["txtFirstName"] == "")
                          {
    	echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtLastName=$_GET[txtLastName]'><< Back</a> ";	
                          }
    
                else
                          {
    	echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtFirstName=$_GET[txtFirstName]'><< Back</a> ";
                          }
    
    }
    
    for($i=1; $i<=$Num_Pages; $i++){
    	if($i != $Page)
    	{
    
    		echo "[ <a href='$_SERVER[sCRIPT_NAME]?Page=$i&txtFirstName=$_GET[txtFirstName]'>$i</a> ]";	
    
    	}
    	else
    	{
    		echo "<b> $i </b>";
    	}
    }
    if($Page!=$Num_Pages)
    {
                  if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "" && $_GET["txtCell"] == "")
                               {
    	        echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtGroup=$_GET[txtGroup]'>Next>></a> ";
                               }
                  else if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "")
                               {
    	        echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]'>Next>></a> ";	
                               }
                  else if($_GET["txtFirstName"] == "" )
                               {
    		echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]'>Next>></a> ";	
                               }
                  else
                               {
    	        echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]'>Next>></a> ";	}
                       }
    
    mysql_close($objConnect);
    
    
    }	
    
    else 
    {
    
    $strSQL = "SELECT * FROM UserAddedRecord WHERE user_id='$id'";
    $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
    $Num_Rows = mysql_num_rows($objQuery);
    
    $Per_Page = 2;   // Per Page
    
    $Page = isset($_GET["Page"]);
    if (!$_GET["Page"])
    {
    	$Page=1;
    }
    
    $Prev_Page = $Page-1;
    $Next_Page = $Page+1;
    
    $Page_Start = (($Per_Page*$Page)-$Per_Page);
    if($Num_Rows<=$Per_Page)
    {
    	$Num_Pages =1;
    }
    else if(($Num_Rows % $Per_Page)==0)
    {
    	$Num_Pages =($Num_Rows/$Per_Page) ;
    }
    else
    {
    	$Num_Pages =($Num_Rows/$Per_Page)+1;
    	$Num_Pages = (int)$Num_Pages;
    }
    
    
    $strSQL .=" order  by id DESC LIMIT $Page_Start , $Per_Page";
    $objQuery  = mysql_query($strSQL);
    
    
    
    
    
    ?>
    <table width="600" border="1">
      <tr>
    	<th width="50"> <div align="center">#</div></th>
    	<th width="91"> <div align="center">ID </div></th>
    	<th width="198"> <div align="center">First Name </div></th>
    	<th width="198"> <div align="center">Last Name </div></th>
    	<th width="250"> <div align="center">Mobile Company </div></th>
    	<th width="100"> <div align="center">Cell </div></th>
    	<th width="100"> <div align="center">Workphone </div></th>
    	<th width="100"> <div align="center">Group </div></th>
      </tr>
    <?
    
    echo "<form name='form1' method='post' action=''>";
    
    while($objResult = mysql_fetch_array($objQuery))
    {
    
    
    echo "<tr>";
       echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>";
       echo "<td>$objResult[addedrec_ID] </td>";
       echo "<td>$objResult[FirstName]</td>";
       echo "<td>$objResult[LastName] </td>";
       echo "<td>$objResult[MobileCompany] </td>";
       echo "<td>$objResult[Cell] </td>";
       echo "<td>$objResult[WorkPhone] </td>";
       echo "<td>$objResult[Custgroup] </td>";
    
    echo "</tr>";
    
    }
    
    
    echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">";
    
    if(isset($_POST['delete'])) // from button name="delete"
     {
    $checkbox = $_POST['checkbox']; //from name="checkbox[]"
    	 $countCheck = count($_POST['checkbox']);
    
    for($d=0;$d<$countCheck;$d++)
    	 {
    		 $del_id  = $checkbox[$d];
    
    $sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id";
    
    $result2=mysql_query($sql);
    
    	 }
    		 if($result2)
    	 {	
    			 header('Location: customer-adddata.php');
    		 }
    		 else
    		 {
    echo "Error: ".mysql_error();
    		 }
     }
    
    echo "</form>";
    
    ?>
    </table>
    <br>
    Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
    <?
    if($Prev_Page)
    {
               if($_GET["txtFirstName"] == "")
                          {
    	echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtLastName=$_GET[txtLastName]'><< Back</a> ";	
                          }
    
                else
                          {
    	echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtFirstName=$_GET[txtFirstName]'><< Back</a> ";
                          }
    
    }
    
    for($i=1; $i<=$Num_Pages; $i++){
    	if($i != $Page)
    	{
    
    		echo "[ <a href='$_SERVER[sCRIPT_NAME]?Page=$i&txtFirstName=$_GET[txtFirstName]'>$i</a> ]";	
    
    	}
    	else
    	{
    		echo "<b> $i </b>";
    	}
    }
    if($Page!=$Num_Pages)
    {
                  if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "")
                               {
    	        echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]'>Next>></a> ";	
                               }
                  else if($_GET["txtFirstName"] == "" )
                               {
    		echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]'>Next>></a> ";	
                               }
                  else
                               {
    	        echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]'>Next>></a> ";	}
                       }
    
    mysql_close($objConnect);
    
    
    
    }
    
    
    ?>
    </body>
    </html>
    

     

     

    And one more error , when I tried to search data and typed some keywords in the textbox , three of the textbox will keep return me value "1" ,

     

    2121.jpg

     

    I really tried to solve the error but still there....can anyone help me for this?

    Thanks in advanced.

     

  15. Hi all.Here is a part of my scripts . When I run it with my hosting server it works very well , but when I run it in ubuntu lampp , it keeps giving me these errors:

     

    Notice: Undefined index: txtFirstName in /opt/lampp/htdocs/EMC/customer-search.php  on line 123

    Notice: Undefined index: txtLastName in /opt/lampp/htdocs/EMC/customer-search.php on line 123

    Notice: Undefined index: txtCell in /opt/lampp/htdocs/EMC/customer-search.php on line 123

    Notice: Undefined index: txtGroup in /opt/lampp/htdocs/EMC/customer-search.php on line 123

    Notice: Undefined variable: id in /opt/lampp/htdocs/EMC/customer-search.php on line 247

    Notice: Undefined index: Page in /opt/lampp/htdocs/EMC/customer-search.php on line 253

    Notice: Undefined index: Page in /opt/lampp/htdocs/EMC/customer-search.php on line 254

     

     

    Here is the code:

     

    
    <html>
    
    <body>
    
    <form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
      <table width="599" border="1">
        <tr>
          <th>Keyword
          <input name="txtFirstName" type="text" id="txtFirstName" value="<?=$_GET["txtFirstName"];?>">
          <input name="txtLastName" type="text" id="txtLastName" value="<?=$_GET["txtLastName"];?>">
          <input name="txtCell" type="text" id="txtCell" value="<?=$_GET["txtCell"];?>">
    
    
    
    <?
    
         $opselect="SELECT DISTINCT Custgroup FROM UserAddedRecord";
    
    $result = mysql_query ($opselect);
    
    while($nt=mysql_fetch_array($result))
    {
    ?>
    <option><?= $nt[Custgroup]?></option>";
    
    <?
    }
    ?>
    
    </select>
          <input type="submit" value="Search">
        </tr>
      </table>
    </form>
    <?
    if($_GET["txtFirstName"] != "" || $_GET["txtLastName"] != "" || $_GET["txtCell"] != "" || $_GET["txtGroup"] != "")
        {
        $objConnect = mysql_connect("localhost","root","") or die(mysql_error());
        $objDB = mysql_select_db("EMC");
        // Search By Name or Email
        $strSQL = "SELECT * FROM UserAddedRecord WHERE (FirstName LIKE '%".$_GET["txtFirstName"]."%' and LastName LIKE '%".$_GET["txtLastName"]."%' and Cell LIKE '%".$_GET["txtCell"]."%' and Custgroup LIKE '%".$_GET["txtGroup"]."%')";
        $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
        $Num_Rows = mysql_num_rows($objQuery);
    
    
        $Per_Page = 2;   // Per Page
    
        $Page = $_GET["Page"];
        if(!$_GET["Page"])
        {
            $Page=1;
        }
    
        $Prev_Page = $Page-1;
        $Next_Page = $Page+1;
    
        $Page_Start = (($Per_Page*$Page)-$Per_Page);
        if($Num_Rows<=$Per_Page)
        {
            $Num_Pages =1;
        }
        else if(($Num_Rows % $Per_Page)==0)
        {
            $Num_Pages =($Num_Rows/$Per_Page) ;
        }
        else
        {
            $Num_Pages =($Num_Rows/$Per_Page)+1;
            $Num_Pages = (int)$Num_Pages;
        }
    
    
        $strSQL .=" order  by id DESC LIMIT $Page_Start , $Per_Page";
        $objQuery  = mysql_query($strSQL);
    
        ?>
        <table width="600" border="1">
          <tr>
            <th width="50"> <div align="center">#</div></th>
            <th width="91"> <div align="center">CustomerID </div></th>
            <th width="98"> <div align="center">Name </div></th>
            <th width="198"> <div align="center">Email </div></th>
            <th width="97"> <div align="center">CountryCode </div></th>
            <th width="59"> <div align="center">Budget </div></th>
            <th width="71"> <div align="center">Used </div></th>
          </tr>
        <?
        while($objResult = mysql_fetch_array($objQuery))
        {
        ?>
          <tr>
            <td><div align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?=$objResult["id"];?>"></div></td>
            <td><div align="center"><?=$objResult["id"];?></div></td>
            <td><?=$objResult["FirstName"];?></td>
            <td><?=$objResult["LastName"];?></td>
            <td><div align="center"><?=$objResult["MobileCompany"];?></div></td>
            <td align="right"><?=$objResult["Cell"];?></td>
            <td align="right"><?=$objResult["Workphone"];?></td>
          </tr>
        <?
        }
        ?>
        </table>
        <br>
        Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
        <?
        if($Prev_Page)
        {
               if($_GET["txtFirstName"] == "")
                          {
            echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtLastName=$_GET[txtLastName]'><< Back</a> ";    
                          }
    
                else
                          {
            echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtFirstName=$_GET[txtFirstName]'><< Back</a> ";
                          }
    
        }
    
        for($i=1; $i<=$Num_Pages; $i++){
            if($i != $Page)
            {
    
                echo "[ <a href='$_SERVER[sCRIPT_NAME]?Page=$i&txtFirstName=$_GET[txtFirstName]'>$i</a> ]";    
    
            }
            else
            {
                echo "<b> $i </b>";
            }
        }
        if($Page!=$Num_Pages)
        {
                  if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "" && $_GET["txtCell"] == "")
                               {
                    echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtGroup=$_GET[txtGroup]'>Next>></a> ";
                               }
                  else if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "")
                               {
                    echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]'>Next>></a> ";    
                               }
                  else if($_GET["txtFirstName"] == "" )
                               {
                echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]'>Next>></a> ";    
                               }
                  else
                               {
                    echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]'>Next>></a> ";    }
                           }
        
        mysql_close($objConnect);
    
    
        }    
    
    else
    {
    
        $strSQL = "SELECT * FROM UserAddedRecord WHERE user_id='$id'";
        $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
        $Num_Rows = mysql_num_rows($objQuery);
    
        $Per_Page = 2;   // Per Page
    
        $Page = $_GET["Page"];
        if(!$_GET["Page"])
        {
            $Page=1;
        }
    
        $Prev_Page = $Page-1;
        $Next_Page = $Page+1;
    
        $Page_Start = (($Per_Page*$Page)-$Per_Page);
        if($Num_Rows<=$Per_Page)
        {
            $Num_Pages =1;
        }
        else if(($Num_Rows % $Per_Page)==0)
        {
            $Num_Pages =($Num_Rows/$Per_Page) ;
        }
        else
        {
            $Num_Pages =($Num_Rows/$Per_Page)+1;
            $Num_Pages = (int)$Num_Pages;
        }
    
    
        $strSQL .=" order  by id DESC LIMIT $Page_Start , $Per_Page";
        $objQuery  = mysql_query($strSQL);
    
    
    
        ?>
        <table width="600" border="1">
          <tr>
            <th width="50"> <div align="center">#</div></th>
            <th width="91"> <div align="center">ID </div></th>
            <th width="198"> <div align="center">First Name </div></th>
            <th width="198"> <div align="center">Last Name </div></th>
            <th width="250"> <div align="center">Mobile Company </div></th>
            <th width="100"> <div align="center">Cell </div></th>
            <th width="100"> <div align="center">Workphone </div></th>
            <th width="100"> <div align="center">Group </div></th>
          </tr>
        <?
    
    echo "<form name='form1' method='post' action=''>";
    
        while($objResult = mysql_fetch_array($objQuery))
        {
    
    
    echo "<tr>";
       echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>";
       echo "<td>$objResult[addedrec_ID] </td>";
       echo "<td>$objResult[FirstName]</td>";
       echo "<td>$objResult[LastName] </td>";
       echo "<td>$objResult[MobileCompany] </td>";
       echo "<td>$objResult[Cell] </td>";
       echo "<td>$objResult[WorkPhone] </td>";
       echo "<td>$objResult[Custgroup] </td>";
    
    echo "</tr>";
    
        }
    
    
    echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">";
    
    if($_POST['delete']) // from button name="delete"
         {
    $checkbox = $_POST['checkbox']; //from name="checkbox[]"
             $countCheck = count($_POST['checkbox']);
    
    for($d=0;$d<$countCheck;$d++)
             {
                 $del_id  = $checkbox[$d];
    
    $sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id";
    
    $result2=mysql_query($sql);
    
             }
                 if($result2)
             {    
                     header('Location: customer-adddata.php');
                 }
                 else
                 {
    echo "Error: ".mysql_error();
                 }
         }
    
    echo "</form>";
    
        ?>
        </table>
        <br>
        Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
        <?
        if($Prev_Page)
        {
               if($_GET["txtFirstName"] == "")
                          {
            echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtLastName=$_GET[txtLastName]'><< Back</a> ";    
                          }
    
                else
                          {
            echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtFirstName=$_GET[txtFirstName]'><< Back</a> ";
                          }
    
        }
    
        for($i=1; $i<=$Num_Pages; $i++){
            if($i != $Page)
            {
    
                echo "[ <a href='$_SERVER[sCRIPT_NAME]?Page=$i&txtFirstName=$_GET[txtFirstName]'>$i</a> ]";    
    
            }
            else
            {
                echo "<b> $i </b>";
            }
        }
        if($Page!=$Num_Pages)
        {
                  if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "")
                               {
                    echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]'>Next>></a> ";    
                               }
                  else if($_GET["txtFirstName"] == "" )
                               {
                echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]'>Next>></a> ";    
                               }
                  else
                               {
                    echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]'>Next>></a> ";    }
                           }
        
        mysql_close($objConnect);
    
    
    
    }
    
    
    ?>
    </body>
    </html>

     

    Can I know how to solve this problem?

    Thanks in advanced.

  16. If you are not passing $groupnumber the the secondary pagination script on the next page loads,then yes, that is the problem. The easiest solutin would be to probably add the groupnumber to the pagination links on the secondary page.

     

    Thanks for your reply .

    I tried to look at my scripts again and again , but I have really no idea how to pass the groupnumber to next page load...?

     

    Here is my code (not yet complete)

    <?
    
    $groupnumber = $_GET['id'];
    
    $strSQL = "SELECT * FROM esp WHERE Groupnumber='$groupnumber'";
    $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
    $Num_Rows = mysql_num_rows($objQuery);
    
    $Per_Page = 2;   // Per Page
    
    $Page = $_GET["Page"];
    if(!$_GET["Page"])
    {
    	$Page=1;
    }
    
    $Prev_Page = $Page-1;
    $Next_Page = $Page+1;
    
    $Page_Start = (($Per_Page*$Page)-$Per_Page);
    if($Num_Rows<=$Per_Page)
    {
    	$Num_Pages =1;
    }
    else if(($Num_Rows % $Per_Page)==0)
    {
    	$Num_Pages =($Num_Rows/$Per_Page) ;
    }
    else
    {
    	$Num_Pages =($Num_Rows/$Per_Page)+1;
    	$Num_Pages = (int)$Num_Pages;
    }
    
    
    $strSQL .=" order  by id DESC LIMIT $Page_Start , $Per_Page";
    $objQuery  = mysql_query($strSQL);
    
    
    
    
    
    ?>
    <table width="600" border="1">
      <tr>
    	<th width="50"> <div align="center">#</div></th>
    	<th width="91"> <div align="center">ID </div></th>
    	<th width="91"> <div align="center">Groupnumber </div></th>
    	<th width="198"> <div align="center">Message </div></th>
    	<th width="198"> <div align="center">Create on </div></th>
      </tr>
    <?
    
    echo "<form name='form1' method='post' action=''>";
    
    while($objResult = mysql_fetch_array($objQuery))
    {
    
    
    echo "<tr>";
       echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[id]\"></td>";
       echo "<td>$objResult[id] </td>";
       echo "<td>$objResult[Groupnumber]</td>";
       echo "<td>$objResult[Message] </td>";
       echo "<td>$objResult[mylocaltime] </td>";
    
    
    
    
    echo "</tr>";
    
    }
    
    
    
    
    echo "</form>";
    
    ?>
    </table>
    <br>
    Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
    <?
    if($Prev_Page)
    {
               if($_GET["txtFirstName"] == "")
                          {
    	echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtLastName=$_GET[txtLastName]'><< Back</a> ";	
                          }
    
                else
                          {
    	echo " <a href='$_SERVER[sCRIPT_NAME]?Page=$Prev_Page&txtFirstName=$_GET[txtFirstName]'><< Back</a> ";
                          }
    
    }
    
    for($i=1; $i<=$Num_Pages; $i++){
    	if($i != $Page)
    	{
    
    		echo "[ <a href='$_SERVER[sCRIPT_NAME]?Page=$i&txtFirstName=$_GET[txtFirstName]'>$i</a> ]";	
    
    	}
    	else
    	{
    		echo "<b> $i </b>";
    	}
    }
    if($Page!=$Num_Pages)
    {
                  if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "")
                               {
    	        echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]'>Next>></a> ";	
                               }
                  else if($_GET["txtFirstName"] == "" )
                               {
    		echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]'>Next>></a> ";	
                               }
                  else
                               {
    	        echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]'>Next>></a> ";	}
                       }
    
    mysql_close($objConnect);
    
    
    
    
    
    ?>
    

     

    So...should I add it somewhere....here??

    	if($Page!=$Num_Pages)
    {
                  if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "")
                               {
    	        echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]'>Next>></a> ";	
                               }
                  else if($_GET["txtFirstName"] == "" )
                               {
    		echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]'>Next>></a> ";	
                               }
                  else
                               {
    	        echo " <a href ='$_SERVER[sCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]'>Next>></a> ";	}
                       }
    

     

     

  17. Hi all .

    I have a script , which will display the records from sql . If user wish to view more details of the record , they can click view .

     

    eeee.jpg

     

          echo "<td>$objResult[Message] </td>";
       echo "<td>$objResult[mylocaltime] </td>";
       echo '<td><a href="historydetails.php?id=' . $objResult[Groupnumber] . '">View</a></td>';

     

    Then it will link to a page which will display more details according to the Groupnumber .

    Which will display 2 records per page .

     

    cccc.jpg

     

    <?
    
    $groupnumber = $_GET['id'];
    
    $strSQL = "SELECT * FROM esp WHERE Groupnumber='$groupnumber'";
    $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
    $Num_Rows = mysql_num_rows($objQuery);
    
    $Per_Page = 2;   // Per Page
    
    $Page = $_GET["Page"];
    if(!$_GET["Page"])
    {
    	$Page=1;
    }
    
    $Prev_Page = $Page-1;
    $Next_Page = $Page+1;
    
    $Page_Start = (($Per_Page*$Page)-$Per_Page);
    if($Num_Rows<=$Per_Page)
    {
    	$Num_Pages =1;
    }
    else if(($Num_Rows % $Per_Page)==0)
    {
    	$Num_Pages =($Num_Rows/$Per_Page) ;
    }
    else
    {
    	$Num_Pages =($Num_Rows/$Per_Page)+1;
    	$Num_Pages = (int)$Num_Pages;
    }
    
    
    $strSQL .=" order  by id DESC LIMIT $Page_Start , $Per_Page";
    $objQuery  = mysql_query($strSQL);
    
    ?>

     

    But when I click next to view the third record , then the table will become blank .

     

    bbbb.jpg

     

    Is it because when I click to next page , the $groupnumber  is no longer getting the data from $_GET['id'] ?

    Or is there any other problem?

     

    Thanks for every reply .

     

  18. Hi all , here is a question about a disabled button .

     

    If I have a button:

    <input id='submit' type='submit' disabled='disabled' value='submit'>

     

    Is it possible to change the "disabled=true" through php function ? such as

     

    function change_button(){
    
    echo "<script language=\"javascript\">";
    
    echo "document.getElementById('submit').disabled=true;"; 
    
    echo "</script>";
    
    }
    
    

     

    I tried it , not working...is this function possible or have I make any mistake ?

    Thanks for every reply .

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