Note that there are some explanatory texts on larger screens.

plurals
  1. POUndefined variables errors
    primarykey
    data
    text
    <p>So i'm working on a project and i am running to to a few mysql &amp; php errors.</p> <p>First Error : </p> <p>This is all code associated with First Error </p> <pre><code>// Database Class class Database { public $_link, $_result, $_numRows; public function __construct($server, $username, $password, $db){ $this-&gt;_link = mysql_connect($server, $username, $password) or die('Cannot Execute:'. mysql_error()); mysql_select_db($db, $this-&gt;_link); } public function disconnect(){ mysql_close($this-&gt;_link); } public function query($sql){ $this-&gt;_result = mysql_query($sql, $this-&gt;_link) or die('Cannot Execute:'. mysql_error()); $this-&gt;_numRows = mysql_num_rows($this-&gt;_result); } public function numRows() { return $this-&gt;_numRows; } public function rows(){ $rows = array(); for($x = 0; $x &lt; $this-&gt;numRows(); $x++) { $rows[] = mysql_fetch_assoc($this-&gt;_result); } return $rows; } } // Setup.php $is_set = 'false'; global $company_name, $ebay_id; if( isset($_POST['ebay_id'], $_POST['company_name']) ){ $_ebay_id = $_POST['ebay_id']; $_company_name = $_POST['company_name']; $is_set = 'true'; } else { // Silence is Golden! } $_service_database = new Database('localhost', 'root', 'password', 'chat-admin'); $_service_database-&gt;query("SELECT * FROM installs WHERE `identity` = '$mysqldb' AND `db_name` = '$mysqldb'"); if ($_service_database-&gt;numRows() == 0){ if($is_set == true){ $_service_database-&gt;query("INSERT INTO installs (ebay_id, name, db_name, identity) VALUES ('$_ebay_id', '$_company_name', '$mysqldb', '$mysqldb')"); } } else { // header("Location: index.php"); } $_service_database-&gt;disconnect(); ?&gt; &lt;form name="setup" method="post" action="&lt;?php echo $_SERVER["PHP_SELF"]; ?&gt;"&gt; &lt;input placeholder="eBay Username" type="text" name="ebay_id"&gt; &lt;input placeholder="Company Name" type="text" name="company_name"&gt; &lt;input type="hidden" name="insert" value="true"&gt; &lt;input type="submit"&gt; &lt;/form&gt; </code></pre> <p>So what this does is checks if the variables defined are in the database if they are not then when the form is submitted it inserts our values, if they are in the database it redirects to index.php, ok so i am receiving the all mighty MySQL num_rows* expects parameter 1 to be resource, boolean given ..., now i have searched everywhere and only found that the die error should solve, that is why you can see it on line 16 in the function query, now although i get the error everything still works its not really good for me to turn error reporting off so any help would be great. Also if you see undefined variables like $mysqldb they are actually set but on a different page and they are valid</p> <p>Second Error : = function made for simplicity of a templating system</p> <p>This is all associated with Second Error </p> <pre><code>function get_content_type($value){ if (strpos($value,'title:') === 0 ) { $title = explode("title: ",$value); $value = $title[1]; } else if (strpos($value,'css:') === 0 ) { $css = explode("css: ",$value); $value = $css[1]; } else if (strpos($value, 'js:') === 0 ) { $javascript = explode("js: ", $value); $value = $javascript[1]; } else { // Silence is Golden } if($value == $title[1]){ echo '&lt;title&gt;'.$value.'&lt;/title&gt;'; } else if ($value == $css[1]) { echo '&lt;link rel="stylesheet" href="'.$value.'"&gt;'; } else if ($value == $javascript[1]) { echo '&lt;script src="'.$value.'"&gt;&lt;/script&gt;'; } } // Calling get_content_type('title: Welcome to my site'); get_content_type('css: http://something.com/style.css'); get_content_type('js: http://code.jquery.com/jquery-latest.min.js'); </code></pre> <p>everything works as this outputs</p> <pre><code>&lt;title&gt;Welcome to my site&lt;/title&gt;&lt;link rel="stylesheet" href="http://somesite.com/style.css"&gt;&lt;script src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt; </code></pre> <p>Only when i set <code>error_reporting(0);</code></p> <p>The errors i get are undefined variables because obviously i'm setting one, then im unsettling that one and setting the other so eventually only 1 is true although its already outputted all of them correctly.</p> <p><strong>UPDATE</strong></p> <p>Second Error : Errors = </p> <p><code>Notice: Undefined variable: css in C:\Server\www\hidie\libs\test.php on line 19</code> <code>Notice: Undefined variable: title in C:\Server\www\hidie\libs\test.php on line 17</code> <code>Notice: Undefined variable: title in C:\Server\www\hidie\libs\test.php on line 17</code></p> <p>First Error : Errors = </p> <p>ERROR: <code>Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given</code></p>
    singulars
    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