0

Hi
i m trying to update records via array and i m getting this error ..
Notice: Uninitialized string offset: 1 in C:\wamp\www\routephp\search_results.php on line 142

 <?php
 if(isset($_GET['van'])){

  $van=$_GET['van'];
  $van = preg_replace("/[^0-9]/", '', $van);
} 
?>
<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8">
        <title>Route Database</title>        

<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript">
function delete_id(id)
{
     if(confirm('Sure To Remove This Record ?'))
     {
        window.location.href='deleteroute.php?delete_id='+id;
        header("Location: http://localhost/routephp/search_results.php?page=-1&van=Van1");
     }
}
</script>

</head>

    <body>
        <header>
            <h1>Routes Application</h1>
        </header>
<section>
<br>
<form action="keyword.php" method="get">
  <label>     
  <input type="text" name="keyword" size="40px" placeholder="Name Address Location Prl No.."/>
  </label>
  <input id="submit" type="submit" value="Search" />
</form>           
           <div>
                <h2>Van No : <?php echo $van;?></h2>
            </div>
           <table>
           <form name="form1" method="post" action="">
             <tr> 
            <td>
           <table  width=100%>

                    <th>Prl No</th>
                    <th>Day</th>
                    <th>Position</th>
                    <th>Name</th>
                    <th>Address</th>
                    <th>Location</th>




<?php

$results = "";
$page1=0; 
$letter = "";
$page="";
$cou=0; 
$rec_limit = 20;
if(isset($_GET['letter']) && strlen($_GET['letter']) == 1){
    $letter = preg_replace('#[^a-z]#i', '', $_GET['letter']);
    if(strlen($letter) != 1){
        echo "ERROR: The variable is empty.";
        exit();
    }
 } 
 $mysqli = new mysqli("localhost", "root", "root", "route");
 if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}
if ($result = $mysqli->query("SELECT * FROM route where van=$van ")) {
    $rec_count=$result->num_rows;
    //printf("Select returned %d rows.\n", $rec_count);

    /* free result set */
    $result->close();
} 

if( isset($_GET{'page'} ) )
{
   $page = $_GET{'page'} + 1;
   $offset = $rec_limit * $page ;
}
else
{
   $page = 0;
   $offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);


$sql=$mysqli->query("SELECT * from `route` where SUBSTRING(van,4,2)=$van  LIMIT $offset, $rec_limit"); 
$count=mysqli_num_rows($sql);
while($row = mysqli_fetch_array($sql, MYSQLI_USE_RESULT)){

   $prl=$row['prl_no'];
   $day=$row['day'];
   $position=$row['position'];
   $name=$row['name'];
   $address=$row['address'];
   $address2=$row['address2'];
   $van=$row['van'];
   $id=$row['id'];


   ?>  

                    <tr>

                    <td><input class='prl' name="prl[]" type="text" id="prl" value='<?php echo $prl;?>' </td>
                    <td><input class='day' name="day[]" type="text" id="day" value='<?php echo $day; ?>'</td>
                    <td> <input class='position'  name="position[]" type="text" id="position" value='<?php echo $position; ?>'</td>
                    <td> <input class='name' name="name[]" type="text" id="name" value='<?php echo $name; ?>'</td>
                    <td> <input class='name' name="address[]" type="text" id="address" value='<?php echo $address; ?>'</td>
                    <td> <input class='name' name="address2[]" type="text" id="address2" value='<?php echo $address2; ?>'</td>  




 <?php
   }
   ?>

 </tr></table>
 </tr></td>
 <tr><td><input id='submit' type='submit' name='Submit' value='Submit'></td></tr></form></table></section><br><br>   

<?php
if(isset($_POST['Submit'])){
   for($i=0;$i<$count;$i++){
     $sql1="UPDATE route SET address='$address[$i]', address2='$address2[$i]',day='$day[$i]',name='$name[$i]',position='$position[$i]',prl_no='prl[$i]' WHERE id='$id[$i]'";
     if(mysqli_query($mysqli, $sql1)){
       echo "Records were updated successfully.";}
   }
}
if( $page > 0 )
{

   $last = $page - 2;
   echo "<a href='search_results.php?page=$last&van=$van'>Last 10 Records</a> |";
   echo "<a href='search_results.php?page=$page&van=$van'>Next 10 Records</a>";
}
else if( $page == 0 )
{

   echo"<a href='search_results.php?page=$page&van=$van'>Next 10 Records</a>";
}
else if( $left_rec < $rec_limit )
{

   $last = $page - 2;
   echo "<a href='search_results.php?page=$last&van=$van'>Last 10 Records</a>";
}

 //mysql_close($mysqli);
 echo "<br>";
echo "<br><a href='search.php'>Search Form</a>";
?>

</body>
</html>

any help please

2
Contributors
4
Replies
18
Views
2 Years
Discussion Span
Last Post by asaidi
0

Hi
i did some updates but still not working

 <?php
 error_reporting(E_ALL);
ini_set('display_errors', 1);
?>

 <?php
 if(isset($_GET['van'])){

  $van=$_GET['van'];
  $van = preg_replace("/[^0-9]/", '', $van);
} 
?>
<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8">
        <title>Route Database</title>        

