I am having trouble with sending info to my database. I can retrieve information from it, and edit it and send it back, but i can't get it to let me create a new record in the database.
<html>
<body>
<?php
$db = mysql_connect("localhost", "wwwfulc_admin", "**removed**");
mysql_select_db("wwwfulc_nuke2",$db);
if ($submit) {
// here if no ID then adding else we're editing
if ($id) {
$sql = "UPDATE nuke_bios SET position='$position',cname='$cname',dob='$dob',eyes='$eyes',hair='$hair',height='$height',weight='$weight',marks='$marks',personal='$personal',likes='$likes',dislikes='$dislikes',strength='$strength',weakness='$weakness',awards='$awards' WHERE id=$id";
} else {
$sql = "INSERT INTO nuke_bios (position,cname,dob,eyes,hair,height,weight,marks,personal,likes,dislikes,strength,weakness,awards) VALUES ('$position',$cname','$dob','$eyes','$hair','$height','$weight','$marks','$personal','$likes','$dislikes','$strength','$weakness','$awards')";
}
// run SQL against the DB
$result = mysql_query($sql);
echo "Record updated/edited!<p>";
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM nuke_bios WHERE id=$id";
$result = mysql_query($sql);
echo "$sql Record deleted!<p>";
} else {
// this part happens if we don't press submit
if (!$id) {
// print the list if there is not editing
$result = mysql_query("SELECT * FROM nuke_bios",$db);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href="%s?id=%s">%s %s</a> n", $PHP_SELF, $myrow["id"], $myrow["cname"], $myrow["dob"], $myrow["height"], $myrow["weight"], $myrow["marks"], $myrow["personal"], $myrow["dislikes"], $myrow["strength"], $myrow["weakness"], $awards["awards"]);
printf("<a href="%s?id=%s&delete=yes">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]);
}
}
?>
<P>
<a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
<P>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if ($id) {
// editing so select a record
$sql = "SELECT * FROM nuke_bios WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$position = $myrow["position"];
$cname = $myrow["cname"];
$dob = $myrow["dob"];
$eyes = $myrow["eyes"];
$hair = $myrow["hair"];
$height = $myrow["height"];
$weight = $myrow["weight"];
$marks = $myrow["marks"];
$personal = $myrow["personal"];
$likes = $myrow["likes"];
$dislikes = $myrow["dislikes"];
$strength = $myrow["strength"];
$weakness = $myrow["weakness"];
$awards = $myrow["awards"];
// print the id for editing
?>
<input type=hidden name="id" value="<?php echo $id ?>">
<?php
}
?>
Name: <input type="Text" name="cname" value="<?php echo $cname ?>"><br>
Date of Birth: <input type="Text" name="dob" value="<?php echo $dob ?>"><br>
Eye Color: <input type="Text" name="eyes" value="<?php echo $eyes ?>"><br>
Hair Color: <input type="Text" name="hair" value="<?php echo $hair ?>"><br>
Height: <input type="Text" name="height" value="<?php echo $height ?>"><br>
Weight: <input type="Text" name="weight" value="<?php echo $weight ?>"><br>
Any distinguishing marks: <input type="Text" name="marks" value="<?php echo $marks ?>"><br>
Personal History:<br>
<textarea name="personal"><?php echo $personal ?></textarea><br>
Likes: <input type="Text" name="likes" value="<?php echo $likes ?>"><br>
Dislikes:<input type="Text" name="dislikes" value="<?php echo $dislikes ?>"><br>
Strengths:<input type="Text" name="strength" value="<?php echo $strength ?>"><br>
Weaknesses:<input type="Text" name="weakness" value="<?php echo $weakness ?>"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
}
?>
</body>
</html>
That is my php code, and my sql is looking like this
Database wwwfulc_nuke2 - Table nuke_bios running on localhost
nuke_bios
Field Type Null Default Extra
id int(10) No auto_increment
position varchar(255) No
cname varchar(20) Yes NULL
eyes varchar(20) Yes NULL
hair varchar(20) Yes NULL
height varchar(20) Yes NULL
weight varchar(20) Yes NULL
marks varchar(255) Yes NULL
personal text Yes NULL
dob varchar(50) Yes NULL
likes varchar(255) Yes NULL
dislikes varchar(255) Yes NULL
strength varchar(255) Yes NULL
weakness varchar(255) Yes NULL
awards varchar(255) Yes NULL
Indexes : Keyname Type Cardinality Field
PRIMARY PRIMARY 1 id
id UNIQUE 1 id
id_2 INDEX None id
Space usage : Type Usage
Data 616 Bytes
Index 4,096 Bytes
Total 4,712 Bytes
Row Statistic : Statements Value
Format dynamic
Rows 1
Row length ø 616
Row size ø 4,712 Bytes
Next Autoindex 2
Any help is appreciated.
Thanks,
Jason Britton
http://st.fulco.net
scar@fulco.net