As a beginner, I designed a website using php, but unfortunately I found difficulty with 3 codes. I have already written them but am not sure why they didn't work . Please check it for me…
There are:
1-changing pending status to accept or reject from admin ,,,

<?php

session_start();
  $_SESSION['UserName'] = $UserName;
  $_SESSION['Password'] = $Password;

$sql="update product_customer SET Status ='$Status' where OID='$OID'";
$result = mysql_query($sql);

echo"<br><br><br><br><br><br><br><br><br><font size='6' face='Lucida Handwriting' color='#CCCCCC'>";
echo "<br><br>the admin has been decided ..<br><br>";
echo"</font>";

header("location:search.php");
//////////////////////////////
//this is accept code
<?php
session_start();

  $_SESSION['UserName'] = $UserName;
  $_SESSION['Password'] = $Password;

  include ("connect.php");
  
  $sql1 = "select * from product_customer where Status  = 'Accept' and UserName ='$UserName' ";
  $result1 = mysql_query($sql1);
  
  echo "<table width=300 border=1 >
<tr>
<td width=100 bgcolor=#BCE954><b><font size=2 color=#000000 ><center>OID</font></b></td>
<td width=100 bgcolor=#BCE954><b><font size=2 color=#000000 ><center>PID</font></b></td>
<td width=100 bgcolor=#BCE954><b><font size=2 color=#000000><center>UserName</font></b></td>
<td width=100 bgcolor=#BCE954><b><font size=2 color=#000000><center>Status</font></b></td>
<tr>
<table>";

while ($row1=@mysql_fetch_array($result1))

{

$i++;

 echo"
<table border=1 width=832 id=table1 >
<tr>
		<td width=73 >".$row1['OID']."</td>
        <td  width=115 >".$row1['PID']."</td>
		<td  width=106 >".$row1['UserName']."</td>
		<td  width=113 >".$row1['Status']."</td>
  
       <td width=50 ><a href=pay.php?OID=".$row1['OID']."&&PID=".$row1['PID'].">Pay</a></td>




 </tr>
</table> ";

}
2-Adding product to the database and delete it. (phpMyAdmin) The problem is that the product is added to the list on the website(localhost), but not on the database(phpmyadmin)<?php

session_start();
  $_SESSION['UserName'] = $UserName;
  $_SESSION['Password'] = $Password;


//echo "<a href=logout.php>Logout</a> <br><br>Welcome $username";

include ("connect.php");


$sql= "insert into products values(         '$PID',
                                            '$Model',
                                            '$manufacture',
                                            '$PColor',
                                            '$PPrice',
                                            '$PQuantity',
                                            '$PCategory')";


mysql_query($sql) or die ("Could not Insert the new record becouse of either Syntax error or a database problem");

header ('Location:admin_prod.php');

?>

3-editing product features such as delete or update product

<?
  include ("top.php");
?>

<?php
 //session_start();
  $_SESSION['UserName'] = $UserName;
  $_SESSION['Password'] = $Password;

include ("connect.php");
echo "<table>
<tr>
<td width = 200> <b><font size=3 color=ff0000 >$UserName </font></b></td>
<tr>
<table>
";
include ("connect.php");

$_GET['UserName'] = $UserName;
$_GET['Password'] = $Password ;

echo "Delete a product by clicking on the product ID..";

$sql = "SELECT * FROM products ";
$result = mysql_query($sql)or die ("could Not execute query $sql");
echo "<table width = 600 border=1 >
<tr>
<td width=100 bgcolor=#BCE954><b><font size=2 color=#000000> <center>PID</font></b></td>
<td width=100 bgcolor=#BCE954><b><font size=2 color=#000000> <center>Model</font></b></td>
<td width=100 bgcolor=#BCE954><b><font size=2 color=#000000> <center>PColor</font></b></td>
<td width=100 bgcolor=#BCE954><b><font size=2 color=#000000> <center>PPrice</font></b></td>
<td width=100 bgcolor=#BCE954><b><font size=2 color=#000000> <center>PQuantity</font></b></td>
<td width=100 bgcolor=#BCE954><b><font size=2 color=#000000> <center>PCategory</font></b></td>




<tr>
<table>";

WHILE($row=@mysql_fetch_array($result)) {


echo "<table width = 600 border=1 >
<tr>
<td width = 100> <a href=deletform.php?PID = ".$row["PID"]."> ".$row["PID"]."</a></td>
<td width = 100>  ".$row["Model"]." </td>
<td width = 100>  ".$row["PColor"]." </td>
<td width = 100>  ".$row["PPrice"]." </td>
<td width = 100>  ".$row["PQuantity"]." </td>
<td width = 100>  ".$row["PCategory"]." </td>
<tr>
<table>";
}

?>
 <?


include ("buttom.php");

///////
///this is deleteform.php
$sql = "DELETE FROM products where PID = '$PID'"or die ("ERROR: Cannot not find user!");

$result = mysql_query($sql) or die ("Error in query: $sql. ".mysql_error());

Recommended Answers

All 2 Replies

By "didn't work" you mean? It would be a little easier to help you can explain the problem further.

Also, what are you trying to do with:

$_SESSION['UserName'] = $UserName;
$_SESSION['Password'] = $Password;

at the top of every page. I was confused by that.

As a beginner, I designed a website using php, but unfortunately I found difficulty with 3 codes. I have already written them but am not sure why they didn't work ....

I'll remark on the first proggy. A few obligatory questions. How is the status getting from the browser to the server so the PHP code can work with it? Where are the username and password coming from?

One typical way of doing this sort of thing:

  • start the page's output
  • fetch the vars passed from the browser in $_GET or $_POST
  • handle any actions passed from the browser (the user or admin)
  • prepare remainder of web page HTML
  • have a form somewhere in the HTML that passes values from the browser to the host via $_GET or $_POST; this includes static and dynamic data
  • end the page's output

Your href's could do the trick if you only have static data to pass back.

In a way, PHP (the server end) harkens back to the olden days of batch "input, process, output", though it's more like "receive, process, transmit". The browser end is more like "receive, display, input, transmit". Your program almost seems to follow this, but there seem to be parts missing.

N

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.