Edit mysql data

Hey, im trying to make a code that will will one the first page make a list of items for the specific input the user gives.

And then when the user press edit next to the item open a page where the user can edit the info stated in the database

But atm I can’t seem to get the code to send the data when the user presses edit.

It only transfers to the edit.php but it doesen’t enter the data in the input box.

Here is the 2 codes.

test_edit.php
[php]<?php
error_reporting (E_ALL ^ E_NOTICE);
session_start();
$userid = $_SESSION[‘userid’];
$username = $_SESSION[‘username’];
?>

<?php require ('config.php'); $field = mysql_query("SELECT * FROM Field_Data")or die (mysql_error()); $dep = mysql_query("SELECT * FROM Department_Data")or die (mysql_error()); echo " Choose Week: "; while ($row = mysql_fetch_array($field)){ echo '' . $row['week'] . '';} echo "
"; echo " Choose year:
"; echo " Choose Department: "; while ($row2 = mysql_fetch_array($dep)){ echo '' . $row2['name'] . '';} echo "
"; echo " "; ?> <?php if (isset($_POST['submit'])){ $week_r = $_POST['week']; $dep_r = $_POST['department']; $sql=mysql_query("SELECT * FROM `Marketing` WHERE Week = '$week_r' and Department = '$dep_r'"); if (mysql_num_rows($sql) < 0){ $output = "Sorry there is no data with these values"; }else{ echo ""; while ($rows = mysql_fetch_array($sql)){ echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ""; echo ""; echo ""; } } } echo $form; ?>

[/php]

edit.php

[code]<?php
require (‘config.php’);

if (isset($_GET['marketing']))
{
	$id = $_GET['marketing'];
	$res = mysql_query("SELECT * `Marketing` WHERE ID='$id'");
	$row = mysql_fetch_array($res);
}
else
{
	echo "Error no data was send";	
}

if (isset($_POST['newweek']))
{
	$newweek = $_POST['newweek'];
	$id = $_POST['id'];
	$sql = "UPDATE Marketing SET Week='$newweek' WHERE ID='$id'";
	$res = mysql_query($sql);
}

?>

Week
[/code]
Week Brand Product Department Group Number Product Type Display Type Count Price Goodsnr Username
'. $rows['Week'] .''. $rows['Brand'] .''. $rows['Product'] .''. $rows['Department'] .''; echo ' '. $rows['Group'] .''. $rows['Number'] .''. $rows['ProductType'] .''. $rows['DisplayType'] .''. $rows['Count'] .''. $rows['Price'] .''. $rows['Goodsnr'] .''. $rows['Username'] .'edit

mysql_query(“SELECT * FROM Marketing WHERE ID=’$id’”);

Double check all variables being sent if your getting stuck.
Comment blocks out and echo the variables to make sure everything is being sent correctly.
If it isn’t then you know where to look.

Also make sure to protect your mysql from $_POST[‘newweek’]

Dont use old Mysql calls. Use PDO or mysqli

add this to the bottom of your script, you should see where your problem lies…

[php] ##Debugging
var_dump ($dep);
var_dump ($dep_r);
var_dump ($field);
var_dump ($output);
var_dump ($row);
var_dump ($row2);
var_dump ($sql);
var_dump ($userid);
var_dump ($username);
var_dump ($week_r);
var_dump ($rows);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service