Jump to content

Simpson

New Members
  • Posts

    4
  • Joined

  • Last visited

Simpson's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thx, I knew i had missed something, just could't see it
  2. Hey, I wrote this code, to make a dynamic table, but I keep getting Syntax error, and I can't see where that error is, plz help. mysql_connect ("localhost", "USERNAME", "PASSWORD") or die ('I cannot connect to the database because: ' . mysql_error()); // Select the database mysql_select_db ("DATABASE") or die ("Could not select database"); // Store Settings $gable_max_colo = "9"; $box_max_fresh = "2"; $box_max_frozen = "2"; // Getting data $dep = 'Colonial'; $displayT = 'Gable'; $res = mysql_query("SELECT * FROM Marketing WHERE Year='".$_POST['year']."' and Week='".$_POST['week']."'"); while ($row = mysql_fetch_array($res)){ $dep = $row['Department']; $displayT = $row['DisplayType']; if ($dep == 'Colonial'){ if ($displayT == 'Gable'){ $number = '1'; while ($number > $gable_max_colo){ $result = mysql_query("SELECT * FROM Marketing WHERE Year'".$_POST['year']."' and Number='".$number."' and DisplayType='".$displayT."' and Department='".$dep."' and Week='".$_POST['week']."'"); $html_start = '<h2>Endegavl'.$number.'</h2> <table border="1" cellspacing="4" cellpadding="4"> <tr> <th>Brand</th> <th align="right">Product</th> <th align="left">Type</th> <th>Price</th> </tr>'; while ($row = mysql_fetch_array($result)){ $Product = $row['Product']; $Brand = $row['Brand']; $Price = $row['Price']; $ProductT = $row['ProductType']; $Count = $row['Count']; $Goods = $row['Goodsnr']; $html_inside .= ' <tr> <td>'.$Brand.'</td> <td>'.$Product.'</td> <td>'.$Type.'</td> <td>'.$Price.'</td> </tr>'; } $html_end = '</table>'; $number = $number + 1; } } } echo $html_start; echo $html_inside; echo $html_end;
  3. Hey, Im trying to make a page that will show the content from a database in a table, with an edit link to every row. So that when the user presses the link it goes to the edit.php file where he/she then can edit the content in the datebase with the specific id. I can get it to show the content in the table and to send the user to edit.php when edit is pressed, but I can't get it to transfer over the information to the edit.php. As i wannt my text input to have the value of the content currently in database, so its easier to edit. Here is the 2 codes. test_edit.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?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 "<form action='test_edit.php' method='POST'> <label> Choose Week: <select name='week' size='1' id='week'>"; while ($row = mysql_fetch_array($field)){ echo '<option value=' . $row['week'] . '>' . $row['week'] . '</option>';} echo "</select> </label><br />"; echo "<label> Choose year: <input type='text' name='year' value='2014' /><br />"; echo "<label> Choose Department: <select name='department' size='1' id='department'>"; while ($row2 = mysql_fetch_array($dep)){ echo '<option value=' . $row2['name'] . '>' . $row2['name'] . '</option>';} echo "</select> </label><br />"; echo "<input type='submit' value='show' name='submit' /> </form>"; ?> <?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 "<table id='marketing'> <thead> <th>Week</th> <th>Brand</th> <th>Product</th> <th>Department</th> <th>Group</th> <th>Number</th> <th>Product Type</th> <th>Display Type</th> <th>Count</th> <th>Price</th> <th>Goodsnr</th> <th>Username</th> </thead> <tbody>"; while ($rows = mysql_fetch_array($sql)){ echo '<tr>'; echo '<td>'. $rows['Week'] .'</td>'; echo '<td>'. $rows['Brand'] .'</td>'; echo '<td>'. $rows['Product'] .'</td>'; echo '<td>'. $rows['Department'] .''; echo '<td>'. $rows['Group'] .'</td>'; echo '<td>'. $rows['Number'] .'</td>'; echo '<td>'. $rows['ProductType'] .'</td>'; echo '<td>'. $rows['DisplayType'] .'</td>'; echo '<td>'. $rows['Count'] .'</td>'; echo '<td>'. $rows['Price'] .'</td>'; echo '<td>'. $rows['Goodsnr'] .'</td>'; echo '<td>'. $rows['Username'] .'</td>'; echo "<td><a href='edit.php?=". $rows['ID'] ."'>edit</a></td>"; echo "</tr>"; echo "</tbody>"; } } } echo $form; ?> </body> </html> edit.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?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); } ?> <form action="edit.php" method="post"> <label>Week<input type="text" name="newweek" value="<?php echo $row[1]; ?>"></label><br /> <input type="hidden" name="id" value="<?php echo $row[0]; ?>"> <input type="submit" value="Update"> </form> </body> </html> I hope you guys can see where the error is, as I can't seem to find it.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.