4 responses to “How To Store Some Data In Mysql Database Through Php Script?”

  1. Kenneth

    First, create a table to store the data in mysql. If you don’t have much experience with command line mysql, you can use a web interface called phpMyAdmin.
    Once you have created your table, these are the steps to do a basic insert:
    1. Create db connection and select db:
    $link=mysql_connect (“$server”, “$user”, “$pwd”) or die (‘Connection failed: ‘ . mysql_error());
    mysql_select_db(“yourDB”);
    2. Create query:
    $query=”INSERT INTO yourTable(‘name’,'phone’,'age’) VALUES (‘John’,’123-456′,23);
    3. Execute query:
    mysql_query($query);
    That is just a very simple example, you should look at the PHP manual (www.php.net) for more information.

  2. cyndilou

    To insert from data into the database use the INSERT statement from answer two and reference the from elements.
    $query=”INSERT INTO yourTable(‘name’,'phone’,'age’) VALUES (‘.$_POST["name"].’,’.$_POST["number"].’…
    It’s also a good idea to protect the data from SQL injections using the mySQL function mysql_real_escape_string().

  3. altarilg

    Just to expound on what others have said, never, under any circumstances, insert a form value directly into a MySQL query. It’s kind of like begging to be hacked.
    If the value is supposed to be a number, check to be sure its numeric
    if(is_numeric($_POST['value'])) {
    $value = $_POST['value'];
    // do something
    } else {
    echo(“FAILED!”);
    }
    If it isn’t numeric, such as a text or varying character field, use mysql_real_escape_string.
    $value = mysql_real_escape_string($_POST['value']…

  4. Michael Safyan

    Use the “mysqli” library.