Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit Records in a database using PHP forms

Status
Not open for further replies.

likelylad

IS-IT--Management
Jul 4, 2002
388
GB
I have a form with 2 field types.
1) a text box
2) a dropdown listbox

I am trying to run a search of the database so that I can edit a record.
My problem is that I can not display the records on the form.

The form contains a field called order_naumber
A number is put into this field, the submit button is hit and the records should appear in the relevent boxes.
I have pasted the code I am using below.

Secondly I need the dropdown list box to appear with the data from the database. The user may decide to choose another option from the droplist.

Thanks in advance for any help received

<html>
<body>
<form method=&quot;POST&quot; action=&quot;<b>Order Details:</b><input type=&quot;Text&quot; name=&quot;order_details&quot; value=&quot;<?php echo $myrow4[Order_Desc] ?>&quot;><br><br>
<b>Enter Order Number:</b><input type=&quot;Text&quot; name=&quot;order_number&quot;><br><br>
<?php // begin php code
$db = mysql_connect(&quot;10.40.1.1&quot;, &quot;root&quot;, &quot;&quot;) or die ('Cannot connect to database');
mysql_select_db(&quot;Logo_Dept&quot;,$db) or die ('database not available');
$sql='SELECT Product_Cat FROM product_category';
$result = mysql_query($sql,$db);
echo &quot;<select name=product_category>\n&quot;;
while ($row = mysql_fetch_array($result)) {
echo &quot;<option value=$row[0]>$row[0]</option>\n&quot;;
}
echo &quot;</select>\n&quot;;
?>
<input type=&quot;Submit&quot; name=&quot;submit&quot;>
</form>

<?php

if(isset($_POST[submit])){

$db = mysql_connect(&quot;localhost&quot;, &quot;root&quot;);

mysql_select_db(&quot;records&quot;,$db);

$sql4 = &quot;Select * from record_information Where (left(Order_Desc,7))= $_POST[order_number]&quot;;
$result4=mysql_query($sql4,$db);
$myrow4=mysql_fetch_array($result4);
}
?>
</body>
</html
 
$sql4 = &quot;Select * from record_information Where (left(Order_Desc,7))= $_POST[order_number]&quot;;

should be

$sql4 = &quot;Select * from record_information Where left(Order_Desc,7) = '$_POST[order_number]'&quot;;
______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
OK creative time then, what we'll do is set the left(Order_desc,7) as a variable in the select statement.
This will stop the query from trying to do a select in the where statement and everything should be fine.

$sql4 = &quot;Select *,@leftdes:=left(Order_Desc,7) from record_information Where @leftdes = '$_POST[order_number]'&quot;;
______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Hi KarveR

Thanks for the help, but still no joy.
I don't think the problem is with the SQL statement.
I tried the following
$sql4 = &quot;Select * from record_information Where left(Order_Desc,7) = 1234567&quot;;

If I dumped the output to a table then I could see the results, however it will not show up in the form where I would like to see it.
 
Hi KarveR

Sorry you where correct in assuming that the problem was the SQL statement

I reduced the code to only 2 text boxes and I eventually got it to work

$sql4 = &quot;Select * from record_information where Left(Order_Desc,7)= '$_POST[order_number]'&quot;;

However I would be greatful if you could point me in the right direction for the dropdown list
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top