Jump to content

JessicaC

New Members
  • Content Count

    7
  • Joined

  • Last visited

  • Days Won

    1

JessicaC last won the day on November 21 2016

JessicaC had the most liked content!

Community Reputation

2 Neutral

About JessicaC

  • Rank
    Newbie
  1. Who says I don't give a "shit" about the subject? I do. But it doesn't mean I have total interest in pursuing a career in programming (I honestly do not know what I want to do). I am taking the class because I need to fulfill a requirement. I am majoring in information science. That school is merging with the computer science department to form a new school. I still don't understand what the issue is with my professor teaching PHP6. Is it really as outdated as PHP7?? And just because I am now learning "obsolete code" doesn't mean I would use it in a future job. How do you know I won't learn proper coding? I have no intention of scamming people let alone hacking. All I am doing right now is trying to complete an assignment!
  2. Fixed that, but I am still getting "Error" <?php /* EDIT.PHP Allows user to edit specific entry in database */ // creates the edit customer form function renderForm($User_id, $Fname, $Lname, $error) { ?> <!DOCTYPE html> <html lang="EN"> <html> <head> <title>Edit Customer details</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="User_id" value="<?php echo $User_id; ?>"/> <div> <p><strong>User_id:</strong> <?php echo $User_id; ?></p> <strong>First Name: *</strong> <input type="text" name="first_name" value="<?php echo $Fname; ?>"/><br/> <strong>Last Name: *</strong> <input type="text" name="last_name" value="<?php echo $Lname; ?>"/><br/> <p>* Required</p> <input type="submit" name="submit" value="Submit"> </div> </form> </body> </html> <?php } // connect to the database include('script/login.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['User_id'])) { // get form data, making sure it is valid $User_id = $_POST['User_id']; $Fname = mysql_real_escape_string(htmlspecialchars($_POST['first_name'])); $Lname = mysql_real_escape_string(htmlspecialchars($_POST['last_name'])); // check that firstname/lastname fields are both filled in if ($Fname == '' || $Lname == '') { // generate error message $error = 'ERROR: Please fill in all required fields!'; //error, display form renderForm($User_id, $Fname, $Lname, $error); } else { // save the data to the database mysql_query("UPDATE users SET first_name='$Fname', last_name='$Lname' WHERE User_id='$User_id'") or die(mysql_error()); // once saved, redirect back to the view page header("Location: customerlist.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 { if (isset($_GET['User_id']) && is_numeric($_GET['User_id']) && $_GET['User_id'] > 0) { // query db $User_id = $_GET['User_id']; $result = mysql_query("SELECT * FROM users WHERE User_id=$User_id") or die(mysql_error()); $row = mysql_fetch_array($result); // check that the 'id' matches up with a row in the database if($row) { // get data from db $Fname = $row['first_name']; $Lname = $row['last_name']; // show form renderForm($User_id, $Fname, $Lname, ''); } 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!'; } } ?> other files: content.php <!DOCTYPE html> <html lang="EN"> <head> <!-- Jessica Chen, CS334, Fall 2016, Lab 10 --> <title>Customers</title> </head> <body> <a href="contentphp.txt">content.php text file</a></br> <a href="sql_code.txt">SQL codes</a></br></br> <div id="wrapper"><!-- BEGIN MAIN WRAPPER --> <section id="top_area"> <article class="box-right"> <form action="script/data.php" method="post"> <fieldset> <legend>Enter customer information</legend> <p> <label>First Name:</label> <input name="first_name" required="required" placeholder="John" type="text"> </p> <p> <label>Last Name:</label> <input name="last_name" required="required" placeholder="Doe" type="text"> </p> <p> <label>Gender:</label> <input type="radio" name="sex" value="male" checked="checked" /><label>male</label> <input type="radio" name="sex" value="female" /> <label>female</label> </p> <p> <label> Your email:</label> <input name="email" required="required" placeholder="random@mail.com" type="email"> </p> <p> <label>password:</label> <input name="password" required="required" placeholder="eg. X8df!90EO" type="password"> </p> <p> <input value="Submit" type="submit"> </p> <a href="customerlist.php">View and edit customer list</a></br> </fieldset> </form> </article> </section> </div><!-- END MAIN WRAPPER --> </br></br> <form action="" method="post"> <fieldset> <legend>Search Contacts Details</legend> <p>You may search either by first or last name</p> <input name="search" type="search" autofocus><input type="submit" name="button"> </form> <table> <tr><td><b>First Name</td><td></td><td><b>Last Name</td></tr> <?php $con=mysql_connect('localhost', 'jesschen_jzc22', ''); $db=mysql_select_db('jesschen_jess-ascraeus'); if(isset($_POST['button'])){ //trigger button click $search=$_POST['search']; $query=mysql_query("select * from users where first_name like '%{$search}%' || last_name like '%{$search}%' "); if (mysql_num_rows($query) > 0) { while ($row = mysql_fetch_array($query)) { echo "<tr><td>".$row['first_name']."</td><td></td><td>".$row['last_name']."</td></tr>"; } }else{ echo "No customer Found<br><br>"; } }else{ //while not in use of search returns all the values $query=mysql_query("select * from users"); } mysql_close(); ?> </fieldset> </body> </html> script/data.php <?php //data.php require_once 'login.php'; //Get values from form $Fname = $_POST['first_name']; $Lname = $_POST['last_name']; $sex = $_POST['sex']; $email = $_POST['email']; $password = $_POST['password']; //insert data into mysql $sql = "INSERT INTO users(first_name, last_name, sex, email, password, registration_date) VALUES ('$User_id','$Fname','$Lname','$sex','$email', SHA1('$password'), NOW())"; $result=mysql_query($sql); //if successfully insert data into database, displays message "successful". if($result) { header('Location: ../thankyou.php'); } else { echo "ERROR"; } //close mysql mysql_close(); ?> ..
  3. JessicaC

    Hi

    My name is Jessica and I am from Pennsylvania. I am not an expert programmer, but I have some experience in it due to taking classes in college. I am currently in a Python class and an Intermediate web design class (where I am learning PHP and SQL). I have my own website, though it is really a (rather dead) phpBB board. I do have some interest in programming and web design, but I do not anticipate I will become any sort of professional programmer.
  4. I don't care if it's obsolete and insecure. I am trying to finishing up an assignment and want it working.
  5. That's odd...I didn't even post that link. My link was this: http://chenschool.elementfx.com/CS334/lab10/content.txt Of course that text file no longer exists. I changed the name... I understand, but as far as I know, my code is supposed to follow certain instructions and we aren't using the very latest PHP. I am not sure why my professor is not using the latest, but I'm using what I learned in class. In any case, the class is easy enough that I am doing really well in the class. I also have no plans on becoming a professional programmer. Does it even matter? If my code works, it works. So what if it's not the very latest version? It's not like I will be keeping these PHP files and code after term is over
  6. For my class lab assignment, I need to be able to edit a customer record customerlist.php <!DOCTYPE html> <html lang="EN"> <head> <!-- View customer list --> <title>Customer list</title> </head> <body> <?php /* CUSTOMERLIST.PHP Displays all data from 'users' table */ // connect to the database include('script/login.php'); // get results from database $result = mysql_query("SELECT * FROM users") or die(mysql_error()); // display data in table echo "<table border='1' cellpadding='10'>"; echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>"; // loop through results of database query, displaying them in the table while($row = mysql_fetch_array( $result )) { // echo out the contents of each row into a table echo "<tr>"; echo '<td>' . $row['User_id'] . '</td>'; echo '<td>' . $row['first_name'] . '</td>'; echo '<td>' . $row['last_name'] . '</td>'; echo '<td><a href="edit.php?id=' . $row['User_id'] . '">Edit</a></td>'; echo "</tr>"; } // close table> echo "</table>"; ?> <p><a href="content.php">Add a new customer</a></p> </body> </html> edit.php <?php /* EDIT.PHP Allows user to edit specific entry in database */ // creates the edit customer form function renderForm($User_id, $Fname, $Lname, $error) { ?> <!DOCTYPE html> <html lang="EN"> <html> <head> <title>Edit Customer details</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="User_id" value="<?php echo $User_id; ?>"/> <div> <p><strong>ID:</strong> <?php echo $User_id; ?></p> <strong>First Name: *</strong> <input type="text" name="first_name" value="<?php echo $Fname; ?>"/><br/> <strong>Last Name: *</strong> <input type="text" name="last_name" value="<?php echo $Lname; ?>"/><br/> <p>* Required</p> <input type="submit" name="submit" value="Submit"> </div> </form> </body> </html> <?php } // connect to the database include('script/login.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['User_id'])) { // get form data, making sure it is valid $id = $_POST['User_id']; $Fname = mysql_real_escape_string(htmlspecialchars($_POST['first_name'])); $Lname = mysql_real_escape_string(htmlspecialchars($_POST['last_name'])); // check that firstname/lastname fields are both filled in if ($Fname == '' || $Lname == '') { // generate error message $error = 'ERROR: Please fill in all required fields!'; //error, display form renderForm($User_id, $Fname, $Lname, $error); } else { // save the data to the database mysql_query("UPDATE users SET first_name='$Fname', last_name='$Lname' WHERE User_id='$User_id'") or die(mysql_error()); // once saved, redirect back to the view page header("Location: customerlist.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 { if (isset($_GET['User_id']) && is_numeric($_GET['User_id']) && $_GET['User_id'] > 0) { // query db $id = $_GET['id']; $result = mysql_query("SELECT * FROM users WHERE User_id=$User_id") or die(mysql_error()); $row = mysql_fetch_array($result); // check that the 'id' matches up with a row in the database if($row) { // get data from db $Fname = $row['first_name']; $Lname = $row['last_name']; // show form renderForm($User_id, $Fname, $Lname, ''); } 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!'; } } ?> Whenever I click the Edit link I don't get the edit form but the error generated by my code. I cannot figure out how to fix this, when the user ID for each customer is correct
  7. This "junk" is for a lab assignment for class. I don't need to use anything fancy let alone PDO, something I haven't even learned yet. I figured out what I did wrong. It works now That link does NOT link to a Facebook page. It's my own website, one of the domains which I am using for a class
  8. I need to write a program that asks a user's name and searches the database for that user. Trying to get search results to show first name and last name when a search query is entered but I can't get it to show at all. Here is my content.php: http://chenschool.elementfx.com/CS334/lab10/content.txt Not sure where in my code it's wrong. I already have one row of data in the table (First name: John, last name: Doe) and entering either John or Doe does nothing (no "John Doe" text appears). I made sure the column names are all correct and yes, I have connected to the database.
×
×
  • 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.