Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Getting error call to member function get_results on null. I include one file in another Why this error occur.
Here is screenshot-https://prnt.sc/wgpznd[^]

here is code-
<table border="1">
	<tr>
	<th>Id</th>
	<th>Name</th>
	<th>Email</th>
	<th>Gender</th>
	<th>Age</th>
	<th>Edit</th>
	<th>Delete</th>
	</tr> 

	<?php
	global $wpdb;
	$table= 'wp_contact_form';
	$result = $wpdb->get_results ( "SELECT * FROM $table" );

	if(!empty($result)){

	foreach ( $result as $print ) {   
		?>
	<tr>
	<td><?php echo $print->id;?></td>
	<td><?php echo $print->names;?></td>
	<td><?php echo $print->emails;?></td>
	<td><?php echo $print->gender;?></td>
	<td><?php echo $print->age;?></td>
	<td><a href="/vishal_nov/edit-form-template/?upd=<?php echo $print->id ?>" name="update">Update</a></td>
	<td>
	<input type="button" value="Delete" id="delete" data-id = "<?php echo $print->id ?>" name="delete" class="del_btn">
	</td>
	</tr>
	<?php
	}
	}
	?>
</table>


What I have tried:

Changed table name
$wpdb->prefix.'contact form'
to
$table
.(wp_contact_form is table name and $table is variable in which table name is assign).
Posted
Updated 5-Jan-21 17:27pm
v5
Comments
Richard MacCutchan 5-Jan-21 7:44am    
Look at line 25 as referred in the error message and you will be able to see which variable is null.
vishal@1 5-Jan-21 7:49am    
there is no any null variable.

Richard MacCutchan 5-Jan-21 9:13am    
Well that is what the error message states. And I am fairly sure it knows whether the variable is null or not.
Sandeep Mewara 5-Jan-21 8:22am    
It would help others to help you if you share the code related.
vishal@1 5-Jan-21 22:57pm    
I shared code above

1 solution

On line 25 of whatever script file it's talking about, you have something that looks like this:
... = someObjectName.get_results();

someObjectName is null. You and you're code are assuming something worked to build or retrieve someObjectName as you expected, but it didn't, resulting in a null value.

It's up to you to figure out why it's null.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900