How to Insert a record into a MySql database.

Hi,
In an earlier question I was advised to use the Adobe extension to get access to database connectivity and server behaviours.
That extension is now installed. Whether it is functional is another question.
To chewck it out I follwed exactly the steps set out in Lessons 5 and 6 of Dreamweaver CS5 with PHP
When trying to make a database connection I am still getting the 404 error I mentioned in an earlier email. However if I type the database name (phpcs5) into the “select database” box and test it says I connected successfully and I can see the user’s table in the database panel.
So far apparently so good.
I have created the cs5wtite and cs5read connections to the phpcs5 database
I set up the insert record behaviour using “Form1!, “cs5write”, “users”,
Everything went as per the manual, the file turned aqua in Live view.
I entered data and ctrl/clicked “Sign me up” button and nothing happened.
No data was entered into the database and I was not passed to login.php.
I deleted everything from the computer, restarted the pc and started again from scratch.
The result was the same. Nothing
My one concern was line 49  $insertGoTo = " login.php";
The file is in registration so I changed to $insertGoTo = "registration/login.php";
but that made no difference.
Is there any logging or error reporting I can use to see where it is going wrong?
This is the add user page generated
<?php require_once('../Connections/cs5write.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  return $theValue;
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO users (first_name, family_name, username, password) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['first_name'], "text"),
                       GetSQLValueString($_POST['surname'], "text"),
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['password'], "text"));
  mysql_select_db($database_cs5write, $cs5write);
  $Result1 = mysql_query($insertSQL, $cs5write) or die(mysql_error());
  $insertGoTo = "login.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  header(sprintf("Location: %s", $insertGoTo));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add new user</title>
<link href="../../styles/users.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Sign Up Now</h1>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <fieldset>
    <legend>Just a few details and you&rsquo;re in</legend>
    <p>
      <label for="first_name">First name:</label>
      <input type="text" name="first_name" id="first_name" />
    </p>
    <p>
      <label for="surname">Family name:</label>
      <input type="text" name="surname" id="surname" />
    </p>
    <p>
      <label for="username">Username:</label>
      <input type="text" name="username" id="username" />
    </p>
    <p>
      <label for="password">Password:</label>
      <input type="password" name="password" id="password" />
    </p>
    <p>
      <label for="conf_password">Confirm password:</label>
      <input type="password" name="conf_password" id="conf_password" />
    </p>
    <p>
      <input type="submit" name="add_user" id="add_user" value="Sign me up!" />
    </p>
  </fieldset>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
</body>
</html>
This is the connection page
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_cs5write = "localhost";
$database_cs5write = "phpcs5";
$username_cs5write = "cs5write";
$password_cs5write = "Smp??2014";
$cs5write = mysql_pconnect($hostname_cs5write, $username_cs5write, $password_cs5write) or trigger_error(mysql_error(),E_USER_ERROR);
?>
I understand this solution is a wokraround Adobe privided whist deprecating its use.
In the earlier question I asked if there was another way to work with a database. Someone posted a link to an Object orientated solution but It was way beyond my coding abilities. I wonder are there any other solutions out there?
Thanks for any input

