Jump to content

edit form


elexion

Recommended Posts

good day everyone, I've been working on a edit script for my website the idea is to go to the first page insert the product name and console and hit the submit button then you'll a new form with all the values of the product displayed in a form. However something strange is happening. Whenever i try to add a WHERE command to my query it returns nothing. When i leave the WHERE out it displays the productname time the numbers of records in my table. Finally for some odd reason it fills in the productname and the genre with the last record in my table. So lets get to the code

<!DOCTYPE html	public "-//W3C//DTD XHTML 1.0 strict //EN"	"http://www.w3.org/TR/xhtmll/DTD/xhtmll-strict.dtd"><html><head><?phpinclude("connect.php");include("menu.php");include("shoppingcart.php");include("function.php");date_switcher();?></head><body><?php$theProduct = $_POST['productQuery'];//this is the query that refuses my WHERE command$query = mysql_query("SELECT * FROM producten");while($row = mysql_fetch_array($query))  {  $game = $row['productname'];  echo $theProduct;  $console = $row['console'];  $prijs = $row['price'];  $genre = $row['genre'];  $beschrijving = $row['discription'];  $levertijd = $row['delivery'];  }?><b>update the value</b><form name="update" action="editScript.php" method="POST">productname: <input type="text" name="newProductname" value=<?php echo $game; ?> ><br />console:<select>  <option>must set</option>  <option>xbox 360</option>  <option>playstation 3</option>  <option>wii</option></select><br />genre: <input type="text" name="genre" value=<?php echo $genre; ?> ><br />prijs: <input type="text" name="price" /><br />beschrijving: <input type="text" name="discription"><br />levertijd:<input type="text" name="delivery"><br />update: <input type="submit" value="update geselecteerde product" /></body></html>

So that's it. hopefully i didnt make a silly mistake but any help is apreciated

Link to comment
Share on other sites

you should paste the code with WHERE clause which is actualy creating problem.can you show that?what is happening when you use where clause? is it showing any errors?

Link to comment
Share on other sites

you should paste the code with WHERE clause which is actualy creating problem.can you show that?what is happening when you use where clause? is it showing any errors?
The problem is it doesn't display anything at all. even if i replace my variable with a string value like 'z'
$theProduct = $_POST['productQuery'];//this is the query that refuses my WHERE command$query = mysql_query("SELECT * FROM producten WHERE productname=$theProduct");

would i replace that withWHERE productname='z'it still turns out blank

Link to comment
Share on other sites

if the sepcified value does not exist in that column it will return a empty resultset. are you sure what you are passing in productname exist in database?

Link to comment
Share on other sites

if the sepcified value does not exist in that column it will return a empty resultset. are you sure what you are passing in productname exist in database?
yes the productname colum exists in my table, perhaps i'm doing something wrong in my form i'll post it and hopefully it's somewhat usefull
<form name="input" action="fetch_edit.php" method="post">productnaam: <input type="text" name="productQuery" /><br />console: <select>  <option>xbox 360</option>  <option>playstation 3</option>  <option>wii</option></select><br />fetch: <input type="submit" value="zoek product" /></form>

Link to comment
Share on other sites

yes the productname colum exists in my table
i mean the value you are trying to match in productname column..is that value exist in the database?you can put
echo mysql_num_rows($query);

after the mysql_query() statement. it will confirm if any rows are returning or not if its shows you zero then your where clause is unable to match any result.and another thing here in your select tag you should specify the name atribute and in option tag you should specify the value attribute so after the submit of the form it will go as name=value pair from the drop down.

Link to comment
Share on other sites

i mean the value you are trying to match in productname column..is that value exist in the database?you can put
echo mysql_num_rows($query);

after the mysql_query() statement. it will confirm if any rows are returning or not if its shows you zero then your where clause is unable to match any result.and another thing here in your select tag you should specify the name atribute and in option tag you should specify the value attribute so after the submit of the form it will go as name=value pair from the drop down.

alright, your right about the rows not returning anything runing mysql_num_rows returns 0, After that i decided to check what's in my $theProduct variable and displayed it with a echo. It did display the value i inserted in the form so i think it's safe to assume the value goes from A to B. I'm not entirely sure about my syntax here
 $query = mysql_query("SELECT * FROM producten WHERE productname='$theProduct'");

Link to comment
Share on other sites

I solved the problem for the time being with a LIKE command. Just a small question whenever i search for a title like the adventure of.... i only get the written down how do i deal with that?

Link to comment
Share on other sites

the syntax is looking good and should work.if you are unsure about a query is succesfull or now you can always check for error if $query is false using mysql_error()

Link to comment
Share on other sites

I solved the problem for the time being with a LIKE command. Just a small question whenever i search for a title like the adventure of.... i only get the written down how do i deal with that?
sorry i did not understand the question
Link to comment
Share on other sites

sorry i did not understand the question
For some reason the title "the adventure of" get's cut down to "the" and i'm not sure why and how i can fix this
Link to comment
Share on other sites

i am not sure which title are you refering for.

Link to comment
Share on other sites

i am not sure which title are you refering for.
From the products i want to update for example i have the game killzone 3 in my table but when i want to edit it the productname only says: killzone. So it cut off the 3
Link to comment
Share on other sites

still not sure i think i am loosing the context. are you refering in the above code? if not then please post the code.

Link to comment
Share on other sites

You're not quoting values correctly. With this, for example:<input type="text" name="newProductname" value=<?php echo $game; ?> >If you have a name with spaces it prints out like this:<input type="text" name="newProductname" value=the adventures >Without quotes, it sees the value of the "value" attribute as "the", and it sees "adventures" as the name of another attribute, not part of the value of the previous attribute. Originally your query also was missing quotes around the value you were searching for, but it looks like you added those.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...