Arun Arun - 1 year ago 152
MySQL Question

Getting Illegal string offset Warning while fetching data

$cq = "SELECT * FROM salescard WHERE custid = '$custid'";
$rq = mysqli_query($conn,$cq);
if ($c = mysqli_fetch_array($rq, MYSQLI_ASSOC)) {

$edate =$c['expdate'];
$ono = $c['orderno'];
$cno = $c['cardno'];
$c = $c['cvv'];
$email = $c['email'];
$no = $c['no'];

}


I am fetching data from the table and echoing the variables fetched above.

All the variables are echoed properly expect $email and $no.

Warning: Illegal string offset 'email' in
C:\xampp\htdocs\erp\admin\viewsales\card.php on line 94

Warning: Illegal string offset 'no' in
C:\xampp\htdocs\erp\admin\viewsales\card.php on line 95


All i know is this warning has something to do with variable being defined where an array is expected.

Only two variables are showing the error and rest are fetching properly
How can i make this work properly?

EDIT

i surely have these two columns in my salescard table and i was able to store data into it from another form.

$email = $c['email'];
$no = $c['no'];


These are the lines 94 and 95

And i want to display the data here

<div class="form-group half left clear">
<input type="text" value="<?php echo $email;?>" name="email" />
<label class="control-label" for="input">Email Address</label><i
class="bar"></i>
</div>

<div class="form-group half right">
<input type="text" value="<?php echo $no;?>" name="no" />
<label class="control-label" for="input">Contact number</label><i
class="bar"></i>
</div>

Answer Source

You overwrite $c in line 93, and make it a string.

$c = $c['cvv'];

Should be:

$cvv = $c['cvv'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download