Okay, I'm a noob, and I've tried to figure this PHP stuff out and it just blows my mind.
What I want to do is create a searchable database for firearms.
I borrowed a sample database code off the Net and managed to get it connected to my GoDaddy MySQL database just fine (I stopped getting errors concerning connections to the database so I believe I got it connected just fine.
Now I get the following:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/a/l/l/alleydude/html/firearms/page1.php on line 70
I've seen this in other threads with replies that seem to work, but I just don't know enough to apply what was suggested to get mine to work.
The code I am using is just a template that I was hoping to alter to apply to what I want to do, but I think it is all over my head.
Here is the code to my page:
<!--very good data entry page,with confirmation page!//-->
<html>
<head>
<title>data entry page</title>
</head>
<body bgcolor="CCCCCC">
<?php
//header include for data entry page. [not nessesacery you can delete this line #10]
$db = mysql_connect("host", "user", "pass");
// might have to change user name and host name.
mysql_select_db("test",$db);
// data base name
//i have used my test data vase here.
//you will have to create a table called employees in your test DB in mysql.
//with the following mysql query:
//mysql>use test;
//database changed
//mysql>create table employees( id tinyint(4) default '0' not null auto_increment,
// ->first varchar (255),
// ->last varchar(255),
// ->address varchar(255),
// ->position mediumtext,
// ->primary key (id),
// ->unique id (id));
//
//then go back and view this page and start your data base,
//you will need to create a new php page to veiw the info in your site!
//to upload images from this form simply type in where you will find the image on you server eg:<img src="C:/images/image.gif">
//and this is alot faster that uploading a image to the data base
if ($submit) {
// here if no ID then adding else we're editing
if ($id) {
$sql = "UPDATE employees SET first='$first',last='$last',address='$address',position='$position' WHERE id=$id";
} else {
$sql = "INSERT INTO employees (first,last,address,position) VALUES ('$first','$last','$address','$position')";
}
// run SQL against the DB
$result = mysql_query($sql);
echo "<img src=button1.gif><br><p>Record updated/edited!</p><a href=$PHP_SELF>[ Refresh ]</a>";
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM employees WHERE id=$id";
$result = mysql_query($sql);
echo "<img src=button1.gif><br><p>$sql Record deleted!</p><a href=$PHP_SELF>[ Refresh ]</a>"; } 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 employees",$db);
while ($myrow = mysql_fetch_array($result,MYSQL_NUM)) {
printf("<li><a href=\"%s?id=%s\">%s </a>\n", $PHP_SELF, $myrow["id"], $myrow["first"]);
printf(" <a href=\"%s?id=%s&delete=yes\"><b>[Delete]</b></a><br><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 employees WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$first = $myrow["first"];
$last = $myrow["last"];
$address = $myrow["address"];
$position = $myrow["position"];
// print the id for editing
?>
<input type=hidden name="id" value="<?php echo $id ?>">
<?php
}
?>
<table border="1" cellspacing="1" cellpadding="7"><tr><td>
Page title!</td><td><input type="Text" name="first" value="<?php echo $first ?>"><br>
</td></tr>
<tr><td>
Header or Images.</td><td><input type="Text" name="last" value="<?php echo $last ?>"><br>
</td></tr>
<tr><td>
Info.</td><td><input type="Text" name="address" value="<?php echo $address ?>"><br>
</td></tr>
<tr><td valign="top">
HTML content!</td><td>
<textarea type="input" name="position" value="" rows="20" cols="70"><?php echo $position ?></textarea>
</td></tr>
<tr><td valign="top">
<input type="Submit" name="submit" value="Enter information"></td><td valign="top">
<input type="reset" name="reset" value="clear fields"><br>
</form>
</td></tr>
</table>
<?php
}
?>
</body>
</html>
I appologize if this is this is not the correct way to post this. I am really lost. I can do html all day long, but PHP has me lost.
Any help would be appreciated.