hello everybody

I'm new to Php and I have a problem of concatinating string with variable. I have a stored procedure in mysql which takes 2 varaibles and inserts in the table. the variables actually are the string. THe varaible1 contains column names (including the brackets) and var 2 has values for these columns(including the word values). so my problem is how do i make a insert statement.

var1="(name,city,number)"
var2="values ('john mess','sanfrancisco','12414')"

the proccedure is below

create procedure testing (in var1 longtext,in var2 longtext)
begin

//how to make an insert statement so that the string looks like this - insert into mytable(name,city,number) values ('john mess','sanfrancisco','12414')

//how to concatinate the "inert into mytable " with my varaibles ...

end
delilmiter;

thanks plz help

    Now are you using a form to get this information? if so why not go with something like this

    $name = $_POST['name'];
    $city = $_POST['city'];
    $number = $_POST['number'];
    
    $sql="INSERT INTO table VALUES('$name, city, number')";
    $result=mysql_query($sql);
    
    if($result){
    echo "Successful<BR>";
    echo "<a href='index.php'>Home</a>";
    }
    else {
    echo "ERROR";
    }
    

    btw not sure if this script would work just threw it together lol. but test it out if this is the way you need.

      i do not want to write queries i php files, i want to have all my queries in Stored pocedurs , thats what Im asking?.

      can u plz help

        a year later

        did you ever find the answer to this?
        I m looking to do the same thing.

        thanks.

          Write a Reply...