Jump to content

monkeymaker

Members
  • Posts

    20
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling
  • Location
    basement

monkeymaker's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Literally, this is all that was neccessary... $sql = "DELETE FROM student WHERE sid = $sid"; Maybe something got lost in translation so to speak in terms of all I was trying to do? I started off doing C++ and I quickly understood that the more simple solutions were the best solutions. Also I appreciate the concern but all this stuff about cowboy coding seems uncalled for, all I wanted help for was with a delete command, not an CMS written in PHP And yes you 'were' referring to me
  2. Huh? I appreciate the help but I want to point out that your example youve just shown me is waaaaayy more advanced and complicated then neccessary, adding to the confusion of learning something new, actually I just did iwhat I wanted with a buddies help. Dude, seriously are you trying to scare me away from php or something, really? lol
  3. yeah, everything is the same..what I really don't get though is that the SQL : delete from (table) where value ='anything' is a manual thing only... for instance I have a select form, user selects the ID to delete, then after pressing the button the SQL query should pick up that the ID has been selected and removes the associated rows and ID? Basically having to type in the manual SQL instead of using the select form is pointless really and all the examples I have seen thats what they basically say to do ?
  4. <?php include 'studentfunc.php'; ?> <?php $db1 = new dbstudent(); $db1->openDB(); $sql="select sid from student"; $result=$db1->getResult($sql);// get the ids from the tables for the select ?> <?php if (!$_POST) //page loads for the first time { ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Select Student ID to <b> DELETE! </b>: <select name="sid"> <?php while($row = mysql_fetch_assoc($result)) echo "<option value='{$row['sid']}'>{$row['sid']} </option>"; ?> </select> <input type="submit" value=">!DELETE!<" /> </form> <?php } else { $sid = $_POST['sid']; $name = $_POST['name']; $address = $_POST['address']; $postcode = $_POST['postcode']; $photo = $_POST['photo']; $db1 = new dbstudent(); $db1->openDB(); $numofrows = $db1->delete_student($sid, $cid, $grade, $comments); echo "Success. Number of rows affected: <strong>{$numofrows}<strong>"; $db1->closeDB(); } ?>
  5. So, could the value be say, for instance, the ID? If so I have already tried this without luck?
  6. Thanks, but there isnt a value I just want to delete the contents on an entire row from when the user presses 'confirm' button? sorry of any of this sounds dumb
  7. Hello, the user selects an id (sid) on select form then presses confirm button. Below is my delete function however I have error : Warning: Missing argument 5 for dbstudent::delete_student(), called in C:\xampp\htdocs\cw1\delstudent.php on line 36 and defined in C:\xampp\htdocs\cw1\studentfunc.php on line 28 SQL Insertion 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 '(sid, name, address, postcode, photo) from student where values ('1', '', '', '' at line 1 Please advise!! function delete_student($sid, $name, $address, $postcode, $photo) { $esc_name = mysql_real_escape_string($name, $this->conn); $esc_address = mysql_real_escape_string($address, $this->conn); $esc_postcode = mysql_real_escape_string($postcode, $this->conn); $esc_photo = mysql_real_escape_string($photo, $this->conn); $sql = "delete (sid, name, address, postcode, photo) from student where values ('{$sid}', '{$esc_name}', '{$esc_address}', '{$esc_postcode}', '{$esc_photo}')"; $result = mysql_query($sql, $this->conn); if (!$result) { die("SQL Insertion error: " . mysql_error()); } else { $numofrows = mysql_affected_rows($this->conn); return $numofrows; } }
  8. Yes thanks all matches up using print() now it just needs to save into the student table on the db
  9. **updated** Thank you, I sincerely appreciate your efforts. I have made some ammendments as suggested, see the function below. The user selects the ID they want to change in the database, then the user fills in the input boxes and submit button should update or change the exisiting fields on the database to the new ones entered in by the user using the input boxes. Right now the newly entered inputs from the form fields just dont over write the existing db fields Please advise function student_update($sid, $name, $address, $postcode, $photo) { $esc_sid = mysql_real_escape_string($sid , $this->conn); $esc_name = mysql_real_escape_string($name, $this->conn); $esc_address = mysql_real_escape_string($address, $this->conn); $esc_postcode = mysql_real_escape_string($postcode, $this->conn); $esc_photo = mysql_real_escape_string($photo, $this->conn); $sql = "UPDATE student SET name='{$esc_name}', address='{$esc_address}', postcode='{$esc_postcode}', photo='{$esc_photo}' WHERE sid='{$esc_sid}'"; $result = mysql_query($sql, $this->conn); if(!$result) die("SQL Error: " . mysql_error()); else { print("$esc_sid"); /*see sid*/ $numofrows = mysql_affected_rows($this->conn); return $numofrows; } } <?php include 'studentfunc.php'; //import the class in this web page ?> <!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>Update Student</title> </head> <body> <?php $db1 = new dbstudent(); $db1->openDB(); $sql="select sid from student"; $result=$db1->getResult($sql); if (!$_POST) //page loads for the first time { ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Select Student ID to update: <select name="sid"> <?php while($row = mysql_fetch_assoc($result)) echo "<option value='{$row['sid']}'>{$row['sid']} </option>"; ?> </select> </form> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Update new student name:<input type="text" name="name" /><br /> Update new student address:<input type="text" name="address" /><br /> Update new student postcode:<input type="text" name="postcode" /><br /> Update new student picture:<input type="text" name="photo" /><br /> <br /> <input type="submit" value="Save" /> </form> <?php } //end if else { $sid = $_POST['sid']; $name = $_POST['name']; $address = $_POST['address']; $postcode = $_POST['postcode']; $photo = $_POST['photo']; $db1 = new dbstudent(); $db1->openDB(); $numofrows = $db1->student_update($sid, $name, $address, $postcode, $photo); echo "Success. Number of rows affected: <strong>{$numofrows}<strong>"; $db1->closeDB(); } ?> </body> </html>
  10. Hey, thanks again. The SQL statement now runs but actually I think there might be something a bit wierd going on with my input forms, print 'sid', as used on the function, is actually outputting the input from 'name'? Something must be missing or I am trying something totally wrong? See <?php include 'studentfunc.php'; //import the class in this web page ?> <!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>Update Student</title> </head> <body> <?php $db1 = new dbstudent(); $db1->openDB(); $sql="select sid from student"; $result=$db1->getResult($sql); if (!$_POST) //page loads for the first time { ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Select Student ID to update: <select name="sid"> <?php while($row = mysql_fetch_assoc($result)) echo "<option value='{$row['sid']}'>{$row['sid']} </option>"; ?> </select> </form> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> Update new student name:<input type="text" name="name" /><br /> Update new student address:<input type="text" name="address" /><br /> Update new student postcode:<input type="text" name="postcode" /><br /> Update new student picture:<input type="text" name="photo" /><br /> <br /> <input type="submit" value="Save" /> </form> <?php } //end if else { $sid = $_POST['sid']; $name = $_POST['name']; $address = $_POST['address']; $postcode = $_POST['postcode']; $photo = $_POST['photo']; $db1 = new dbstudent(); $db1->openDB(); $numofrows = $db1->student_update($name, $address, $postcode, $photo, $sid); echo "Success. Number of rows affected: <strong>{$numofrows}<strong>"; $db1->closeDB(); } ?> </body> </html>
  11. Hey thanks for getting back to me again! I tried some other changes now I'm getting the following SQL 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 'values ('test', 'test', 'test', '' WHERE sid='test')' at line 2 This is student_update() function student_update($sid, $name, $address, $postcode, $photo) { $esc_sid = mysql_real_escape_string($sid , $this->conn); $esc_name = mysql_real_escape_string($name, $this->conn); $esc_address = mysql_real_escape_string($address, $this->conn); $esc_postcode = mysql_real_escape_string($postcode, $this->conn); $esc_photo = mysql_real_escape_string($photo, $this->conn); $sql = "UPDATE student SET name='{$esc_name}' where sid='${esc_sid} ' values ('{$esc_name}', '${esc_address}', '{$esc_postcode}', '${esc_photo}' WHERE sid='${sid}')"; $result = mysql_query($sql, $this->conn); if(!$result) die("SQL Error: " . mysql_error()); else { print("$sid"); /*see sid*/ $numofrows = mysql_affected_rows($this->conn); return $numofrows; } }
  12. It ran but now rows were effected Can you give an example on where I should put the echo statements for the variables. Should that be in the function or the php page? Also what about vardump() ? Thanks for having the patience to help me out!
  13. Ok thanks but sorry Im still a bit confused, the whole SQL section of the function should be this? $sql = "UPDATE student SET name='$esc_name' where sid='$esc_sid ' values ('{$esc_name}', '${esc_address}', '{$esc_postcode}', '${esc_photo}' WHERE sid='${sid}')";
  14. Awesome thanks.. heres the current code function student_update($name, $address, $postcode, $photo) { $esc_sid = mysql_real_escape_string($sid , $this->conn); $esc_name = mysql_real_escape_string($name, $this->conn); $esc_address = mysql_real_escape_string($address, $this->conn); $esc_postcode = mysql_real_escape_string($postcode, $this->conn); $esc_photo = mysql_real_escape_string($photo, $this->conn); $sql = "UPDATE student (name, address, postcode, photo) values ('{$esc_name}', '${esc_address}', '{$esc_postcode}', '${esc_photo}') WHERE sid='${sid}'"; $result = mysql_query($sql, $this->conn); if(!$result) die("SQL Error: " . mysql_error()); else { $numofrows = mysql_affected_rows($this->conn); return $numofrows; } } I'm not sure what you mean about defining $sid, it is a field in the DB and on the function ?
×
×
  • 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.