Connecting Tech Pros Worldwide Forums | Help | Site Map

how to pass form imput as variable to mysql?

Carramba
Guest
 
Posts: n/a
#1: Jul 17 '05
hi!

I have simple form like
<form method="POST" action="create_db.php">
db name: <input type="text" name="db" size="20">
<br>
table name: <input type="text" name="table" size="20">
<br>
Skriv in field name: <input type="text" name="name" size="20">
<input type="submit" value="Submit"><input type="reset">


I want to pass thouse variable to create_db.php but having problems.. how
to do it?

<?
//create_db.php
$create ="CREATE DATABASE " + $db;

$link = mysql_connect(localhost,root);

if (! $link)
die("Couldn't connect to MySQL");
mysql_query( $create );
if ( $link ){ //om länk finns skapa tabel
mysql_select_db( $db, $link)
or die("Select DB Error: ".mysql_error());
mysql_query("CREATE TABLE $table( id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id), namn VARCHAR(30) )")
or die("Create table Error: ".mysql_error());
//sätter in värden från formen in i tabelen
mysql_query ("INSERT INTO personer ( name ) VALUES ('$name')");
}
else {
echo "succes";
mysql_close($link);
}
?>

--

Thanx in advance
________________________
BTW. I know my english is not best in the word, so please stop bugging me
about my spelling. And yes Iam sorry you don't understand what I mean, but
there is no point to yell at me. Have a nice day.


Jamie Meyers
Guest
 
Posts: n/a
#2: Jul 17 '05

re: how to pass form imput as variable to mysql?


$db = $_POST['db'];
$table= $_POST['table'];
$name= $_POST['name'];


"Carramba" <nospam@note.com> wrote in message news:op.ssbn56upeel3e6@big...[color=blue]
> hi!
>
> I have simple form like
> <form method="POST" action="create_db.php">
> db name: <input type="text" name="db" size="20">
> <br>
> table name: <input type="text" name="table" size="20">
> <br>
> Skriv in field name: <input type="text" name="name" size="20">
> <input type="submit" value="Submit"><input type="reset">
>
>
> I want to pass thouse variable to create_db.php but having problems.. how
> to do it?
>
> <?
> //create_db.php
> $create ="CREATE DATABASE " + $db;
>
> $link = mysql_connect(localhost,root);
>
> if (! $link)
> die("Couldn't connect to MySQL");
> mysql_query( $create );
> if ( $link ){ //om länk finns skapa tabel
> mysql_select_db( $db, $link)
> or die("Select DB Error: ".mysql_error());
> mysql_query("CREATE TABLE $table( id INT NOT NULL AUTO_INCREMENT,
> PRIMARY KEY(id), namn VARCHAR(30) )")
> or die("Create table Error: ".mysql_error());
> //sätter in värden från formen in i tabelen
> mysql_query ("INSERT INTO personer ( name ) VALUES ('$name')");
> }
> else {
> echo "succes";
> mysql_close($link);
> }
> ?>
>
> --
>
> Thanx in advance
> ________________________
> BTW. I know my english is not best in the word, so please stop bugging me
> about my spelling. And yes Iam sorry you don't understand what I mean, but
> there is no point to yell at me. Have a nice day.
>[/color]


Oli Filth
Guest
 
Posts: n/a
#3: Jul 17 '05

re: how to pass form imput as variable to mysql?


Carramba said the following on 13/06/2005 19:55:[color=blue]
> hi!
>
> I have simple form like
> <form method="POST" action="create_db.php">
> db name: <input type="text" name="db" size="20">
> <br>
> table name: <input type="text" name="table" size="20">
> <br>
> Skriv in field name: <input type="text" name="name" size="20">
> <input type="submit" value="Submit"><input type="reset">
>
>
> I want to pass thouse variable to create_db.php but having problems..
> how to do it?
>
> <?
> //create_db.php
> $create ="CREATE DATABASE " + $db;
>
> $link = mysql_connect(localhost,root);
>
> if (! $link)
> die("Couldn't connect to MySQL");
> mysql_query( $create );
> if ( $link ){ //om länk finns skapa tabel
> mysql_select_db( $db, $link)
> or die("Select DB Error: ".mysql_error());
> mysql_query("CREATE TABLE $table( id INT NOT NULL AUTO_INCREMENT,
> PRIMARY KEY(id), namn VARCHAR(30) )")
> or die("Create table Error: ".mysql_error());
> //sätter in värden från formen in i tabelen
> mysql_query ("INSERT INTO personer ( name ) VALUES ('$name')");
> }
> else {
> echo "succes";
> mysql_close($link);
> }
> ?>
>[/color]

Use $_POST variables. See
http://www.php.net/manual/language.v...s.external.php

--
Oli
Steve
Guest
 
Posts: n/a
#4: Jul 17 '05

re: how to pass form imput as variable to mysql?


On Mon, 13 Jun 2005 20:55:08 +0200, Carramba wrote:
[color=blue]
> hi!
>
> I have simple form like
> <form method="POST" action="create_db.php"> db name: <input type="text"
> name="db" size="20"> <br>
> table name: <input type="text" name="table" size="20"> <br>
> Skriv in field name: <input type="text" name="name" size="20"> <input
> type="submit" value="Submit"><input type="reset">
>
>
> I want to pass thouse variable to create_db.php but having problems.. how
> to do it?
>
> <?
> //create_db.php
> $create ="CREATE DATABASE " + $db;
>
> $link = mysql_connect(localhost,root);
>
> if (! $link)
> die("Couldn't connect to MySQL");
> mysql_query( $create );
> if ( $link ){ //om länk finns skapa tabel
> mysql_select_db( $db, $link)
> or die("Select DB Error: ".mysql_error()); mysql_query("CREATE TABLE
> $table( id INT NOT NULL AUTO_INCREMENT,
> PRIMARY KEY(id), namn VARCHAR(30) )") or die("Create table Error:
> ".mysql_error());
> //sätter in värden från formen in i tabelen mysql_query ("INSERT INTO
> personer ( name ) VALUES ('$name')");
> }
> else {
> echo "succes";
> mysql_close($link);
> }
> ?>[/color]

Fixinf the logic in your php would help as well (:
Carramba
Guest
 
Posts: n/a
#5: Jul 17 '05

re: how to pass form imput as variable to mysql?


On Tue, 14 Jun 2005 07:53:15 +0200, Steve <ThisOne@Aint.Valid> wrote:
[color=blue]
> On Mon, 13 Jun 2005 20:55:08 +0200, Carramba wrote:
>[color=green]
>> hi!
>>
>> I have simple form like
>> <form method="POST" action="create_db.php"> db name: <input type="text"
>> name="db" size="20"> <br>
>> table name: <input type="text" name="table" size="20"> <br>
>> Skriv in field name: <input type="text" name="name" size="20"> <input
>> type="submit" value="Submit"><input type="reset">
>>
>>
>> I want to pass thouse variable to create_db.php but having problems..
>> how
>> to do it?
>>
>> <?
>> //create_db.php
>> $create ="CREATE DATABASE " + $db;
>>
>> $link = mysql_connect(localhost,root);
>>
>> if (! $link)
>> die("Couldn't connect to MySQL");
>> mysql_query( $create );
>> if ( $link ){ //om länk finns skapa tabel
>> mysql_select_db( $db, $link)
>> or die("Select DB Error: ".mysql_error()); mysql_query("CREATE TABLE
>> $table( id INT NOT NULL AUTO_INCREMENT,
>> PRIMARY KEY(id), namn VARCHAR(30) )") or die("Create table Error:
>> ".mysql_error());
>> //sätter in värden från formen in i tabelen mysql_query ("INSERT INTO
>> personer ( name ) VALUES ('$name')");
>> }
>> else {
>> echo "succes";
>> mysql_close($link);
>> }
>> ?>[/color]
>
> Fixinf the logic in your php would help as well (:[/color]

what do you mean

p.s. proglem is solvt


--

Thanx in advance
________________________
BTW. I know my english is not best in the word, so please stop bugging me
about my spelling. And yes Iam sorry you don't understand what I mean, but
there is no point to yell at me. Have a nice day.

Closed Thread