Jump to content

mga_ka_php

Members
  • Posts

    134
  • Joined

Posts posted by mga_ka_php

  1. 1stly you have to create a form:

     

    <form action="" method="POST">
    <input type="text" name="name">
    <input type="text" name="age">
    <input type="text" name="hobbies">
    </form>

    Then in PHP:

    Connect to mysql and db...
    //insert into table
    $sql="insert into personal(name,age)values('$_POST['name']','$_POST['age']')";
    $query=mysql_query($sql) or die(mysql_error());
    
    //write the rest for other tables.....

     

    This is just a basic idea, try to build it for your need.

     

     

    additional to this, if your going to use the id of first sql query,

    $sql="insert into personal(name,age)values('$_POST['name']','$_POST['age']')";
    $query=mysql_query($sql) or die(mysql_error());
    $last_id=mysql_insert_id();
    
    $sql="insert into hobbies(hobbies,personal_id)values('$_POST['hobbies']','$last_id')";
    $query=mysql_query($sql) or die(mysql_error());
    

     

  2. $myname = $_POST["myname"];
    
    $mymail = $_POST["mymail"];
    
    $msubj = $_POST["msubj"];
    
    $mbody = $_POST["mbody"];
    
    $mcompany= $_POST["mcompany"]; // INSERT THIS
    
    $mphone= $_POST["mphone"]; // INSERT THIS
    
    //////////////////////////////////////////////////////////////////////////////////////
    
    $fpmanager = popen("/usr/sbin/sendmail dmcnzl@gmail.com","w");
    
    fputs($fpmanager,"Content-Type: text/html; charset=iso-8859-1\n");
    
    fputs($fpmanager,"From: ". $mymail ."\n");
    
    fputs($fpmanager,"Subject: Website Enquiry > $msubj");
    
    //////////////////////////////////////////////////////////////////////////////////////
    
    fputs($fpmanager,"\n\nMessage Subject > $msubj\n\n"); 
    
    fputs($fpmanager,"Message Content > \n"); 
    
    fputs($fpmanager,"$mcompany\n\n");  // INSERT THIS
    
    fputs($fpmanager,"$mphone\n\n");  // INSERT THIS
    
    fputs($fpmanager,"$mbody\n\n"); 
    
    fputs($fpmanager,"\n\nMessage From > $myname ($mymail) \n\n"); 
    
    fputs($fpmanager,"User IP Address > ". $_SERVER['REMOTE_ADDR'] ."\n"); 
    
    

  3. $name=stripslashes($_POST['name']);
    $email=stripslashes($_POST['email']);
    $company=stripslashes($_POST['company']);
    $phone=stripslashes($_POST['phone']);
    $subject=stripslashes($_POST['subject']);
    
    //Let's start our headers
    $header="MIME-Version: 1.0\n";
    $header.="Content-type: text/html\n";
    $header.="From: Free Form Blister Pack Customer: $name<$email>";
    
    $message="<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
    $message.="<tr><td>Name</td><td>$name</td></tr>";
    $message.="<tr><td>Email</td><td>$email</td></tr>";
    $message.="<tr><td>Company</td><td>$company</td></tr>";
    $message.="<tr><td>Phone</td><td>$phone</td></tr>";
    $message.="<tr><td>Subject</td><td>$subject</td></tr>";
    $message.="</table><br /><br />";
    
    // send the message
    mail("email address","Contact Form",$message,$headers); 
    

  4. use mysql_insert_id.

     

    like this

     

    $album = clean_full($_POST['album']);

    $artistid = $_POST['artist'];

    $year = (int)($_POST['year']);

    $review =  clean_body($_POST['review']);

    $user_id = $_SESSION['user_id'];

     

    $query = "INSERT

      INTO albums

      SET

      id = '', // This id will auto-increment in the database but I need to get the number it is assigned

    artist_id = '$artistid',

    title = '$album',

    year = '$year',

    user_id = '$user_id',

    created_at = NOW()

    ";

     

     

    $result = mysql_query($query);

     

    $prev_id=mysql_insert_id();

     

    $query1 = "INSERT

      INTO reviews

      SET

      id = '',

    artist_id = '$artistid',

    album_id = $prev_id // I need to get the id from the previous insert and place it here

    body = '$review',

    user_id = '$user_id',

    created_at = NOW()

    ";

     

    mysql_insert_id() = get the id from the previous sql statement

  5. how do you explode string with two conditions, space and newline?

    i use strtok but i could only use 1 condition

    i cannot use the 2 condition space and newline

    i want to explode a string with if a string has a space and newline?

    how do i do that?

     

    thanks in advance.

  6. how do i input textarea value to mysql database that will preserve the format?

    ex.

    if i input a text in textarea

    ----------------------------------

    line one

    line two

    ----------------------------------

    and transfer it to mysql database and retreive it

    the text will look like this

    ----------------------------------------------------

    line one            line two

    ----------------------------------------------------

    it will not put it to the next line.

     

    thank you.

  7. i used this script but it doesn't work?

     

    First off, you need to be adjusting your action to reflect the page you're wanting to submit to. Try something like this:

    <script type="text/javascript">
    var myForm = document.forms[0];
    
    function submitAdd() {
      myForm.action = "users.php?do=add";
      myForm.submit();
    }
    
    function submitEdit() {
      myForm.action = "users.php?do=edit";
      myForm.submit();
    }
    </script>
    
    <a href="#" onclick="return submitAdd();">new</a>
    <a href="#" onclick="return submitEdit();">edit</a>
    

     

    Also, I'm moving this to the javascript forum since it has nothing to do with PHP ;)

×
×
  • 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.