Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder StealthRT's Avatar
    Join Date
    Aug 2006
    Posts
    185
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Question Making mySQL from PHP look like ASP

    Hey all how can i covert this php code here:
    PHP Code:
    $sql="INSERT INTO form_data (name,email) VALUES ('$name','$email')"
    to what im used to using with ASP...
    Code:
    Sql="select * from theguests"
    oRecordset.Open Sql, oConnection,3,3
    
    oRecordset("theName") = name
    oRecordset("theEmail") = email
    Thanks!
    David

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Are you asking how to select a row with PHP, or how to insert a row with ASP?

  • #3
    Regular Coder StealthRT's Avatar
    Join Date
    Aug 2006
    Posts
    185
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Sorry, how to insert a row with php.

    How do i get it set up like ASP. like instead of having the whole insert statement on one line as it does in PHP can i have it as its set up in ASP where it has line by line to insert it?
    Code:
    php=
    $sql="INSERT INTO form_data (name,email) VALUES ('$name','$email')";  
    
    asp=
    Sql="select * from theguests"
    oRecordset.Open Sql, oConnection,3,3
    
    oRecordset("theName") = name
    oRecordset("theEmail") = email
    So what im asking is can i do something like this..
    PHP Code:
    $sql="INSERT INTO form_data";

    name '$name';
    email '$email'
    David
    Last edited by StealthRT; 03-02-2008 at 06:17 AM.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You can do something like this
    PHP Code:
    $sql="INSERT INTO form_data
    (
    name,
    email
    ) VALUES
    (
    '$name',
    '$email'
    )"

    Though I'm curious what is wrong with the one line thing? You can possible using prepared queries. Here is an example in php5
    http://www.petefreitag.com/item/356.cfm
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    StealthRT (03-02-2008)

  • #5
    Regular Coder StealthRT's Avatar
    Join Date
    Aug 2006
    Posts
    185
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    You can do something like this
    PHP Code:
    $sql="INSERT INTO form_data
    (
    name,
    email
    ) VALUES
    (
    '$name',
    '$email'
    )"

    Though I'm curious what is wrong with the one line thing? You can possible using prepared queries. Here is an example in php5
    http://www.petefreitag.com/item/356.cfm
    Ok, that will do i guess. Thanks _Aerospace_Eng_

    David

  • #6
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    you can also do
    PHP Code:
    $sql="INSERT INTO form_data
    set name = '$name',
    email = '$email'
    "

    I use data models so that I can do eg.

    PHP Code:
    $formdata->name $name;
    $formdata->email $email;
    $formdata->save(); 
    All my data models extend from a base class that contains all the basic functionality - this is my save function. It also calls a validation function to check the data before saving and empty before and after save functions that can be over-written in the model.

    PHP Code:
            function save()
            {
                 
    $this->success=true;
                
    $this->before_save();
                
    $this->validate();
                

        
                if(
    $this->success == false) return;
                foreach(
    $this->fields as $name => $field)
                {
                 
                    if(
    $name !== $this->primary)
                    {
                        
    $fieldvals[] = '`'.$name."` = ".$this->protect($this->$name);
                    }
                }
                
    $fieldvals implode(", "$fieldvals);
                if(
    $this->{$this->primary})
                {
                    
    $sql "UPDATE $this->modelName SET ".$fieldvals." WHERE $this->primary = ".$this->protect($this->{$this->primary});
                }
                else
                {
                    
    $sql "INSERT INTO $this->modelName SET ".$fieldvals;
                    
    $insert true;
                }
                
                
    $result $this->query($sql);
                if(
    $this->affected_rows($result)>0)
                {
                    
    $this->errors[] = "Record Updated Sucessfully";
                    
    $this->success true;
                    if(
    $insert==true)
                    {
                        
    $this->id $this->insert_id;
                    }
                    
                }
                else
                {
                    
    $this->errors[] = "Update Record Failed!";
                    
    $this->success false;
                }
                
    $this->after_save();
            } 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •