Jump to content

Naps

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Naps's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi all, thank you for the replies. @mikosiko many thanks for your info and suggestion! I have successfully amended the code as per your link and advice. Line 32 has now been amended to: $num = mysqli_affected_rows($dbc);
  2. Hello, I am still quite new to php and am currently working with mysqli to update a database. When passing data from one script to another in order to update the database I am having the following error printed occur: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in add_news.php on line 32 the code on line 32 is: $num = mysqli_num_rows($r); The database however does update fine with content I provide. I just can't figure out why I am getting this message every time even though the database updates ok. The reason I am running the code $num = mysqli_num_rows($r); is to enable to php code to verify that the database has been updated via the returned row. Could anyone explain why this is happening? Please find my code below: <? require_once ('../mysqli_connect.php'); include ('header.html'); if (isset ($_POST['title']) && (isset ($_POST['content']) && (isset ($_POST['date'])))) { $title = mysqli_real_escape_string($dbc, $_POST['title']); $content = mysqli_real_escape_string($dbc, $_POST['content']); $date = mysqli_real_escape_string($dbc, $_POST['date']); } else { echo "You have accessed this in error"; include ('footer.html'); exit; } $q = "INSERT INTO content VALUES (NULL,'$title', '$content', '$date')"; $r = mysqli_query($dbc, $q); $num = mysqli_num_rows($r); if ($num > 0) { echo '<h2>News Added<h2>'; } else { echo '<h2>Error</h2>'; echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } include ('footer.html'); ?> Edit: I should add that the database consists of the following 4 columns: 1. id (auto increment) 2. title 3. content 4. date
  3. Kiken thanks, that is exactly what I was getting at. Thank you all for your input!
  4. Thanks for the further info kicken and scootach. I will try to elaborate. When for example when you create an array: $array = array(1, 2, 3, 4, 5); My understanding is that it’s values will be automatically assigned to the keys as follows: [edit : auto formatted wrong!] [0] 1 [1] 2 [2] 3 [3] 4 [4] 5 I am wondering what happens in that second part of the multidimensional array ‘a’ => array(‘b’ => 1, ‘c’) How would the value c be accessed? Or is c a key containing nothing?
  5. *edit Thanks AyKay47 what? I meant to say would 'c' be assigned to the aplhabetical key of 'c' or for example '1' 'a' => array( 'b' => 1, 'c'
  6. I am looking at the code below: $array = array( array( 1, 2 ), 'a' => array( 'b' => 1, 'c' ) ); Is this an example of a multidimensional array? If so how would I access the value of 1 from key b? Also would the next line ('c') be automatically assigned to the asociative key of c?
  7. Thanks for the quick response and explanation guys, I understand now.
  8. I am trying to understand why the following code outputs the value of 4 (it is part of a PHP quiz question). I know that array_diff will compare one array with another and return the result but I just don't understand what is going on with the code below: <?php $a = array(1,2,4,; $b = array(0,2,4,6,8,10); echo count (array_merge(array_diff($a, $b), array_diff($b, $a))); //prints 4 ?> Would someone be able to walk me through it?
  9. Naps

    Printf Query

    Thanks guys, much appreciated.
  10. Naps

    Printf Query

    Thanks PFMaBiSmAd, I am still curious though as to why when $mystring is echoed after $mystring = printf('%.1f', 1.2); it results in 3. Do you know why this is?
  11. Quick question regarding the printf function. I understand that printf will print a formatted string for example: $mystring = printf('%.1f', 1.2); //Will output 1.2 However I don't understand why if I then print $mystring the result is 3 Example: $mystring = printf('%.1f', 1.2); //prints 1.2 echo "<br><br>"; echo $mystring //Prints 3 Please could someone explain how this works?
  12. Wow thats great I understand now, thanks for the quick response David!
  13. I am trying to work out why the answer to a PHP quiz question is what it is. The code below prints out: b,c,A,B,C, I just can't seem to get my head round how it works, would anyone be able to talk me through it quickly? Code: <?php class Magic { public $a = "A"; protected $b = array("a" => "A", "b" => "B", "c" => "C"); protected $c = array (1,2,3); public function __get($V) { echo "$V,"; return $this->b[$V]; } public function __set($var, $val) { echo "$var: $val,"; echo $this->$var = $val; } } $m = new Magic(); echo $m->a . "," . $m->b . "," . $m->c . ","; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.