Note that there are some explanatory texts on larger screens.

plurals
  1. PODatabase Table Won't Update with Mysqli
    primarykey
    data
    text
    <p>So I have a problem with updating a mysql table via mysqli in php.</p> <p>The database connection and class:</p> <pre><code>&lt;?php class testDB extends mysqli { private static $instance = null; private $user = "tester"; private $pass = "tester01"; private $dbName = "testdb"; private $dbHost = "localhost"; public static function getInstance() { if (!self::$instance instanceof self) { self::$instance = new self; } return self::$instance; } public function __clone() { trigger_error('Clone is not allowed.', E_USER_ERROR); } public function __wakeup() { trigger_error('Deserializing is not allowed.', E_USER_ERROR); } private function __construct() { parent::__construct($this-&gt;dbHost, $this-&gt;user, $this-&gt;pass, $this-&gt;dbName); if (mysqli_connect_error()) { exit('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } parent::set_charset('utf-8'); } public function verify_credentials ($username, $password){ $username = $this-&gt;real_escape_string($username); $password = $this-&gt;real_escape_string($password); $result = $this-&gt;query("SELECT 1 FROM users WHERE user_username = '" . $username . "' AND user_password = '" . $password . "'"); return $result-&gt;data_seek(0); } public function get_vitae() { return $this-&gt;query("SELECT * FROM vitae"); public function update_vitae($text, $id) { $text = $this-&gt;real_escape_string($text); $this-&gt;query("UPDATE vitae SET vitae_text=".$text." WHERE vitae_id = ".$id); } } ?&gt; </code></pre> <p>Here's the page code:</p> <p>Above the header we check the login by making sure there is a session started; then import the database class and the rest is called upon resubmitting the form to this same page:</p> <pre><code>&lt;?php session_start(); if (!array_key_exists("username", $_SESSION)) { header('Location: index.php'); exit; } require_once("includes/db.php"); $vitae_empty = false; if ($_SERVER['REQUEST_METHOD'] == "POST") { if ($_POST['text'] == "") { $vitae_empty = true; } else if ($_POST["text"]!="") { testDB::getInstance()-&gt;update_vitae($_POST["text"], $_POST["id"]); header('Location: manage.php' ); exit; } } ?&gt; </code></pre> <p>In the body (the header and the rest of the html is imported via a 'require_once'):</p> <pre><code> &lt;section&gt; &lt;div class="grid_3 header_line"&gt;&lt;h2&gt;Update for CV&lt;/h2&gt;&lt;/div&gt; &lt;div class="grid_3"&gt; &lt;?php $result = testDB::getInstance()-&gt;get_vitae(); $vitae = mysqli_fetch_array($result); ?&gt; &lt;form name="editvitae" action="editvitae.php" method="POST"&gt; &lt;textarea name="text" rows="50" cols="100"&gt;&lt;?php echo $vitae['vitae_text'];?&gt;&lt;/textarea&gt;&lt;br/&gt; &lt;?php if ($vitae_empty) echo "Please enter some text.&lt;br/&gt;";?&gt; &lt;input type="hidden" name="id" value="&lt;?php echo $vitae["vitae_id"];?&gt;" /&gt; &lt;br/&gt; &lt;input type="submit" name="savevitae" value="Save Changes"/&gt; &lt;/form&gt; &lt;/div&gt; &lt;div class="grid_3"&gt; &lt;p&gt;&lt;a href="manage.php"&gt;&amp;lsaquo; back to management consol&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;/section&gt; </code></pre> <p>After the 'body' tag:</p> <pre><code>&lt;?php mysql_free_result($result);?&gt; </code></pre> <p>As you can see this pulls the 'vitae' text from the database then loops it to the same page with changes to update the table. It also check's to see that the 'text' box is not empty.</p> <p>This code works in another application; I'm not understanding why it won't work here. AND before you start warning me about injection and security I have stripped most of it out trying to find the problem with the update. It WILL go back in once I can figure that out.</p> <p>I have tried stripping the text check; different variable names; dumping the post values into an array before updating the database; putting the post values into static variables; checking all my spellings etc...</p> <p>I'm missing something and I feel like it's going to be simple.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload