Closed Thread Icon

Topic awaiting preservation: Formular (PHP) (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12074" title="Pages that link to Topic awaiting preservation: Formular (PHP) (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Formular (PHP) <span class="small">(Page 1 of 1)</span>\

 
Blacknight
Bipolar (III) Inmate

From: INFRONT OF MY PC
Insane since: Dec 2001

posted posted 03-01-2002 21:45

How do i select the Formular fields in the sql-Statement
Example:
$ergebnis=mysql_query("INSERT INTO Newsben [(User[,Title[,Content[, Date]]])] VALUES ( I need this");

Is this actualy right , until now

Lurch
Paranoid (IV) Inmate

From: Behind the Wheel
Insane since: Jan 2002

posted posted 03-01-2002 21:56

form.php
---------
<form action=insert.php ...>
Name: <input type=text name=name ....>
Email: <input type=text name=email ....>
Website: <input type=text name=website ...>
....etc...

insert.php
----------

$sql = "INSERT INTO tablename (column1, column2, column3) VALUES ($name, $email, $website)";
$result = mysql_query($sql, $connection);
...etc...

the name in the form input is the variable name.

--Lurch--

[This message has been edited by Lurch (edited 03-01-2002).]

Blacknight
Bipolar (III) Inmate

From: INFRONT OF MY PC
Insane since: Dec 2001

posted posted 03-01-2002 22:07

Thanks.
so far so good.

And how do I execute the $result?????

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 03-01-2002 22:16

what exactly do you mean?
i think theres no more need to execute the result.

Lurch
Paranoid (IV) Inmate

From: Behind the Wheel
Insane since: Jan 2002

posted posted 03-01-2002 22:17

for inserting (I'm assuming you're only inserting one set of values into the table at a time) you shuoldn't need any more...
but when selecting...
$sql = "SELECT name, id FROM tablename ORDER BY id DESC LIMIT 5";
$result = mysql_query($sql, $connection);
While ($row = mysql_fetch_object($result)){
$display .= "Name: $row->name";
}

?>

<html><body>
<? echo($display); ?> <--------- shows list of 5 names with highest id's (most recent)

</body></html>

--Lurch--

Blacknight
Bipolar (III) Inmate

From: INFRONT OF MY PC
Insane since: Dec 2001

posted posted 03-01-2002 22:19

it looks like, the script doesn´t insert into the Database.
Here is the whole Script:
<?
$server ="localhost";
$user="****";
$pass="****";
$dbase="*******";
$conn= mysql_connect($server, $user,$pass) or die ("Konnte verbindung zur db nicht herstellen");

mysql_select_db($dbase, $conn);
$ergebnis=mysql_query("INSERT INTO Newsben (User,Title,Content, Date) VALUES ($User,$Title,$Content,$Date )");
$result=mysql_query($ergebnis,$conn);

mysql_close($conn);
?>

Should this work?????

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 03-01-2002 22:19

Blacknight: You might also want to read through some of these (they are most helpful):
www.devshed.com/Server_Side/MySQL

Emps

Lurch
Paranoid (IV) Inmate

From: Behind the Wheel
Insane since: Jan 2002

posted posted 03-01-2002 22:22
quote:
$ergebnis=mysql_query("INSERT INTO Newsben (User,Title,Content, Date) VALUES ($User,$Title,$Content,$Date )");
$result=mysql_query($ergebnis,$conn);



get rid of "mysql_query" in front of that first line...
eg...
$ergebnis="INSERT INTO Newsben (User,Title,Content, Date) VALUES ($User,$Title,$Content,$Date )";
$result=mysql_query($ergebnis,$conn);


--Lurch--

Blacknight
Bipolar (III) Inmate

From: INFRONT OF MY PC
Insane since: Dec 2001

posted posted 03-01-2002 22:29

ok i think i have aproblem somewhere but i dont know where :

perhapse youl find it *gg*

<html>
<head>
</head>

<body>
<Form Method="post" aktion="admin.php">
<Table Border="0" Width="100%">
<tr>
<td width="10%"><input type="text" Name ="User"></td>
<td><input type="text" Name ="Title"></td>
</tr>
<tr>
<td Width="10%"><input type="text" Name ="Content"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td collsapn="2"><input type="Submit" Name ="Submit" Value="Submit"></td>

</tr>
</Table>
</Form>
<?
$date=now;
$server ="localhost";
$user="******";
$pass="******";
$dbase="*****";
$conn= mysql_connect($server, $user,$pass) or die ("Konnte verbindung zur db nicht herstellen");

mysql_select_db($dbase, $conn);
$ergebnis="INSERT INTO Newsben (User,Title,Content, Date) VALUES ($User,$Title,$Content,$Date )";
$result=mysql_query($ergebnis,$conn);

mysql_close($conn);
?>


GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 03-01-2002 22:39

try putting the values in apostrophes like:

$ergebnis="INSERT INTO Newsben (User,Title,Content, Date) VALUES ('$User','$Title','$Content','$Date')";

Blacknight
Bipolar (III) Inmate

From: INFRONT OF MY PC
Insane since: Dec 2001

posted posted 03-01-2002 22:45

hey thanks it workes only the $date=now; does not work how do i declare Date as now?

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 03-01-2002 22:46

action in the form HTML is misspelled. (I think it's gotta be english I could be wrong!)



:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 03-01-2002 22:51

depends on how you define the date col in your mysql table.
i prefer using:
$mydate = date("Y-m-d H:i:s");

Blacknight
Bipolar (III) Inmate

From: INFRONT OF MY PC
Insane since: Dec 2001

posted posted 03-01-2002 22:57

strange things are hapening....the date doesnt work like that (table is defined as DATE in the sql)
and the script seems to add empty datasets irrgulary ?????

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 03-09-2002 18:39

with date only try:
$mydate = date("Y-m-d");

« BackwardsOnwards »

Show Forum Drop Down Menu