Jump to content

dani33l_87

Members
  • Posts

    38
  • Joined

  • Last visited

Everything posted by dani33l_87

  1. I have hard time to understand what is a PHP Prepared Statement? and how can barricades SQL injection ? On the internet I don`t found a good explanation?
  2. I have this questions Is there a connection between SQL multi table query and PK and FK? and this answer SELECT country.Name, countrylanguage.Language FROM country, countrylanguage WHERE country.Code = countrylanguage.CountryCode But I need to explain it and I don t understand very good databse. Someone know an answer/explanation easy to remember?
  3. Hi, How can I copy the value from a column (table nw_items) to other table (nw_products). or even better, into a column (in nw_products) that already exists and has all values set to 0 ? I tried this INSERT INTO nw_products (ID_PLAYER) SELECT nw_items.ID_OWNER FROM nw_items; and got this error :#1062 - Duplicate entry '0-0' for key 'PRIMARY'
  4. ok, I will try again... I have a database named operation Inside the databse I have two tables (modules) mn_news and mn_money For each data inside mn_news need to add a new field/column (there are also ID, NAME, etc ) isBlog that contain the TYPE small(1) with the VALUE 0 also to add a other field/collumn OwnerType type enum , value to be player The second part I also don t understand because I supose to put the same value according with some ID or something. For the moment I will try to fix the first part.
  5. Hi, Inside the databse I have the module mn_news. How I supose to add in a nicely way a new field for the entire module mn_news with a new column isBlog TYPE small(1) and DEFAULT '0' NOT NULL". Also I want to change the value of the collumn OwnerType type enum , value to be "player" in mn_news Other thing that maybe is more complicated is that inside of the mn_news I have the column Credit with different kind of value and I want to have the same values inside the other module mn_money ,column Money. I found somenting one google but they are very different answers and I don t want to mess with the databse. Somebody can help me? Rgds.
  6. Your statement will add new artist in the database? $stmt = $mySqli->prepare("INSERT INTO artist (artist_id, artist_name, place_of_birth) VALUES (?, ?, ?)"); Fatal error: Call to a member function bind_param() on a non-object instead of the original one if ($stmt = $mySqli->prepare("SELECT artist_id, artist_name, place_of_birth FROM artists WHERE ARTIST_NAME =?")) {
  7. Andy you are right. I have added new fields ID <input type = "text" name = "artist_id" value = ""> NAME <input type = "text" name = "artist_name" value = ""> PLACE <input type = "text" name = "place_of_birth" value = ""> and also make the post: $stmt = $_POST["artist_id"]; $stmt = $_POST["artist_name"]; $stmt = $_POST["place_of_birth"]; I don t understand how this suppose to work and the bind parameters (I skip some classes)
  8. Hi, I have the next exercise to make it and I need some help. "The following getArtist.php script is generating a prepared statement object, named: stmt. In the actual script only theArtisName is bound into the statement in the “?” place. The script on the next page has getArtist.php as its action property. Your task now is to change the two scripts to enable a full insert of all fields in the artist table. I.e. the form has to have text fields for all relevant artist data." <?php $theUserName = $_POST["userName"]; print "<h3>Hello user: $theUserName!</h3>"; $thePassword = $_POST["password"]; $theArtistName = $_POST["artistName"]; print "<h3>You are searching data for: $theArtistName!</h3>"; $mySqli = new Mysqli('localhost', $theUserName, $thePassword, 'cd_inventory'); /* check connection by means of the connect_errno property */ if ($mySqli->connect_errno) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { echo 'Now connected to MySQL'; echo '<br><br>'; } /* Spawn a MySQLi_STMT class object containing the SQL statement */ if ($stmt = $mySqli->prepare("SELECT artist_id, artist_name, place_of_birth FROM artists WHERE ARTIST_NAME =?")) { /* bind parameters for ? marker(s) */ $stmt->bind_param("s", $theArtistName); // s for string /* execute query */ $stmt->execute(); /* bind result variables */ $stmt->bind_result($artist_id, $artist_name, $place_of_birth); /* fetch values */ while ($stmt->fetch()) { printf("Artist: %s %s %s \n", $artist_id, $artist_name, $place_of_birth); } // else emit an error message /* close statement */ $stmt->close(); } /* close connection */ $mySqli->close(); ?> Second code: <html> <head> <title>Input Username and password</title> </head> <body> <h1>Input Username and password</h1> <form method = "post" action = "getArtist.php"> Please type your username: <input type = "text" name = "userName" value = ""> <br> Please type your password: <input type = "password" name = "password" value = ""> <br> Please type the artist you are looking for: <input type = "text" name = "artistName" value = ""> <br> <input type = "submit" value = "Submit"> </form> </body> </html>
  9. <?php class Person { private $name; function __construct($name) { $this->name = $name; } function setName($newName) { $this->name = $newName; } function getName() { return $this->name; } } $brian = new Person("Brian Mischook"); // create object $name = $brian->getName(); // get name variable from object echo "Brian's full name: " . $name . '<br>'; // Need to add the code here. It must check the returned name length and print at logic output according to the name length ?> By using functions like strlen(), stripos() and substr(), I need to add code to the script that checks the length of the name property and if it is more than 10 characters long, the name property must be set to only be the first name. The class must not be changed. Exemple: Brian Full Name: Brain Mischoock Braian First Name: Brain Some suggestions?
  10. Hi, I am working to an exercise and I have a little problem. Make a script that populates a PHP array of 10 times 10 cells. The value in each cell must be the array indexes referencing that cell, multiplied together. e.g. 7*4 = 28 and 0*9=0. Hint: Make you script use e.g. a while loop inside a while loop to fill the array. Now write a second script part, in the same script file, that makes the PHP array being printed in a nice formatted way. For example by using HTML table tags. Again make the script use some kind of loop inside a loop to print the table and take out the values from the array. I make the first part and almost I finish the second but I have some problem with that, I don t understand so well how this suppose to work. This suppose to be the final result: http://zuscience.com/php.png This is the code almost finish but I don t understand how to fix the last part to make it work. <?php //File array section $yStart = 0; $y = $yStart; while( $y < (10 + $yStart)) { $x = 0; while ( $x < 10) { $myArray[$x][$y] = $x * $y; //array entry $x++; } $y++; } //Print Section $x = 0; echo '<table border="1">'; echo '<tr>'; //print vertical index row echo '<td>'; echo 'Index'; echo '<td>'; while ( $x < 10 ){ $x++; } echo '</tr>'; $y = 0; while ( $y < 10 ) { echo '<col with= "30">'; $x = 0; echo '<tr><td>' . $y . '</td>'; //print horisontal index while ( $x < 10) { echo '</td>' $myArray[$x][$y]; //cell content $x++; } echo '</tr>' $y++; } ?> Some sugestions what I am doing wrong?
×
×
  • 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.