Jump to content

ramforinkas

New Members
  • Posts

    4
  • Joined

  • Last visited

ramforinkas's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. It appears I was missing the " " around my select name. User: <SELECT NAME= "FullName"> <OPTION VALUE=0>Choose</OPTION> <?php echo $options2; ?> </select> It is now working, thanks so much for your assistance!
  2. Thanks for the fast reponse! I went ahead and did as you suggested if (isset($_POST['FullName'])) { $FullName = mysql_real_escape_string($_POST['FullName']); mysql_query("DELETE FROM useraccess WHERE FullName='$FullName'") or die(mysql_error()); echo "Success!"; } else { echo "No value selected"; } However now it doesn't seem to want to delete anything.
  3. Hey guys! Fairly new with PHP/MySQL and been working on a website for a class, and having some issues with my drop down not working as intended. What I'm trying to do is simply allow the user to select a name from a drop down field, then after pressing the submit button, would delete the selected name from the database. Here is my code. <?php ini_set('display_errors', 'on'); error_reporting(E_ALL); session_start(); $_SESSION['title'] = "PEC Menu"; //Opening Session Vars $currentFile = $_SERVER["PHP_SELF"]; //current page for menu $currentUser = $_SESSION['currentname']; // users account info include('../../functions/mainmenu.php'); // menu functions //Menu Content,Code / Buttons Goes here DrawMenu($currentFile, $currentUser); //Setting up database mysql_connect("localhost","root","changeme"); mysql_select_db("certestdb"); $dbLink = mysql_connect("localhost", "root", "changeme"); mysql_query("SET character_set_client=utf8", $dbLink); mysql_query("SET character_set_connection=utf8", $dbLink); $result = mysql_query("SELECT distinct TermID FROM clinical") or die(mysql_error()); $result2 = mysql_query("SELECT FullName FROM useraccess") or die(mysql_error()); $options=''; $options2=''; while($row=mysql_fetch_array($result)) { if (isset($_POST)) { $TermID=$row["TermID"]; $options.= '<option value="'.$row['TermID'].'">'.$row['TermID'].'</option>'; } }; while($row=mysql_fetch_array($result2)) { if (isset($_POST)) { $FullName=$row["FullName"]; $options2.= '<option value="'.$row['FullName'].'">'.$row['FullName'].'</option>'; } }; if (isset($_POST)) { mysql_query("DELETE FROM useraccess WHERE FullName='$FullName'") or die(mysql_error()); echo "Success!"; } else { echo "Not successful"; } ?> <html> <style> </style> <body> <h4> Add User</h4> <form name = "AddUser" action="PEC_addUser.php" method= "get" style = "text-align:right; color: Black;float:left;"> <input type="submit" value="Add User"> </form><br><br> <hr size = "5" color = "darkgray"> <h4> Assign User to Course</h4> <form name = "AssignUser" action=" " method= "get" style = "text-align:right; float:left; color: darkred;"> User: <select> </select> Course: <select> </select> Term: <SELECT NAME= termid> <OPTION VALUE=0>Choose</OPTION> <?php echo $options; ?> </select> <input type="submit" value="Assign"> </form> <br><br> <hr size = "5" color = "darkgray"> <h4> Assign Student to Instructor </h4> <form name = "AssignStudent" action=" " method= "get" style = "text-align:right; color: darkred;float:left;"> Student: <select> <option value = "Select"> Select</option>} <option value = "one"> 1</option>} <option value = "two"> 2</option>} <option value = "three"> 3</option>} </select> Course: <select> <option value = "Select"> Select</option>} <option value = "one"> 1</option>} <option value = "two"> 2</option>} <option value = "three"> 3</option>} </select> Instructor: <select> <option value = "Select"> Select</option>} <option value = "one"> 1</option>} <option value = "two"> 2</option>} <option value = "three"> 3</option>} </select> <input type="submit" value="Assign"> </form><br><br> <hr size = "5" color = "darkgray"> <h4> Delete User</h4> <form name = "DeleteUser" action=" " method= "get" style = "text-align:right; color: darkred;float:left;"> User: <SELECT NAME= FullName> <OPTION VALUE=0>Choose</OPTION> <?php echo $options2; ?> </select> <input type="submit" name="delete" value="delete"> </form><br><br> <hr size = "5" color = "darkgray"> <link rel="stylesheet" href="styles/pecui.css" media="screen" /> </body> </html> <?php ?> This is where the possible issue is if (isset($_POST)) { mysql_query("DELETE FROM useraccess WHERE FullName='$FullName'") or die(mysql_error()); echo "Success!"; } else { echo "Not successful"; } What happens is upon submitting, it just deletes the last 2 records in the table "useraccess" instead of the value selected from the drop down. I'm thinking that its not properly storing the data from the database, which is whats causing the query issue. If anyone could help me, it would be very much appreciated it.
  4. Hi all, I'm fairly new with PHP/HTML and I'm working on implementing a simple comment field for a website I'm designing. The issue I'm having is that the comment field seems to only display integers, and not strings. Other then not displaying words, I'm not getting any errors. The database seems to be working fine, however it's only saving Integers, and not Strings. I've checked the columns and the one which is holding the comments is using type "text", and the ID is "int". I don't believe the issue is with the table, but rather somewhere with the PHP. Here is the code below: <?php 02 mysql_connect("localhost","root","changeme"); 03 mysql_select_db("certestdb"); 04 $comment=$_POST['comment']; 05 $submit=$_POST['submit']; 06 07 08 $dbLink = mysql_connect("localhost", "root", "changeme"); 09 mysql_query("SET character_set_client=utf8", $dbLink); 10 mysql_query("SET character_set_connection=utf8", $dbLink); 11 12 13 14 if (!empty($_POST)) { 15 //$comment=$_POST['comment']; 16 //$submit=$_POST['submit']; 17 18 19 if($submit) { 20 if($comment) { 21 $insert=mysql_query("INSERT INTO comment (comment) VALUES ($comment) "); 22 } else { 23 echo "please fill out all fields"; 24 } 25 } 26 } 27 28 ?> 29 30 <html> 31 <head> 32 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 33 <title>Comment box</title> 34 </head> 35 <div style="width:100px; height:100px; margin: 2 auto;"> 36 <body> 37 <center> 38 <form name="comment.php" method="post" action=""> 39 <table> 40 <tr><td colspan="2">Comments: </td></tr> 41 <tr><td colspan="5"><textarea name="comment" rows="5" cols="150"></textarea></td></tr> 42 <tr><td colspan="2"><input type="submit" name="submit" value="Comment"></td></tr> 43 </table> 44 </form> 45 46 <?php 47 $dbLink = mysql_connect("localhost", "root", "changeme"); 48 mysql_query("SET character_set_results=utf8", $dbLink); 49 50 51 52 $getquery=mysql_query("SELECT * FROM comment ORDER BY id DESC"); 53 while($rows=mysql_fetch_array($getquery)) { 54 $id=$rows['id']; 55 $comment=$rows['comment']; 56 echo $comment . '<br/>' . '<br/>' . '<hr size="1"/>'; 57 } 58 59 ?> 60 61 </body> 62 </html> If anyone might know what is causing this and could help, it would be much appreciated! Thanks!
×
×
  • 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.