Jump to content

ace2go

New Members
  • Posts

    8
  • Joined

  • Last visited

ace2go's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I cannot view data based upon my "wid" in the following code. Basically I have a page that you click on a link, and it passes a number to the "wid" as an integer. I want to call on that corresponding table that has a "like" wid. Here is what I have so far... <?php require 'database.php'; if(!empty($_GET['wid'])) { $wid = $_GET['wid']; } else { $wid = null; } if ( null==$wid ) { header("Location: workorders.php"); } else { $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = 'SELECT * FROM items where wid = ?'; $rows = $pdo->query($sql); foreach ($pdo->query($sql) as $row) { echo '<tr>'; echo '<td>'. $row['id'] . '</td>'; echo '<td>'. $row['wid'] . '</td>'; echo '<td>'. $row['model'] . '</td>'; echo '<td>'. $row['description'] . '</td>'; echo '<td>'. $row['cost'] . '</td>'; echo '<td>'. $row['retail'] . '</td>'; echo '<td>'. $row['tax'] . '</td>'; echo '<td width=250>'; } Database::disconnect(); } ?>
  2. Full working code : <?php require 'database.php'; if(!empty($_GET['name'])) { $name = $_GET['name']; } elseif(!empty($_POST['name'])) { $name = $_POST['name']; } else { $name = null; } if ( !empty($_POST)) { // keep track validation $ $dateError = null; $installerError = null; $salesmanError = null; $categoryError = null; $statusError = null; // keep track post values $date = $_POST['date']; $installer = $_POST['installer']; $salesman = $_POST['salesman']; $category = $_POST['category']; $status = $_POST['status']; // validate input $valid = true; if (empty($date)) { $dateError = 'Please enter Date'; $valid = false; } if (empty($installer)) { $installerError = 'Please enter Installer'; $valid = false; } if (empty($salesman)) { $salesmanError = 'Please enter Salesman'; $valid = false; } if (empty($category)) { $categoryError = 'Please enter Category'; $valid = false; } if (empty($status)) { $statusError = 'Please enter Status'; $valid = false; } // insert data if ($valid) { $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "INSERT INTO workorder (name, date, installer, salesman, category, status) values(?, ?, ?, ?, ?, ?);"; $q = $pdo->prepare($sql); $q->execute(array($name,$date,$installer,$salesman,$category,$status)); Database::disconnect(); header("Location: workorders.php"); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <link href="css/bootstrap.min.css" rel="stylesheet"> <script src="js/bootstrap.min.js"></script> </head> <body> <div class="container"> <div class="span10 offset1"> <div class="row"> <h3>Create a Workorder</h3> </div> <form class="form-horizontal" action="createworkorder.php" method="post"> <input type="hidden" name="name" value="<?php echo htmlentities($name); ?>"> <div class="control-group <?php echo !empty($dateError)?'error':'';?>"> <label class="control-label">Date</label> <div class="controls"> <input name="date" type="text" placeholder="Date" value="<?php echo !empty($date)?$date:'';?>"> <?php if (!empty($dateError)): ?> <span class="help-inline"><?php echo $dateError;?></span> <?php endif; ?> </div> </div> <div class="control-group <?php echo !empty($installerError)?'error':'';?>"> <label class="control-label">Installer</label> <div class="controls"> <input name="installer" type="text" placeholder="Installer" value="<?php echo !empty($installer)?$installer:'';?>"> <?php if (!empty($installerError)): ?> <span class="help-inline"><?php echo $installerError;?></span> <?php endif;?> </div> </div> <div class="control-group <?php echo !empty($salesmanError)?'error':'';?>"> <label class="control-label">Salesman</label> <div class="controls"> <input name="salesman" type="text" placeholder="Salesman" value="<?php echo !empty($salesman)?$salesman:'';?>"> <?php if (!empty($salesmanError)): ?> <span class="help-inline"><?php echo $salesmanError;?></span> <?php endif;?> </div> </div> <div class="control-group <?php echo !empty($categoryError)?'error':'';?>"> <label class="control-label">Category</label> <div class="controls"> <input name="category" type="text" placeholder="Category" value="<?php echo !empty($category)?$category:'';?>"> <?php if (!empty($categoryError)): ?> <span class="help-inline"><?php echo $categoryError;?></span> <?php endif; ?> </div> </div> <div class="control-group <?php echo !empty($statusError)?'error':'';?>"> <label class="control-label">Status</label> <div class="controls"> <input name="status" type="text" placeholder="Status" value="<?php echo !empty($status)?$status:'';?>"> <?php if (!empty($statusError)): ?> <span class="help-inline"><?php echo $statusError;?></span> <?php endif; ?> </div> </div> <div class="form-actions"> <button type="submit" class="btn btn-success">Create</button> <a class="btn" href="workorders.php">Back</a> </div> </form> </div> </div> <!-- /container --> </body> </html> Thanks to everyone for their help!!!
  3. how do I add that hidden form field? If I pass it along with the form results(in the form), how do I retain the value that was presented from the other page? @cyberRobot : Yes, the page is called "createworkorder.php", the values are passed from a page called "customers.php"
  4. my code as of yet : <?php require 'database.php'; $id = null; if ( !empty($_GET['id'])) { $id = $_REQUEST['id']; } if ( null==$id ) { header("Location: customers.php"); } if ( !empty($_POST)) { // keep track validation $ $dateError = null; $installerError = null; $salesmanError = null; $categoryError = null; $statusError = null; // keep track post values $id = $POST['name']; $date = $_POST['date']; $installer = $_POST['installer']; $salesman = $_POST['salesman']; $category = $_POST['category']; $status = $_POST['status']; // validate input $valid = true; if (empty($date)) { $dateError = 'Please enter Date'; $valid = false; } if (empty($installer)) { $installerError = 'Please enter Installer'; $valid = false; } if (empty($salesman)) { $salesmanError = 'Please enter Salesman'; $valid = false; } if (empty($category)) { $categoryError = 'Please enter Category'; $valid = false; } if (empty($status)) { $statusError = 'Please enter Status'; $valid = false; } // insert data if ($valid) { $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "INSERT INTO workorder (name, date, installer, salesman, category, status) values($id, ?, ?, ?, ?, ?);"; $q = $pdo->prepare($sql); $q->execute(array($date,$installer,$salesman,$category,$status)); Database::disconnect(); header("Location: workorders.php"); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <link href="css/bootstrap.min.css" rel="stylesheet"> <script src="js/bootstrap.min.js"></script> </head> <body> <div class="container"> <div class="span10 offset1"> <div class="row"> <h3>Create a Workorder</h3> <?php print_r($_GET); if($_GET["id"] === "") echo "a is an empty string\n"; if($_GET["id"] === false) echo "a is false\n"; if($_GET["id"] === null) echo "a is null\n"; if(isset($_GET["id"])) echo "a is set\n"; if(!empty($_GET["id"])) echo "a is not empty"; ?> </div> <form class="form-horizontal" action="createworkorder.php" method="post"> <div class="control-group <?php echo !empty($dateError)?'error':'';?>"> <label class="control-label">Date</label> <div class="controls"> <input name="date" type="text" placeholder="Date" value="<?php echo !empty($date)?$date:'';?>"> <?php if (!empty($dateError)): ?> <span class="help-inline"><?php echo $dateError;?></span> <?php endif; ?> </div> </div> <div class="control-group <?php echo !empty($installerError)?'error':'';?>"> <label class="control-label">Installer</label> <div class="controls"> <input name="installer" type="text" placeholder="Installer" value="<?php echo !empty($installer)?$installer:'';?>"> <?php if (!empty($installerError)): ?> <span class="help-inline"><?php echo $installerError;?></span> <?php endif;?> </div> </div> <div class="control-group <?php echo !empty($salesmanError)?'error':'';?>"> <label class="control-label">Salesman</label> <div class="controls"> <input name="salesman" type="text" placeholder="Salesman" value="<?php echo !empty($salesman)?$salesman:'';?>"> <?php if (!empty($salesmanError)): ?> <span class="help-inline"><?php echo $salesmanError;?></span> <?php endif;?> </div> </div> <div class="control-group <?php echo !empty($categoryError)?'error':'';?>"> <label class="control-label">Category</label> <div class="controls"> <input name="category" type="text" placeholder="Category" value="<?php echo !empty($category)?$category:'';?>"> <?php if (!empty($categoryError)): ?> <span class="help-inline"><?php echo $categoryError;?></span> <?php endif; ?> </div> </div> <div class="control-group <?php echo !empty($statusError)?'error':'';?>"> <label class="control-label">Status</label> <div class="controls"> <input name="status" type="text" placeholder="Status" value="<?php echo !empty($status)?$status:'';?>"> <?php if (!empty($statusError)): ?> <span class="help-inline"><?php echo $statusError;?></span> <?php endif; ?> </div> </div> <div class="form-actions"> <button type="submit" class="btn btn-success">Create</button> <a class="btn" href="workorders.php">Back</a> </div> </form> </div> </div> <!-- /container --> </body> </html>
  5. I can see the existence of $_GET['id'], the code I need is to set $id in the same script as the PDO query, that is already calling the other values from a form
  6. @maxxd How do I do this? the values in the array are from form fields that the user sends upon clicking the "submit" button. $id is an integer called from a prior page. I tried your code, and it does not even insert the array.
  7. I have the following code to pass the $id value(integer) : $id = null; if ( !empty($_GET['id'])) { $id = $_REQUEST['id']; } if ( null==$id ) { header("Location: customers.php"); } Passes successfully according to this code in the body : <?php print_r($_GET); if($_GET["id"] === "") echo "a is an empty string\n"; if($_GET["id"] === false) echo "a is false\n"; if($_GET["id"] === null) echo "a is null\n"; if(isset($_GET["id"])) echo "a is set\n"; if(!empty($_GET["id"])) echo "a is not empty"; ?> This code tries to insert data into a workorder table : if ($valid) { $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "INSERT INTO workorder (name, date, installer, salesman, category, status) values('$id', ?, ?, ?, ?, ?);"; $q = $pdo->prepare($sql); $q->execute(array($date,$installer,$salesman,$category,$status)); Database::disconnect(); header("Location: workorders.php"); } Breakdown : the $date, $installer, $salesman, $category, $status are retrieved from the form(and inserted fine), the $id is called from a prior page, gets a correct value, but is not accepted into the table. Does anyone have any ideas as to why that is?
×
×
  • 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.