PHP
#1
Posted 04 August 2003 - 06:48 AM
#2
Posted 04 August 2003 - 12:09 PM
e.g. http://www.domain.co...ecord.php?ref=1
when you loop through the database to pull out all the records for each one you echo the link and append the variable to the get string.
Then on the show record page you extract the value of ref e.g. $_GET['ref'] and then use it in your SQL query.
#3
Posted 04 August 2003 - 05:45 PM
#4
Posted 04 August 2003 - 10:12 PM
////////////////////////////////////////////////////
<html>
<head>
<title>Add a Product</title>
</head>
<body>
<?php
if ($edited == "yes")
{
add();
}
?>
<form method="post" action="addcat.php">
<p>Enter Product Code - <input type="text" name="code">
<p>Enter Product Name - <input type="text" name="name">
<p>Enter Product Description - <input type="textarea" name="description">
<p>Enter Product Sizes - <input type="text" name="sizes">
<p>Enter Product Colours - <input type="text" name="colours">
<p>Enter Product Category - <input type="text" name="category">
<p>Enter Product Price - <input type="text" name="price">
<p>Enter Product Thumb Nail Picture Name - <input type="text" name="thumb">
<p>Enter Product Picture Name - <input type="text" name="picture">
/*IMPORTANT BIT*/
<p><input type="hidden" name="edited" value="yes">
<p><input type="submit">
</form>
<?php
function add($code,$name,$description,$sizes,$colours,$category,$price,$thumb,$picture)
{
$host="localhost";
$user="root";
$password="";
$database="brenigcat";
$connection=mysql_connect($host,$user,$password)
or die ("Could Not Connect To MySQL Server");
$db=mysql_select_db($database,$connection)
or die ("Could Not Connect To Database");
$query="INSERT INTO products (code,name,description,category,colours,sizes,price,thumb,picture)
values
('$code','$name','$description','$category','$colours','$sizes','$price','$thumb','$picture')";
$result=mysql_query($query)
or die ("Could Not Add To Database");
}
$edited="no";
?>
<p><a href="addcat.php">Add Another Product</a>
</body>
</html>
////////////////////////////////////////////////////
[Edited on 4-8-2003 by Stuart]
#5
Posted 04 August 2003 - 11:08 PM
so where you call it with:
add();
replace it with
add($code,$name,$description,$sizes,$colours,$category,$price,$thumb,$picture);
Also, I have noticed potential security holes and possible probs when inserting a record.
Try and get the script to add a record by following my advice, and then I will help you to make the script more secure
#6
Posted 05 August 2003 - 06:10 AM
Thanks
Stuart
#7
Posted 12 August 2003 - 12:19 PM
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<html>
<head>
<title>Delete A Product</title>
</head>
<body>
<?php
/*Connect to Database*/
include("misc.inc");
/*Get the names of all of the products from the database*/
$query="SELECT name FROM products";
$result=mysql_query($query)
or die("Could Not Select Names");
/*Create form and select tags*/
echo "<form action='deletecatconfirm.php' method='post'>\n";
echo "<select name='product'>\n";
/*Start of While Loop*/
while ($row=mysql_fetch_array($result))
{
/*Extract all of the information from $row*/
extract($row);
/*Display the information in a drop down list*/
echo "<option value='name'>$name\n";
}
?>
</select>
<input type="submit">
</form>
</body>
</html>
And the confirmation page.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<html>
<head>
<title>Deleted Product Confirmation</title>
</head>
<body>
<?php
/*Connect to Database*/
include("misc.inc");
/*Delete the row store in $product*/
$query="DELETE FROM products WHERE $product";
$result=mysql_query($query)
or die("Couldnt Delete Product");
?>
</body>
</html>
Edited by Stuart, 12 August 2003 - 12:40 PM.
#8
Posted 12 August 2003 - 01:56 PM
'$query="DELETE FROM products WHERE $product";'
The above is saying delete from the products table where product.
This is wrong. You need to tell it which product to delete. e.g.
$query="DELETE FROM products WHERE ref=$productref";
you need to specify the unique primary key of the record you want to delete.
So after the WHERE command,specify the field name of the primary key e.g. ref and then put equals, and then the variable that contains the value of the key to be deleted.
e.g. DELETE FROM products WHERE ref=1 is what you would see if you echo the query to the browser, and this is what SQL see's.
Hope this helps.
#9
Posted 12 August 2003 - 03:19 PM
Stuart
#10
Posted 12 August 2003 - 03:41 PM
I dont know if that was the problem but it still didnt work after I changed the primary key. But then after fiddling, I managed to get it to work If you lookat where the drop down list is created in the first program, it sets the value of each item to product. Im not sure how it works, but I got rid of it to clean the code up a little to make it easier to understand and I noticed that it wasnt needed. I got rid and it worked. . I can now get the updatecat program to work now and then I should have the back bone done and can start fiddling and stop it working again as I try to make it look better and smaller .
Thanks for the help, probebly want a bit more again some time
Stuart
Edited by Stuart, 12 August 2003 - 03:42 PM.
#11
Posted 12 August 2003 - 03:44 PM
#12
Posted 13 August 2003 - 05:28 PM
One of the things the database has to store is a description of the product. Well, it stores the spaces in between words, but how would I get it to store 'enters' so that the text will appear on the next line when the database is query.
Heres an easier way of putting it.
Here is a new line.
And another.
How would I get it to store the text on those new lines instead of like this-
Here is a new line.And another.
Thanks
Stuart
#13
Posted 13 August 2003 - 08:58 PM
You do this by:
$text=nl2br($row['description']); echo("$text");
The nl2br() function takes new lines in your text (everytime you punch return or start a new line) and converts them to a </br> tag. This preserves the structure of the text.
The result of this is that the text will look the same as when you put it in.
Hope that helps.
#14
Posted 13 August 2003 - 09:16 PM
Thanks
Stuart
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users