mercredi 1 avril 2015

Wordpress Custom PHP failing at wpdb object

I am trying to create a form on wordpress that automatically updates a custom table in the database. The form works with the "POST" method and calls the PHP file fine, and any code (such as echos) I enter at the beginning work fine. The problem is every time I try and use the wpdb object, the screen is just white and the code stops. It won't run anything including or past where I call wpdb. I have tried both using insert and get results and neither is working. Also, I am getting absolutely no errors in the console output even though I turned debugging on and everything.


This is my php file (which has a permission value of 755):



<?php
global $wpdb;
error_reporting(E_ALL);
echo "New Plant has been submitted.\n";

$plantname = $_POST["name"];
echo "Before";
$myrows = $wpdb->get_results( "SELECT * FROM wp_users" );
exit( var_dump( $wpdb->last_query ) );
echo " After: " . $myrows;
$wpdb->insert('Plants',array('PlantName' => $plantname),array('%s'));
echo $plantname . " has been submitted.";
?>

</body>
</html>


Also, this is my form:



&nbsp;

<form action="cgi-bin/add_plant.php" method="post">
Plant Name: <input name="name" type="text" />

Lowest Ideal Temperature: <input name="IdealTempLow" type="text" />

Highest Ideal Temperature: <input name="IdealTempHigh" type="text" />

Lowest Ideal pH: <input name="IdealpHLow" type="text" />

Highest Ideal pH: <input name="IdealpHHigh" type="text" />

Lowest Ideal Humidity Level: <input name="IdealHumLow" type="text" />

Highest Ideal Humidity Level: <input name="IdealHumHigh" type="text" />

Lowest Ideal Moisture Level: <input name="IdealMoistLow" type="text" />

Highest Ideal Moisture Level: <input name="IdealMoistHigh" type="text" />

<input type="submit" />
</form>&nbsp;


By the way, I know I need to sanitize my code, but for right now I just want to be able to get it to work in the first place. I know that nothing is getting added because I logged in to PHPMyAdmin and there is nothing in the table. I also tried getting results from the standard wp tables, but that failed as well.





Aucun commentaire:

Enregistrer un commentaire