...

View Full Version : Making mySQL from PHP look like ASP



StealthRT
03-02-2008, 05:45 AM
Hey all how can i covert this php code here:


$sql="INSERT INTO form_data (name,email) VALUES ('$name','$email')";

to what im used to using with ASP...


Sql="select * from theguests"
oRecordset.Open Sql, oConnection,3,3

oRecordset("theName") = name
oRecordset("theEmail") = email

Thanks! :)
David

Inigoesdr
03-02-2008, 06:08 AM
Are you asking how to select a row with PHP, or how to insert a row with ASP?

StealthRT
03-02-2008, 06:15 AM
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?


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


$sql="INSERT INTO form_data";

name = '$name';
email = '$email';


David

_Aerospace_Eng_
03-02-2008, 06:31 AM
You can do something like this

$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

StealthRT
03-02-2008, 06:54 AM
You can do something like this

$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

NancyJ
03-02-2008, 02:51 PM
you can also do


$sql="INSERT INTO form_data
set name = '$name',
email = '$email'
";


I use data models so that I can do eg.



$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.


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();
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum