mardi 20 septembre 2016

i have created a form where the data will first be selected using paginate also

hey guys i have created a register page and then to update that page i have designed another page that will first show all the values and then will update them using update query but i m having problem updating my checkbox option i have created an implode for it and also validated the checkbox but its showing this error " Notice: Array to string conversion"

please check my code this is the register update

    <title>Register Update</title>
<?php
//error_reporting(0);
function __autoload($classname)
{
include "$classname.php"; 
}
$obj = new connect();
$st=$obj->con();

if (isset($_POST['sub'])) 
{
$upd= new update();
$upd->updatedata($_POST);
}


$start=0;
$limit=1;
$id="";
if(isset($_GET['id']))
{
$id=$_GET['id'];
$start=($id-1)*$limit;
}
$qry = "select * from register";
$run = mysqli_query($st,$qry);
$row = mysqli_fetch_assoc($run);
 {
 $g = $row['gen'];
 $l = $row['lang'];
}


$query=mysqli_query($st,"select * from register LIMIT $start, $limit");
//echo "<ul>";
while($query2=mysqli_fetch_assoc($query))
{
    //print_r($query2);
echo "<form method='POST' action='Register_Update.php'>";
echo "<table>";
?>

<p><input type="hidden" name="sid" value=<?php echo $query2['id']; ?>"></p>
<tr>
<td>
First Name:
</td>
 <td><input type="text" name="uname" value="<?php echo $query2['uname']; ?>"></td>
</tr>
<tr>
<td>Password:</td>
    <td><input type="password" name="pwd" value="<?php echo $query2['pwd']; ?>"></td>
</tr>
<tr>
<td>Email Id:</td>    
<td><input type="text" name="emailid" value="<?php echo $query2['emailid']; ?>"
</td>
</tr>
<tr>
<td>Radio Button: Are you male or female?</td>
    <?php
    if ($g == "male"){
echo "<td><input type='radio' name='gen' value='Male' id='gen' checked> Male <input type='radio' name='gen' value='Female' id='gen'> Female </td>";
 }
 else
 {
 echo "<td><input type='radio' name='gen' value='Male' id='gen'> Male <input type='radio' name='gen' value='Female' id='gen' checked> Female </td>";
 }
    ?>
</tr>
<tr>    
<td>Check Box: Check the languages you know?</td>
<td><?php
    $lang=explode(',',$l); 
    //print_r($lang);
        if(in_array('Cricket', $lang))
            echo '<input type="checkbox" name="lang[0]" value="Cricket" checked>Cricket';
        else
            echo '<input type="checkbox" name="lang[0]" value="Cricket">Cricket';
        if(in_array('Basketball', $lang))
            echo '<input type="checkbox" name="lang[1]" value="Basketball" checked>Basketball';
        else
            echo '<input type="checkbox" name="lang[1]" value="Basketball">Basketball';

        if(in_array('Hockey', $lang))
            echo '<input type="checkbox" name="lang[2]" value="Hockey" checked>Hockey';
        else
            echo '<input type="checkbox" name="lang[2]" value="Hockey">Hockey'."<br>";  
    ?>   
</td>
</tr>
<tr>
<td>Mobile No:</td>
<td><input type="text" name="mobile" value="<?php echo $query2['mobile']; ?>"
</td>
</tr>
<tr>
<td>10th Marks:</td>
<td><input type="text" name="marks_10" value="<?php echo $query2['10marks'];?>"
</td>
</tr>
<tr>
<td>
12th Marks:</td>
<td><input type="text" name="marks_12" value="<?php echo $query2['12marks'];?>"</td>
</tr>
<tr>
<td>
Image:</td>
<td><img src='img/<?php echo $query2['name'];?>' width='150px' height='150px'></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="submit" name="sub"><br>
</td>
</tr>
<?php

echo "<table>";
echo "</form>";
}
//echo "</ul>";

$rows=mysqli_num_rows(mysqli_query($st,"select * from register"));
$total=ceil($rows/$limit);

if($id>1)
{
echo "<a href='?id=".($id-1)."' class='button'>PREVIOUS</a>";
}
if($id!=$total)
{
echo "<a href='?id=".($id+1)."' class='button'>NEXT</a>";
}


?>
and now the update query is in different class 
<?php

class update extends connect
{

    function updatedata($rel)
    {
        $obj= new connect();    
        $obj->con();
        extract($_POST);

        $val =("update register set uname='$uname',pwd='$pwd',emailid='$emailid',gen='$gen',lang='$lang',mobile='$mobile',10marks='$marks_10',12marks='$marks_12'");
        print_r($val);
        $res=mysqli_query($this->con(),$val);
        return $res;
    }

}
?>




Aucun commentaire:

Enregistrer un commentaire