Closed Thread Icon

Preserved Topic: mysql/php: table insert problem Pages that link to <a href="https://ozoneasylum.com/backlink?for=21020" title="Pages that link to Preserved Topic: mysql/php: table insert problem" rel="nofollow" >Preserved Topic: mysql/php: table insert problem\

 
Author Thread
GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 07-10-2001 08:37

im using this code for a guestbook on my site:

code:
<?php

$link = mysql_pconnect("db.embege.f2s.com","...","...")
or die("Unable to connect to SQL server");
mysql_select_db("embege",$link) or die("Unable to select database");

if( $insert == "1" ) {
mysql_query("INSERT INTO 'guests' (guest_name,guest_email,guest_message)
VALUES ('$fname','$femail','$fmessage')")
or die("Insert Failed!");
$insert = 0;
}

echo "<form name=book id=book method=POST action=guestbook.php>";
echo "<input type='hidden' name='$insert' value='1'>";
echo "<table cellpadding=2>";
echo "<tr><td>Name:</td><td><input type=text length=10 name=Name id=Name value=$fname></td>";
echo "<td rowspan=2><textarea cols=24 rows=3 name=Komm id=Komm>$fmessage</textarea></td></tr>";
echo "<tr><td>Email:</td><td><input type=text length=10 name=Email id=Email value=$femail></td></tr>";
echo "</table>";
echo "<input type=submit value='Post'>";
echo "</form>";

// print out the entries. this works fine for me. just the insert makes problems.

}

?>



the problem is, that the insert into the tables doesnt work. it is making a new line in the table, but with no data in it. when i select it, i get empty fields.
anyone knows what's wrong? thanks a lot!

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 07-10-2001 11:26

mysql_query("INSERT INTO guests(guest_name, guest_email, guest_message) VALUES ('$fname','$femail','$fmessage')")

should work if you correct what is in bold.

and instead of priting out all the html form use:

something like:
<?
php code here
?>
HTML here
<?
php here
?>

example:
<body>Welcome <? echo $username?></body>
or
<body>Welcome <?=$username?></body>
.
.


GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 07-10-2001 13:19

i already tried that, but it makes no difference.
thanks anyway.

timothymcnulty
Neurotic (0) Inmate
Newly admitted
posted posted 07-10-2001 13:35

the form tag is incorrect..."name" will be read as the variable name, not "value"...value corresponds to what is initially written inside the form field...

name=Name should be name=fname

name=Komm should be name=fmessage

name=email should be name=femail

hope that works...

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 07-10-2001 16:21

Yes, timothy saw the real problem...

Grumble,
It's also suggested that you put the Tags properties between quotes (double or single).
Like <input type="text" name="fname" value="the value">


bitdamaged
Maniac (V) Mad Scientist

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

posted posted 07-10-2001 21:32

Hmm I'm interested this sorta worked at all. I always have all sorts of problems when variables are not set. It seems with the problem with the form this should break before doing the insert.

Another aside about all the echos to print out the form.

I found out a while back that you can drop out of PHP in a loop.

Something like this is okay

while ($x < $y) {
?>
This is a whole bunch of HTML
<? echo $x; $x++; ?>

Then a whole bunch more HTML
<? } ?>

Even though the contents of the loop are not in the PHP space they will still loop the output.


Walking the Earth like Kane

[This message has been edited by bitdamaged (edited 07-10-2001).]

« BackwardsOnwards »

Show Forum Drop Down Menu