PHP - MySQL

Discuss coding issues, and scripts related to PHP and MySQL.

  1. » mluci12
    Hello!How can i sent am email after mysql insert?
    <?php // connect to the  tests  database $conn  = new ...
    Last post » Admin
    Hello
    Just add the code with mail() function in the if() that performs and checks the query....


  2. » mluci12
    Hello admin
    I have next php code
       foreach( $datas  as  $row ) {         ...
    Last post » Admin
    Hi
    There is a second "echo" mixed in tne echo content.
    Try:
    echo  '<tr>  <td>' . $row [ 'ID' ]....


  3. » PloMar
    Hello
    I use the following PHP code to get the image data from an external URL.
    $url  =  $_GET [ 'url' ]; $img  = ...
    Last post » nadera
    problem solved... it works like a charm ... thank you very much dear <3


  4. » frecia18
    <?php     mysql_connect ( 'localhost' ,  'root' );      mysql_select_db ( 'inventory' ); if(isset(...


  5. » Marius
    Hello
    How can I replace part of a string with stars in php?
    For example: "marplo" to turn into "m***lo".
    Last post » Admin
    Hello
    Try the function from this example:...


  6. » Marius
    Hello
    Is it possible to rewrite /replace a protected method in the extended class, in php?
    Last post » Admin
    Hello
    Yes, you can change the protected attribute of the method in the extended class:
    class  A  {...


  7. » Marius
    Hello,
    I have a form to upload audio files on server. The name of the file, path and size is stored into a table in database.
    The script is working,...
    Last post » Admin
    Hy,
    You can get the duration of an audio /video file with JavaScript. Then, with JS you can add the duration into an input field in the form for...


  8. » Marius
    Hello
    I have this script that gets the content from an URL address and outputs it to the browser.
    $url  =  'the_url_address' ;...
    Last post » Admin
    Hi,
    You can use the finfo class and the buffer() method to get the mime-type of a string-content.
    Here is an example:
    $url  =  ' ;...


  9. » Marius
    Hello
    What header() I need to use to output a mp3 file with php so the mp3 to play within the browser?
    Last post » Admin
    Hi
    You can use this header() in php to properly output a mp3 audio file.
    header ( 'Content-Type: audio/mpeg' ); 
    - For a complete...


  10. » Marius
    Hello
    I have a string with these numbers: "3 9 15 23 9 6 8 5", and I want to get a string with reversed order of those numbers.
    To get this...
    Last post » Admin
    Hello
    See the code from this example. Put the numbers into an array, reverse the array items, then put the reversed numbers into a string....


  11. » Marius
    Hello
    I want to make a Select SQL query that sorts ascending by a column, but the rows with NULL values to come last.
    This is the query I use (but...
    Last post » Admin
    Hello
    You could use the ISNULL() function:
    $sql  = ...


  12. » PloMar
    Hello,
    Let say I have records into a MySQL table with IDs: 3, 5, 8, 9, 13; and I want to be able to go from one to another by navigation via...
    Last post » MarPlo
    Hi,
    Try this SQL code that combines two sql statements into one.
    SELECT * FROM table_name
    WHERE (
    id = IFNULL((SELECT MIN(id) FROM table_name...


  13. » PloMar
    How can I add a method to a stdClass object?
    For example I try this code:
    $ob  = new  stdClass ; $ob -> prop  =  'val' ;...
    Last post » Admin
    You cannot dynamically add a method to the stdClass and execute it in the normal way.
    But you can assign that object method to a variable, then...


  14. » PloMar
    I have the following object in php:
    $ob  =  new stdClass ; $ob -> name  =   'some-name' ; $ob -> email  =   'email-address' ; $ob -> site ...
    Last post » Admin
    Hi,
    Just use the: (array) $objectName construction.
    $ob  = new  stdClass ; $ob -> name  =  'some-name' ; $ob ->...


  15. » PloMar
    Hello,
    I have a script that the user can upload and delete images on server. The issue I am running into is that when the user changes his image on...
    Last post » Admin
    Hi,
    The simpliest way to force a refresh /reload of that image after upload is to add an unique " ?hash " to the URL /SRC adress...


  16. » Marius
    Hi,
    I have this php exercise:
    - Calculate the final sum of the digits of a number, till get a number with one digit.
    For example:
    $nr = 458;
    // the...
    Last post » sandy
    Another example with a recursive function:
    <?php function add ( $nr )   {   $nr  =  array_sum ( str_split ( $nr ));   if ( strlen ( $nr )   ==  1...


  17. » PloMar
    Hello,
    I have the following method to update data in MySQL table.
    public function update ( $table ,  $rows ){   foreach ( $rows as $k  =>  $v )  ...
    Last post » Admin
    Hi,
    Try this code:
    public function update ( $table ,  $rows ){   $set  =   [];   foreach ( $rows as $k  =>  $v )   {     $set []...


  18. » Marius
    Hi
    I have a table in mysql database, with 3 columns: id | title | description .
    The id column is INT AUTO_INCREMENT .
    Does anyone know how to select...
    Last post » sandy
    Hi,
    If you're using PDO, use PDO::lastInsertId();// To Display the last Inserted value
    If you're using MySql, use mysql_insert_id();// To Display the...


  19. » PloMar
    Hi,
    I have the following code that uses DOMDocument to get some data from a html string in PHP.
    // string with HTML content $strhtml  =  ...
    Last post » MarPlo
    Hi,
    The nodeValue attribute gives you the combined text of all the child nodes.
    To get the text value of the first child text node only, use:...


  20. » PloMar
    I wrote a PHP code to insert some data in to MySQL database. I want to display a message indicating whether the records are successfully added to the...
    Last post » sandy
    try {        $db_user  =  'root' ;           ...


  21. » PloMar
    Hello,
    I have the following code that saves on the server a png image generated with php.
    In that image I add a text (using imagettftext()), but...
    Last post » MarPlo
    Hi,
    You can use the imagettfbbox() function, it returns an array with 8 elements representing four points making the bounding box of the text.
    Using...


  22. » PloMar
    Hello,
    How can I save the content of the current php page into a html file, only after a form is submitted?
    For example, I have the following code...
    Last post » MarPlo
    If you want to save the page content after a form is submitted, another way is to add the page code into a hidden field in that form, with JavaScript...


  23. » PloMar
    I have the following Select in MySQL:
    $sql = "SELECT * FROM table_1 WHERE rank = 2 AND id IN(2, 5, 8)";
    But the IDs (2, 5, 8, ...) must...
    Last post » MarPlo
    You can use multiple Select statements in the same SQL query.
    Try this query, using a sub-select that selects the IDs.
    $sql = "SELECT * FROM...


  24. » PloMar
    I have two text fields, one for the date in "08/21/2012" format and a second field containing the time in the format "09:41am"....
    Last post » MarPlo
    On the database side, you can use:
    - STR_TO_DATE() to convert into a database friendly format.
    SELECT STR_TO_DATE(CONCAT('08/21/2012',...


  25. » PloMar
    I want to insert a DateTime object in database (created in PHP) where the column type is DateTime. How can I do?
    I am using this code:
    $cdate = new...
    Last post » MarPlo
    Use the "Y-m-d H:i:s" date-time format in PHP, it is the format of the DateTime column in MySQL.
    $cdate  = new  DateTime (...