yoshee08
-
Posts
2 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Downloads
Gallery
Store
Posts posted by yoshee08
-
-
Hi Ben,
I followed your script along (very nicely done by the way)and I had an issue for the edit.php page. As you can see, (after this) I added a few things to it. The delete page, view page all work fine, but when I go to this page (and yes, I have check words and spelling)it shows this (not the word places):
Warning: Missing argument 6 for renderForm(), called in /home/content/26/8887926/html/Yoshee08/troop3/edit.php on line 110 and defined in /home/xxx/xxx/xxx/xxx/edit.php on line 9
ID: 2
Name: * [_____]
type: *[_____]
out: *[_____]
out by who: *[_____]
* Required
SUBMIT(button is here)
once i submit the form, it shows this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'out = '1', outbywho = 'yoshee' WHERE id='2'' at line 1
What could be the problem? Heres the page code..
<?php /* EDIT.PHP Allows user to edit specific entry in database */ // creates the edit record form // since this form is used multiple times in this file, I have made it a function that is easily reusable function renderForm($id, $name, $type, $out, $outbywho, $error) { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Edit Record</title> </head> <body> <?php // if there are any errors, display them if ($error != '') { echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>'; } ?> <form action="" method="post"> <input type="hidden" name="id" value="<?php echo $id; ?>"/> <div> <p><strong>ID:</strong> <?php echo $id; ?></p> <strong>Name: *</strong> <input type="text" name="name" value="<?php echo $name; ?>"/><br/> <strong>type: *</strong> <input type="text" name="lastname" value="<?php echo $type; ?>"/><br/> <strong>out: *</strong> <input type="text" name="out" value="<?php echo $out; ?>"/><br/> <strong>out by who: *</strong> <input type="text" name="outbywho" value="<?php echo $outbywho; ?>"/><br/> <p>* Required</p> <input type="submit" name="submit" value="Submit"> </div> </form> </body> </html> <?php } // connect to the database include('connect-db.php'); // check if the form has been submitted. If it has, process the form and save it to the database if (isset($_POST['submit'])) { // confirm that the 'id' value is a valid integer before getting the form data if (is_numeric($_POST['id'])) { // get form data, making sure it is valid $id = $_POST['id']; $name = mysql_real_escape_string(htmlspecialchars($_POST['name'])); $type = mysql_real_escape_string(htmlspecialchars($_POST['type'])); $out = mysql_real_escape_string(htmlspecialchars($_POST['out'])); $outbywho = mysql_real_escape_string(htmlspecialchars($_POST['outbywho'])); if ($name == '') { // generate error message $error = 'ERROR: Please fill in all required fields!'; //error, display form renderForm($id, $name, $type, $out, $outbywho, $error); } else { // save the data to the database mysql_query("UPDATE equipment SET name = '$name', type = '$type', out = '$out', outbywho = '$outbywho' WHERE id='$id';") or die(mysql_error()); // once saved, redirect back to the view page header("Location: view.php"); } } else { // if the 'id' isn't valid, display an error echo 'Error!'; } } else // if the form hasn't been submitted, get the data from the db and display the form { // get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0) if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0) { // query db $id = $_GET['id']; $result = mysql_query("SELECT * FROM equipment WHERE id=$id") or die(mysql_error()); $row = mysql_fetch_array($result); // check that the 'id' matches up with a row in the databse if($row) { // get data from db $name = $row['name']; $type = $row['type']; $out = $row['out']; $outbywho = $row['outbywho']; // show form renderForm($id, $name, $type, $out, $outbywho); } else // if no match, display result { echo "No results!"; } } else // if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error { echo 'Error!'; } } ?>
Basic Php System: View/edit/delete/add Records
in PHP
Posted
Also on the new.php page (code below), the form displays, but when it submits, it shows this.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''equipment' ('name','type','out','outbywho') VALUES ('','','','' at line 1