<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript">
function delete_id(id)
{
     if(confirm('Sure To Remove This Record ?'))
     {
        window.location.href='deleteroute.php?delete_id='+id;
        header("Location: http://localhost/routephp/search_results.php?page=-1&van=Van1");
     }
}
</script>

</head>

    <body>
        <header>
            <h1>Routes Application</h1>
        </header>
<section>
<br>
<form action="keyword.php" method="get">
  <label>     
  <input type="text" name="keyword" size="40px" placeholder="Name Address Location Prl No.."/>
  </label>
  <input id="submit" type="submit" value="Search" />
</form>           
           <div>
                <h2>Van No : <?php echo $van;?></h2>
            </div>
           <table>
           <form name="form1" method="post" action="">
             <tr> 
            <td>
           <table  width=100%>

                    <th>Prl No</th>
                    <th>Day</th>
                    <th>Position</th>
                    <th>Name</th>
                    <th>Address</th>
                    <th>Location</th>




<?php

$results = "";
$page1=0; 
$letter = "";
$page="";
$cou=0; 
$rec_limit = 20;
if(isset($_GET['letter']) && strlen($_GET['letter']) == 1){
    $letter = preg_replace('#[^a-z]#i', '', $_GET['letter']);
    if(strlen($letter) != 1){
        echo "ERROR: The variable is empty.";
        exit();
    }
 } 
 $mysqli = new mysqli("localhost", "root", "root", "route");
 if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}
if ($result = $mysqli->query("SELECT * FROM route where van=$van ")) {
    $rec_count=$result->num_rows;
    //printf("Select returned %d rows.\n", $rec_count);

    /* free result set */
    $result->close();
} 

if( isset($_GET{'page'} ) )
{
   $page = $_GET{'page'} + 1;
   $offset = $rec_limit * $page ;
}
else
{
   $page = 0;
   $offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);


$sql=$mysqli->query("SELECT * from `route` where SUBSTRING(van,4,2)=$van  LIMIT $offset, $rec_limit"); 
$count=mysqli_num_rows($sql);
while($row = mysqli_fetch_array($sql, MYSQLI_USE_RESULT)){

   $prl=$row['prl_no'];
   $day=$row['day'];
   $position=$row['position'];
   $name=$row['name'];
   $address=$row['address'];
   $address2=$row['address2'];
   $van=$row['van'];
   $id=$row['id'];


   ?>  

                    <tr>

                    <td><input class='prl' name="prl[]" type="text" id="prl" value='<?php echo $prl;?>' </td>
                    <td><input class='day' name="day[]" type="text" id="day" value='<?php echo $day; ?>'</td>
                    <td> <input class='position'  name="position[]" type="text" id="position" value='<?php echo $position; ?>'</td>
                    <td> <input class='name' name="name[]" type="text" id="name" value='<?php echo $name; ?>'</td>
                    <td> <input class='name' name="address[]" type="text" id="address" value='<?php echo $address; ?>'</td>
                    <td> <input class='name' name="address2[]" type="text" id="address2" value='<?php echo $address2; ?>'</td>  
                    <td> <input   name="address3[]" type="hidden"  value='<?php echo $address3; ?>'</td> 
                    <td> <input name="van[]" type="hidden"  value='<?php echo $van; ?>'</td>                    



 <?php
   }
   ?>

 </tr></table>
 </tr></td>
 <tr><td><input id='submit' type='submit' name='Submit' value='Submit'></td></tr></form></table></section><br><br>   
<?php
  if( !isset($address[$i]) ) $address[$i] = '' ;
      if( !isset($address2[$i]) ) $address2[$i] = '' ;
      if( !isset($day[$i]) ) $day[$i] = '' ;
      if( !isset($name[$i]) ) $name[$i] = '' ;
      if( !isset($position[$i]) ) $position[$i] = '' ;
      if( !isset($prl[$i]) ) $prl[$i] = '' ;
      if( !isset($address3[$i]) ) $address3[$i] = '' ;
      if( !isset($van[$i]) ) $van[$i] = '' ;
if(isset($_POST['Submit'])){
   for($i=0;$i<$count;$i++){

     $sql1="UPDATE route SET address='$address[$i]',address2='$address2[$i]',day='$day[$i]',name='$name[$i]',position='$position[$i]',prl_no='$prl[$i]' WHERE id='$id[$i]'";
     if(mysqli_query($mysqli, $sql1)){
       echo "Records were updated successfully.";}
   }
}
if( $page > 0 )
{

   $last = $page - 2;
   echo "<a href='search_results.php?page=$last&van=$van'>Last 10 Records</a> |";
   echo "<a href='search_results.php?page=$page&van=$van'>Next 10 Records</a>";
}
else if( $page == 0 )
{

   echo"<a href='search_results.php?page=$page&van=$van'>Next 10 Records</a>";
}
else if( $left_rec < $rec_limit )
{

   $last = $page - 2;
   echo "<a href='search_results.php?page=$last&van=$van'>Last 10 Records</a>";
}

 //mysql_close($mysqli);
 echo "<br>";
echo "<br><a href='search.php'>Search Form</a>";
?>

</body>
</html>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.