Jump to content

Amanda-Lee

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Everything posted by Amanda-Lee

  1. Thanks guys I solved it. echo "<td><input name = 'product_id' type = 'hidden' value ='{$row['product_id']}'></td>"; changed to: echo "<td><input name = 'product_id' type = 'hidden' value ='{$row['product_id']}'><input name = 'pname' type = 'hidden' value ='{$row['product_name']}'><input name = 'prange' type = 'hidden' value ='{$row['product_range']}'><input name = 'pprice' type = 'hidden' value ='{$row['product_price']}'></td>";
  2. I worked on it my new code is <?php //check to see if user is logged on session_start(); if (!(isset($_SESSION['login']) && $_SESSION['login'] != "")) { header ("Location:login.php"); } include('connect.php'); //connection details to database in a connect.php page //if form was submitted if (isset($_POST['yes'])){ if (isset($_GET['product_id'])||isset($_POST['product_id'])||isset($_GET['pname'])|| isset($_POST['pname']) ||isset($_GET['prange'])||isset($_POST['prange'])||isset($_GET['pprice'])||isset($_POST['pprice'])){ if (isset($_GET['product_id'])|| isset($_GET['pname'])||isset($_GET['prange'])||isset($_GET['pprice'])){ $product_id = $_GET['product_id']; $productname = $_GET['pname']; $range = $_GET['prange']; $price = $_GET['pprice']; } if (isset($_POST['product_id'])|| isset($_POST['pname'])||isset($_POST['prange'])||isset($_POST['pprice'])){ $product_id = $_POST['product_id']; $productname = $_POST['pname']; $range = $_POST['prange']; $price = $_POST['pprice']; } } $query = "DELETE FROM products WHERE product_id = '$product_id'"; $result = mysql_query($query); print "<br> $productname from range $range with a price of R$price has been deleted!</br>"; } if (isset($_POST['no'])){ header ("Location:list.php"); } if (isset($_GET['product_id'])){ $product_id = $_GET['product_id']; $query = "SELECT * FROM products WHERE product_id = '$product_id'"; $result = mysql_query($query); echo "<form method = \"post\" action = \"delete.php\">"; while($row = mysql_fetch_array($result)){ echo "<table>"; echo "<tr>"; echo "<td><input name = 'product_id' type = 'hidden' value ='{$row['product_id']}'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>Do you really want to delete {$row['product_name']} from range {$row['product_range']} with a price of R{$row['product_price']} from the database?</td>"; echo "</tr>"; echo "<tr>"; echo "<td><input type = 'submit' name = 'yes' value = 'Yes'><input type = 'submit' name = 'no' value = 'NO'></td>"; echo "</tr>"; echo "</table>"; } echo "</form>"; } ini_set('error_reporting', E_ALL); ?> And the result I am getting is that the No option works great, the yes option deletes right but shows this on the page: Notice: Undefined index: pname in C:\Program Files (x86)\EasyPHP-5.3.3\www\delete.php on line 39 Notice: Undefined index: prange in C:\Program Files (x86)\EasyPHP-5.3.3\www\delete.php on line 40 Notice: Undefined index: pprice in C:\Program Files (x86)\EasyPHP-5.3.3\www\delete.php on line 41 from range with a price of R has been deleted!
  3. Darkfreaks Can I put it in anywhere between the <?php?> tag? And thank you for your help.
  4. *blush* the else part for the No option i left out because i needed to get the Yes part first!
  5. when you click Yes/No it display the delete page empty.
  6. Hi I am struggling with my last page for a project it is a delete page that retrieves data from a list, asks the user if he wants to delete that record if 'yes' delete it otherwise redirect to another page. My page looks like it should, but the function is not working. my code is: <?php //check to see if user is logged on session_start(); if (!(isset($_SESSION['login']) && $_SESSION['login'] != "")) { header ("Location:login.php"); } include('connect.php'); //connection details to database in a connect.php page //if form was submitted if (isset($_REQUEST['yes'])){ $product_id = $_GET['product_id']; $productname = $_POST['pname']; $range = $_POST['prange']; $price1 = $_POST['pprice']; $price = (int)$price1; $query = "DELETE FROM products WHERE product_id = '$product_id'"; $result = mysql_query($query); print "<br> $productname from range $range with a price of R$price has been deleted!</br>"; } } if (isset($_GET['product_id'])){ $product_id = $_GET['product_id']; $query = "SELECT * FROM products WHERE product_id = '$product_id'"; $result = mysql_query($query); echo "<form method = \"post\" action = \"delete.php\">"; while($row = mysql_fetch_array($result)){ echo "<table>"; echo "<tr>"; echo "<td><input name = 'product_id' type = 'hidden' value ='{$row['product_id']}'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>Do you really want to delete {$row['product_name']} from range {$row['product_range']} with a price of R{$row['product_price']} from the database?</td>"; echo "</tr>"; echo "<tr>"; echo "<td<input type = 'submit' name = 'yes' value = 'Yes'><input type = 'submit' name = 'no' value = 'NO'></td>"; echo "</tr>"; echo "</table>"; } echo "</form>"; } ?> Any help please?
  7. :D THANK YOU! THANK YOU, so so much, it works great!!!
  8. Drummin, thank you for your help. I tried your code but it gives me the following error: Notice: Undefined index: product_id in C:\Program Files (x86)\EasyPHP-5.3.3\www\edit.php on line 47 Line 47 is: $product_id = $_GET['product_id'];
  9. Thank you Thorpe I added the redirect page, but it does the same, when I edit for example "apple" and type in "grapes" it gives me apple again no changes were made!
  10. Hi can anyone please help me, I have to create a edit page that retrieves information from a list so that a user can change the text. The page looks fine but when I enter data in the fields and update it leaves the page as it was retrieved. I am a beginner! My code looks like this: <form method = "get" action = "edit.php"> <?php //check to see if user is logged on session_start(); if (!(isset($_SESSION['login']) && $_SESSION['login'] != "")) { header ("Location:login.php"); } include('connect.php'); //connection details to database in a connect.php page $product_id = $_GET['product_id']; $query = "SELECT * FROM products WHERE product_id = '$product_id'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)){ $product_id = $row['product_id']; echo "<table>"; echo "<tr>"; echo "<td><input name = 'product_id' type = 'hidden' value ='$row[product_id]'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>Product Name:</td><td><input name = 'pname' type = 'text' value ='$row[product_name]'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>Product Range:</td><td><input name = 'prange' type = 'text' value ='$row[product_range]'></td>"; echo "</tr>"; echo "<tr>"; echo "<td>Product Price:</td><td><input name = 'pprice' type = 'text' value ='$row[product_price]'></td>"; echo "</tr>"; echo "<tr>"; echo "<td><input type = 'submit' name = 'Submit' value = 'Update'></td>"; echo "</tr>"; echo "</table>"; } //if form was submitted if ($_SERVER['REQUEST_METHOD'] == 'POST'){ //get values from fields $productname = $_POST['pname']; $range = $_POST['prange']; $price1 = $_POST['pprice']; $price = (int)$price1; if ($productname == "" || $range == "" || $price == "" ) { $errorMessage .= "Please fill in all text boxes"; } else { $errorMessage = ""; } $query = "UPDATE products SET product_name = '$productname', product_range = '$range', product_price = '$price' WHERE product_id = '$product_id'"; $result = mysql_query($query); print "<br> $productname from range $range with a price of $price has been updated!"; } ?> Thank you in advance!
  11. MMDE I changed the following: if ($num_rows = 1){ to if ($num_rows == 1){ and it worked thank you SO SO much! Now to do the rest! Slowly I am learning!
  12. Jesirose Sorry for the code. Saw it was a mistake and tried to edit it before anyone saw it, my bad. I am new to php, and really can't see what i am doing wrong MMDE It should really be basic. It is a project and I only have to fillful to the basic criteria.
  13. Hey all I really need help with a project I am doing. I need to create a website with a registration form that checks if the user exists if not to add the user details to my local database MySQL. My webpage looks like it should, it connects with the database but when I enter a new user it does nothing when it should save the new user to the database! I am guessing my problem is within the if...else section. Please help my code is: <?php include('connect.php'); //connection details to database in a connect.php page $name = ""; $surname = ""; $username = ""; $password = ""; $confirmp = ""; $errorMessage = ""; $num_rows = 0; //if form was submitted if ($_SERVER['REQUEST_METHOD'] == 'POST'){ //get values from fields $submit = $_POST['Submit']; $title = $_POST['title']; $name = $_POST['name']; $surname = $_POST['surname']; $username = $_POST['username']; $password = $_POST['password']; $confirmp = $_POST['confirmp']; //getting string lengths $nameLength = strlen($name); $surnameLength = strlen($surname); $usernameLength = strlen($username); $passwordLength = strlen($password); $confirmpLength = strlen($confirmp); //testing if strings are between certain numbers if ($nameLength > 1 && $nameLength <= 20) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Name must be between 2 and 20 characters" . "<br>"; } if ($surnameLength >= 2 && $surnameLength <= 50) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Surname must be between 2 and 50 characters" . "<br>"; } if ($usernameLength = 6) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Username must be 6 characters long" . "<br>"; } if ($passwordLength = 6) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Password must be 6 characters long" . "<br>"; } if ($confirmpLength = 6) { $errorMessage = ""; } else { $errorMessage = $errorMessage . "Password must be 6 characters long" . "<br>"; } if ($errorMessage == "") { $query = "SELECT * FROM user WHERE username = '$username' AND password = '$password'"; $result = mysql_query($query); $num_rows = mysql_num_rows($result); //check to see if the $result is true if ($num_rows = 1){ $errorMessage = "Username already exists"; } else { if($password == $confirmp){ $query = "INSERT INTO user (title, name, surname, username, password) VALUES ('$title', '$name', '$surname', '$username', '$password')"; $result = mysql_query($query); session_start(); $_SESSION['login'] = "1"; header ("Location: login.php"); } else { $errorMessage = "Passwords do not match!"; } } } else { $errorMessage = "Error Registering"; } } else { $errorMessage = "Please enter your details"; } ?> <html> <head> <title>Mia's Beauty Products</title> </head> <body> <p><img src = "banner1.jpg" width = "975" height = "95" alt = "Mia's Beauty Product" /></p> <br> <p align= "center"><a href="register.php">Register</a> | <a href="login.php">Login</a> | <a href="insert.php">Insert</a> | <a href="list.php">List</a></p> <form method = "post" action = "register.php"> <table> <tr><td>Title:</td><td><select name = "title"> <option>Miss</option> <option>Mrs</option> <option>Mr</option> </select></td></tr> <tr><td>Name:</td><td><input name = "name" type = "text" value ="<?php print $name;?>"></td></tr> <tr><td>Surname:</td><td><input name = "surname" type = "text" value ="<?php print $surname;?>"></td></tr> <tr><td>Username:</td><td><input name = "username" type = "text" value ="<?php print $username;?>"></td></tr> <tr><td>Password:</td><td><input name = "password" type = "password" value ="<?php print $password;?>"></td></tr> <tr><td>Confirm Password:</td><td><input name = "confirmp" type = "password" value ="<?php print $confirmp;?>"></td></tr> <tr><td><input type = "submit" name = "Submit" value = "Submit"></td></tr> </table> </form> <p align= "center"><a href="code.txt">Code</a></p> <br> <?php print $errorMessage; ?> <p><img src = "banner2.jpg" width = "975" height = "95" alt = "Mia's Beauty Product" /></p> </body> </html> Thank you Amanda
×
×
  • 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.