updating a mysql database via php form

Soldato
Joined
10 Apr 2006
Posts
7,890
Location
North West
When i click the submit button i get this error:

Not Found

The requested URL /my ver/< was not found on this server.


Here is the HTML of the page, i think its an error in the form but not sure as I'm new to php/mysql.

Any help to why i get this will be very appreciated, need to get this fixed by tonight can I can't think why it's doing this

Code:
<div id="MainContent">
	<h1>Edit Sweet</h1>
	<div id="EditSweetContent">		
		<div id="Edit_Sweet">
			<h1><?php echo $row["sName"]; ?> <br/></h1>
			<?php 
			echo "<form method='post' action='<?php echo $PHP_SELF;?>'>";
			echo "Sweet Name:<br/><input type='text' name='sName' value='" . $row['sName'] . "' size='60%' /></input><br/>";
			echo "Sweet Category:<br/><input type='text' name='sCategory' value='" . $row['sCategory'] . "' size='60%' /></input><br/>";			
			echo "Short Description:<br/><input type='text' name='sShortDesc' value='" . $row['sShortDesc'] . "' size='60%' /></input><br/>";			
			echo "Long Description:<br/><textarea rows='10' cols='59' name='sLongDesc' wrap='physical' size='60%'>" . $row['sLongDesc']  . "</textarea><br/>";
			echo "Price:<br/><input type='text' name='sPrice' value='&pound;" . $row['sPrice'] . "' size='60%' /></input><br/>";	
			echo "Price Per:<br/><input type='text' name='sPriceper' value='" . $row['sPricePer'] . "' size='60%' /></input><br/>";			
			echo "Picture:<br/>";
			$query = "SELECT DISTINCT * FROM `sweets`";
			$results = mysql_query($query);
			$row = mysql_fetch_array($results);
			echo "<select>";
			while($row = mysql_fetch_array($results))
				{
				echo "<option>" . $row['sImgName'] . "</option>";
				}	
			echo "</select><br/>";
			echo "Stock Level:<br/><input type='text' value'" . $row['sStock'] . "' size='auto' /></input><br/><br/>";
			echo "<input type='submit' value='Submit Edited Sweet' name='submit'></input>";
			echo "</form>";
			?> 
			
			<br/>
		</div>
	</div>
</div>

and the php:

PHP:
<?php
require("functions.php"); //Gets all the functions
dbConnect(); //Connects to the database
html_sec("header"); //Adds Header tags for HTML
$query = "SELECT * FROM `sweets` WHERE uid = {$_GET['id']}";
$results = mysql_query($query);
$row = mysql_fetch_array($results);

$uid = $_POST['uid'];
$sName = $_POST["sName"];
$sCategory = $_POST["sCategory"];
$sShortDesc = $_POST["sShortDesc"];
$sLongDesc = $_POST["sLongDesc"];
$sPrice = $_POST["sPrice"];
$sPricePer = $_POST["sPricePer"];
$sStock = $_POST["sSTock"];
$sGelatinFree = $_POST["sGelatinFree"];
$sSugarFree = $_POST["sSugarFree"];
$sGlutenFree = $_POST["sGlutenFree"];

?>
 
oof, the form action had some mumbojumbo in it.

I changed that and it now loads the page that i tell it to.

ie change the form action to

echo "<form method='post' action='sweet.php?id=" . $row['uid'] . "'>";

So once the sweet info is updated it goes to the sweets page so you can see the updated item.

But now another question!

How do I get the submit button to update the database.
I created the query :
PHP:
mysql_query("UPDATE sweets SET sName=$sName, sCategory=$sCategory, sShortDesc=$sShortDesc, sLongDesc=$sLongDesc, sPrice=$sPrice, sPricePer=$sPricePer, sStock=$sStock  WHERE uid=$uid");

but how do I get it to read the data from the form and actually carry out the query on the database?

Do I have to set the submit button to go to something like sweet_updated.php?id=1
and within that call the query from the last page into action ?

Thanks!
 
thanks for the help!

Does anyone know how to do a proper logout.php ?

session_destroy();

Doesnt work properly, I've tried a few other things but they all do the same.

Heres Logout.php

PHP:
<?php
$url = "index.php"; // target of the redirect
$delay = "1"; // 1 second delay before the new page is shown

session_destroy();

echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';
?>

The full admin.php page:

PHP:
<?php
session_start();
require("functions.php"); //Gets all the functions
dbConnect(); //Connects to the database
$page = $_GET['p'];

if (isset($_SESSION['user']) == false || $_SESSION['user'] = "") {
	if ($page != 1) {
		html_sec("header"); //Adds Header tags for HTML
?>
<div>
<div id="AdminLogin">
    <h1>Admin Login Section</h1>
	<form action ="admin.php?p=1" method="post" id="LoginForm">
        <ul>
			<li><input type="text" name="user" value="Username" /></li></input></li><br/>
			<li><input type="password" name="pass" value="Password" /></li></input></li><br/>
			<li><input type="submit" value="Login" /></li>
		</ul>
    </form>
</div>
</div>
<?php
		html_sec("footer"); //Adds Footer tags for HTML
	} else if ($page = 1) {

		$username = $_POST['user'];
		$password = $_POST['pass'];

		$result = mysql_query("SELECT * FROM login WHERE username='".$username."' and password='".$password."'");
		if (mysql_num_rows($result) > 0) {
    	    $_SESSION['user'] = $username;
            $url = "admin_area.php"; // target of the redirect
	        $delay = "0"; // 3 second delay

			echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';
		} else {
			html_sec("header"); //Adds Header tags for HTML
?>
   <div id="AdminLogin">
      <h1>Admin Login Error</h1>
      <form action ="admin.php?p=1" method="post" id="LoginForm">
        <ul>
          <li><input type="text" name="user" value="Username" /></li></input></li><br/>
          <li><input type="password" name="pass" value="Password" /></li></input></li><br/>
          <li><input type="submit" value="Login" /></li>
        </ul>
    </div>
  </form>
<?php
			html_sec("footer"); //Adds Footer tags for HTML
		}
	}
}

if (isset($_SESSION['user']) == true || $_SESSION['user'] = "") {
	if ($page != 1) {
		html_sec("header"); //Adds Header tags for HTML
?>
<div id="AdminLogin">
    <h1>Already Logged In!</h1>
	For The Admin Area <a href="admin_area.php">Click Here</a><br/><br/>
    To Logout <a href="logout.php">Click Here</a>
</div>
<?php
		html_sec("footer"); //Adds Footer tags for HTML
	}}
dbClose(); //Closes the database connection
?>
 
Back
Top Bottom