Hi,
Thanks for the test.
I used your amendment but still got nothing, no record in database and not sent to login page..
I also tried this code below. It returns "Record added to database" but it was not.
Something strange going on.
<?PHP
$user_name = "cs5write";
$password = "Smp??2014";
$database = "phpcs5";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$SQL = "INSERT INTO users (first_name, surame, username, password) VALUES) VALUES ('Albert', 'Dent', 'hitchiker', 'space')";
$result = mysql_query($SQL);
mysql_close($db_handle);
print "Records added to the database";
else {
print "Database NOT Found ";
mysql_close($db_handle);
?>

Similar Messages

  • How to insert multiple records into a table?

    hi all 
    i have a table that name is : TiketsItem
    now i  want to 100 records insert my table
    for example : TicketsHeaderRef=52000
    Active=False
    TicketsItemId=45000 to 45100
    how to insert TicketsItemId  45000 to 45100 in my table
    thanks all
    Name of Allah, Most Gracious, Most Merciful and He created the human

    So, you just want to insert the serialized data into the table, without useDate or WKRef? I'm assuming these values will be updated later?
    Try something like this:
    DECLARE @TicketsHeader TABLE (TicketsItemID BIGINT, ticketsHeaderRef BIGINT, active BIT, useDate DATETIME, WKRef SMALLINT)
    DECLARE @startInt BIGINT = 45000
    WHILE @startInt <= 45100
    BEGIN
    INSERT INTO @TicketsHeader (TicketsItemID, ticketsHeaderRef, active)
    VALUES (52000, @startInt, 0)
    SET @startInt = @startInt + 1
    END
    SELECT *
    FROM @TicketsHeader
    thanks 
    i edited your codes:
    DECLARE @TicketsItem TABLE (TicketsItemID BIGINT, ticketsHeaderRef BIGINT, active BIT, useDate DATETIME, WKRef SMALLINT)
    DECLARE @startInt BIGINT = 45000
    WHILE @startInt <= 45100
    BEGIN
    INSERT INTO @TicketsItem (TicketsItemID, ticketsHeaderRef, active)
    VALUES (@startInt,52000 , 0)
    SET @startInt = @startInt + 1
    END
    when i execute:
    SELECT *  FROM TiketsItem
    i do not see any records inserted in TiketsItem
    how to solve it?
    Name of Allah, Most Gracious, Most Merciful and He created the human

  • How to insert new record into altered table

    I am using JDBC with MySQL. I altered existing table and want to insert new record using java class. But it is not possible.How to do?

    How is it "not possible"?
    Either modify the Class for the new fields, or give the new fields default values (if applicable). If the type of an existing column has changed, then only the first option is available.
    Where's the problem?

  • How to insert new record into oracle table from GridView in VS2005.

    I need to insert records into Oracle10g table from VS2005 GridView using the Insert Method in Business Logic Class. The Update and Delete Methods are working fine. What's the best way out?

    How is it "not possible"?
    Either modify the Class for the new fields, or give the new fields default values (if applicable). If the type of an existing column has changed, then only the first option is available.
    Where's the problem?

  • How Can insert the records into Excel_sheet by using SQL Task-SSIS ?

    As per requirement ,
    insert the records in excel sheet(DT)  by using SQL Task-SSIS .
    I used SQL query in SQL Task-SSIS:
    e.g.., INSERT INTO [DT$B1:B1] VALUES ('COMMM')
    but error:Executing the query "INSERT INTO [DT$B1:B1] VALUES ('COMMM') " failed with the following error: "This table contains cells that are outside the range of cells defined in this spreadsheet.". Possible failure reasons: Problems
    with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
    Please any suggestion  ...
    -MADHU

    then first create a table inside Excel sheet based on your source data. You can Execute sql task for that using excel connection. then use insert to populate it
    see an example here where I create a dynamic sheet using execute sql task
    http://visakhm.blogspot.in/2013/09/exporting-sqlserver-data-to-multiple.html
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to insert Integer array in a MySql DataBase

    Now i am doing one swing application,in that i have List box,My doubt is ,How to insert the mutiple seleted value into database.

    http://java.sun.com/docs/books/tutorial/jdbc/

  • Workflow Approval Process: 1)How to insert Custom Data into Windows Workflow database? 2)In workflow Approval Process while creating new request ,how to insert our custom data like approvers ,requester,object info into WF DB?

    hi ,
    here the description about my question.
    1)i am working on windows workflow,we need to implement approval process for my project.
    2)we have multiple approvers for one request,requester,created object information.
    3)now i want to insert and retrieve, created instance information from windows workflow
    database.with all following details 
    i)Workflow instaceId,
    ii)current state of work flow(idle,complete,pending)
    iii)approvers information.
    iv)requester information.
    v)created object information.
    here some of the links, which i am trying for solution:
    https://wf.codeplex.com/wikipage?title=Tracking%20states%20with%20WorkflowApplication[^]
    https://msdn.microsoft.com/en-us/library/ee622977(v=vs.110).aspx[^]
    please answer to my question. if you want to send any examples send me to my email address.
    [email protected]

    Hi,
    According to your description, it seems that your main issue is about customID paramerter in workflow approval prcess.
    About this, please refer to the two samples:
    http://blog.petegoo.com/2010/08/22/workflow-4-email-approval-sample/
    http://cgeers.com/2010/04/10/windows-workflow-in-asp-net/
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to insert a value into a field of binary type?

    I've been using Oracle for a while now but never dealt with BLOB
    or long raw type before. Does anyone here know how to insert a
    record into a field of either blob or long raw type?
    Any suggestions would be very appreicated.
    Thanks.

    pls used the loadfromfile procedure which is in the DBMS_LOB
    package to insert the data from external os file into blob data
    type column.
    Kunjan

  • Inserting new records into database table at runtime

    Hi all ,
    How to insert new records into database table at runtime on click update?
    Thanks.

    Hi Sasikala,
    Just for your understanding am giving a sample code snippet which you can use to read the contents of your Table UI element & save the data on to your database. Suppose you have a button up on pressing which you want to read the data from your screens table & save on to the database then you can proceed as shown below:
    1) Obtain the reference of your context node.
    2) Fetch all the data present in your table into an internal table using methods of if_wd_context_node
    3) Use your normal ABAP logic to update the database table with the data from your internal table
    In my example I have a node by name SFLIGHT_NODE and under this I have the desired attributes from SFLIGHT. Am displaying these in an editable table & the user would press up on a push button after making the necessary changes to the tables data. I would then need to obtain the tables information & save on to the database.
    data: node_sflight           type ref to if_wd_context_node,
            elem_sflight           type ref to if_wd_context_element,
            lt_elements            type WDR_CONTEXT_ELEMENT_SET,
           stru_sflight           type if_main=>element_sflight_node,
           it_flights             type if_main=>elements_sflight_node.
    "   navigate from <CONTEXT> to <SFLIGHT_NODE> via lead selection
        node_sflight_node = wd_context->get_child_node( name = 'SFLIGHT_NODE'  ).
       lt_elements = node_sflight->get_elements( ).
    "   Get all the rows from the table for saving on to the database
        loop at lt_elements into elem_sflight.
          elem_sflight->get_static_attributes( importing static_attributes = stru_sflight ).
          append stru_sflight to it_flights.
        endloop.
    " Finally save the entries on to the database
        modify ZSFLIGHT99 from table it_flights.
        if sy-subrc eq 0.
    endif.
    However a word of caution here.... SAP doesn't ever recommend directly modifying the database through an SQL query. You would preferably make use of a BAPI for the same. Try go through Thomas Jung's comments in [here|modify the data base table which is comming dynamiclly;.
    Regards,
    Uday

  • Insert multiple records into database through internal table

    Hi
      please help me how to insert multiple records into database through internal table

    Hi,
    Welcome to SCN.
    Press F1 on INSERT statement and you will teh syntax as well the docu for the same.

  • Inserting a record in an Oracle database

    Hi,
    I would appreciate if anyone could provide a code snippet showing how to insert a record into an Oracle 9i database. The columns in the database table have datatypes such as NUMBR, VACHAR2, and DATE. Some of the columns may be null. The input text is in the form of String. The string from the date fields is in the form 'YYYY-MM-DD HH:MI:SS PM' and I have converted these to java.sql.Date objects. How do I deal with nulls?
    Thanks.

    I am having a problem inserting a date field. The input string is in the form YYYY-MM-DD HH:MM PM. I converted the input string to a java.sql.Date object before trying to post the record. However, an example of what gets inserted is: '2001-12-04 12:00 AM' even if the input date string is: "2001-12-04 04:40". In other words, the hour and minute portions do not get inserted correctly.
    Why is this and how can I resovle this? My code is as follows: (try/catch blocks are not shown)
    String m_HireDate = "2001-12-04 04:40 PM"; // Input string.
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm a");
    java.utilDate m_UtilDate = sdf.parse(URLDecoder.decode(m_HireDate);
    java.sql.Date m_SQLDate = new java.sql.Date(m_UtilDate);
    Connection con = DriverManager.getConnection(url,"abc"," abc") ;
    Statement stmt =
    con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
    ResultSet.CONCUR_UPDATABLE) ;
    String sqlselect = "SELECT EMP_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME, HIRE_DATE, FROM EMP" ;
    ResultSet rs = stmt.executeQuery(sqlselect) ;
    // EMP_ID is the primary key. It has a datatype of NUMBER in the database tabe
    int EMP_ID1 = Integer.parseInt(EMP_ID);
    rs.moveToInsertRow() ;
    rs.updateInt("EMP_ID", EMP_ID1) ;
    rs.updateString("FIRST_NAME", "John" );
    rs.updateString("MIDDLE_NAME", "M" );
    rs.updateString("LAST_NAME", "Smith");
    rs.updateDate("HIRE_DATE" , m_SQLDate); //m_SQLDate is a java.sql.Date object
    rs.insertRow() ;
    Now get the inserted value from SQLPLUS:
    SELECT TO_CHAR(HIRE_DATE, 'YYYY-MM-DD HH:MI PM') FROM EMP WHERE EMP_ID =EMP_ID1;
    The output is: "2001-12-04 12:00 AM"
    Thanks.

  • Hi, plz help me. i wanna store photos to sql database. so how to insert file field into insert record in dreamweaver cs3?

    I dont know how to insert file field into insert record in DW. i also want to know, insert dynamic table with image field. Plz help me anyone. Ty..

    ohh kk thank you bro. But How to store photos to server file. I wanna upload and display the photos in webpage. Can you send me the php code for this?

  • How to insert an image into mysql

    welcome to all,
    can any one tell how to insert an image into mysql database(BLOB). it is urgent.
    regards

    welcome to all,
    can any one tell how to insert an image into mysql database(BLOB). it is urgent.
    regards

  • [php+mysql] how to insert 3 records at once and print out all 3 records?

    Hi all,
    I have to create a serie of pages that allow the user to:
    1- Insert 3 records in a mysql db at once
    2- click NEXT
    3- viewverify//print the data that he has entered (all 3
    records)
    4- click PRINT
    5- click FINISH
    then, restart from 1
    What is the best way to do this?
    TIA for any suggestion.
    tony

    The best way is usually to use a stored procedure. Do you
    know if the version of MySQL you are using supports sprocs?

  • Insert multiple records into a table(Oracle 9i) from a single PHP statement

    How can I insert multiple records into a table(Oracle 9i) from a single PHP statement?
    From what all I've found, the statement below would work if I were using MySQL:
         insert into scen
         (indx,share,expire,pitch,curve,surface,call)
         values
         (81202, 28, 171, .27, 0, 0, 'C' ),
         (81204, 28, 501, .25, 0, 0, 'C' ),
         (81203, 17, 35, .222, 0, 0, 'C' ),
         (81202, 28, 171, .27, 2, 0, 'C' ),
         (81204, 28, 501, .20, 0, 1, 'C' ),
         (81203, 28, 135, .22, 1, 0, 'C' )
    The amount of records varies into the multiple-dozens. My aim is to utilize the power of Oracle while avoiding the i/o of dozens of single-record inserts.
    Thank you,
    Will

    You could look at the INSERT ALL statement found in the documentation here:
    http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_913a.htm#2133161
    My personal opinion is that you probably won't see any benefit because under the hood I think Oracle will still be doing single row inserts. I could be wrong though.
    The only way to confirm was if you did a test of multiple inserts vs an INSERT ALL, that is if the INSERT ALL met your requirements.
    HTH.

Maybe you are looking for