PHP - Help Posting Data To Database
I'm not much of a PHP programmer so please excuse the mess but I'm having a problem with some code. I am able to successfully build a table and assign values to radio buttons based one information in a database. The problem comes when I want to update the database when someone changes a radio button. Everthing works up until the foreach statment. Nothing in the database is being updated, if I replace the sql statement with echo $v; all I get is the word Submit so it's like the rest of the values aren't being included in the form.
<link href="css/demo.css" rel="stylesheet" type="text/css"> <?php session_start(); // dBase file include "dbconfig.php"; if (!$_SESSION["valid_user"]) { // User not logged in, redirect to login page Header("Location: index.php"); } //Grab GUID passed in the URL $guid=$_GET['guid']; // Create query for student name $sql = "SELECT FirstName, LastName FROM Students where GUID ='". $guid . "'"; // Run query $result = mssql_query($sql); $row= mssql_fetch_assoc($result); // Member only content //Title and main page information echo "<div align=\"center\"><p><img src=\"images/EFCTS Logo.jpg\" width=\"600\" height=\"144\" /></p><h1>OCAP DATABASE</h1></div>"; echo "<p><a href=\"logout.php\">Logout</a></p>"; //Build sortable table of student data. echo "<table id=\"test1\" class=\"sortable-onload-3-reverse rowstyle-alt no-arrow\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"; //query database for table information $SQLcommand = "SELECT convert(varchar(36), StudentGUID) as StudentGUID, CompetencyLevel, CompetencyName, CompetencyID, Category, convert(varchar(36), CompetencyGUID) as CompetencyGUID FROM VW_StudentSkills WHERE StudentGUID ='". $guid ."'"; $SQLresult = MsSQL_QUERY($SQLcommand); //Continue building table echo "<caption>".$row[FirstName]." ".$row[LastName]."</caption>"; echo "<th style=\"-moz-user-select: none;\" class=\"sortable-numeric fd-column-0\"><a title=\"Sort on \"Competency ID\"\" href=\"#\">Competency ID</a></th>"; echo "<th style=\"-moz-user-select: none;\" class=\"fd-column-1 sortable-text reverseSort\"><a title=\"Sort on \"Catagory\"\" href=\"#\">Catagory</a></th>"; echo "<th style=\"-moz-user-select: none;\" class=\"fd-column-2 sortable-text reverseSort\"><a title=\"Sort on \"Competency Name\"\" href=\"#\">Competency Name</a></th>"; echo "<th style=\"-moz-user-select: none;\" class=\"sortable-numeric fd-column-3\"><a title=\"Sort on \"Competency Level\"\" href=\"#\">Competency Level</a></th>"; echo "</tr></thead>"; //Set variables for radio buttons $a=""; $b=""; $c=""; $d=""; //count the number of rows returned $count=mysql_num_rows($SQLresult); //Start form echo "<form name=\"form1\" method=\"post\" action=\"".$_SERVER['REQUEST_URI']."\">"; $groupnum = 0; //Build table with SQL data while($row2=mssql_fetch_array($SQLresult)) { //find the competency level $complevel = $row2[CompetencyLevel]; if($complevel=="1") $a="checked"; if($complevel=="2") $b="checked"; if($complevel=="3") $c="checked"; if($complevel=="4") $d="checked"; //build the table echo "<tr class=\"\"><td>".$row2[CompetencyID]."</td><td>".$row2[Category]."</td>"; echo "<td>".$row2[CompetencyName]."</td>"; echo "<td class=\"lft\"><input type=\"radio\" name=\"".$row2[CompetencyID]."\" value=\"1\"".$a."> 1"; echo "<input type=\"radio\" name=\"".$row2[CompetencyID]."\" value=\"2\"".$b."> 2"; echo "<input type=\"radio\" name=\"".$row2[CompetencyID]."\" value=\"3\"".$c."> 3"; echo "<input type=\"radio\" name=\"".$row2[CompetencyID]."\" value=\"4\"".$d."> 4"; $idarray[]=$row2[CompetencyGUID]; echo "</td></tr>"; $groupnum++; //clear the variables $a=""; $b=""; $c=""; $d=""; } echo "</tbody>"; echo "<input type=\"submit\" name=\"Submit\" value=\"Submit\">"; echo "</form></table>"; echo "<script type=\"text/javascript\" src=\"javascript/tablesort.js\"></script>"; if($_POST['Submit']) { echo"submit button detected"; foreach($_POST as $k=>$v) { if($k!="Submit") { $sqlUpdate = "UPDATE DATA SET COMPETENCYLEVEL = '".$v."' WHERE COMPETENCYGUID = '".$idarray."' AND STUDENGUID = '".$guid."' "; $resultUpdate = mssql_query($sqlUpdate); } } } if($resultUpdate) { print_r ($_POST); echo $resultUpdate; echo $sqlUpdate; } else { echo "Your entry is not completed at this time............."; echo $sqlUpdate; echo $resultUpdate; } // Display Member information //echo "<p>User ID: " . $_SESSION["valid_id"]; //echo "<p>Username: " . $_SESSION["valid_user"]; //echo "<p>Logged in: " . date("m/d/Y", $_SESSION["valid_time"]); ?> Similar TutorialsHi everyone, First off thank you very kindly to anyone who can provide some enlightenment to this total php/mysql newb. I am creating my first database and while I have been able to connect to the database within my php script (or so I believe), the form data does not appear to be actually getting sent. I have development experience in other languages but this is completely new to me so if I've missed something that appears painfully obvious like a parse error of some sort, I do apologize. I am creating a website using Godaddy as the hosting account, and attempting to connect to the mysql database at the following URL (maybe this is where I'm going wrong): "pnmailinglist.db.4662743.hostedresource.com" Below is my very simple code: <?php //Verify successful connection to database. $connect = mysql_connect("pnmailinglist.db.4662743.hostedresource.com", "*********", "*********"); if(!$connect) {die("Could not connect!"); } //Initialize variables with form data. $firstname = $_POST['FirstName']; $lastname = $_POST['LastName']; $email = $_POST['Email']; $howfound = $_POST['HowFound']; //Post data to database, or return error. mysql_select_db("pnmailinglist", $connect); mysql_query("INSERT INTO mailinglist (First, Last, Email, How_Found) VALUES ($firstname,$lastname,$email,$howfound)"); mysql_close($connect); echo "Thank you for joining our mailing list! We will contact you soon with the dates and times of our upcoming events."; ?> Thank you again very much for any pointers or hints as to where I'm screwing up. I get no runtime errors, no syntax errors, and the echo message does display fine at the end -- just no data when I go to check my database! Best Regards, CL You guys helped me create a function to gather information for my database. Now I need some help with posting that information. Function code and Form: <?php include("opendatabase.php"); ?> <?php function createMatchup($week, $game) { $query1 = "SELECT team_name FROM schedule, teams WHERE schedule.week_id = $week AND schedule.game_id = $game AND schedule.A_team = teams.team_id"; $query2 = "SELECT team_name FROM schedule, teams WHERE schedule.week_id = $week AND schedule.game_id = $game AND schedule.H_team = teams.team_id"; $result1 = mysql_fetch_assoc(mysql_query($query1)); $result2 = mysql_fetch_assoc(mysql_query($query2)); $output = " <input type=\"text\" size = \"3\" name=\"w$weekg$gameA\"> {$result1['team_name']} vs. {$result2['team_name']} <input type=\"text\" size = \"3\" name=\"w$weekg$gameH\">"; return $output; } $game1 = createMatchup(1, 1); $game2 = createMatchup(1, 2); $game3 = createMatchup(1, 3); $game4 = createMatchup(1, 4); $game5 = createMatchup(1, 5); $game6 = createMatchup(1, 6); $game7 = createMatchup(1, 7); $game8 = createMatchup(1, 8); $game9 = createMatchup(1, 9); $game10 = createMatchup(1, 10); $game11 = createMatchup(1, 11); $game12 = createMatchup(1, 12); $game13 = createMatchup(1, 13); $game14 = createMatchup(1, 14); $game15 = createMatchup(1, 15); $game16 = createMatchup(1, 16); mysql_close($con); ?> <form action="insert_spreads.php" method="post"> <?php echo $game1; ?> <br> <?php echo $game2; ?> <br> <?php echo $game3; ?> <br> <?php echo $game4; ?> <br> <?php echo $game5; ?> <br> <?php echo $game6; ?> <br> <?php echo $game7; ?> <br> <?php echo $game8; ?> <br> <?php echo $game9; ?> <br> <?php echo $game10; ?> <br> <?php echo $game11; ?> <br> <?php echo $game12; ?> <br> <?php echo $game13; ?> <br> <?php echo $game14; ?> <br> <?php echo $game15; ?> <br> <?php echo $game16; ?> <br /><br /> <input type="Submit" value="Submit Spreads"> </form> I'm wondering if I can use this code for posting to the database (insert_spreads.php): <?php header("Location: admin_schedule.php"); include("opendatabase.php"); $w$weekg$gameA=("$_POST['w$weekg$gameA']"); $w$weekg$gameH=("$_POST['w$weekg$gameH']"); $sql=" UPDATE schedule SET A_pt_spread= '$w$weekg$gameA',H_pt_spread= '$w$weekg$gameH' WHERE week_id = '$week' AND game_id = '$game'; $result = mysql_query($sql) or die(mysql_error().$sql); mysql_close($con) ?> Thanks for helping. I'm trying to figure out how to post an array into my database. I am able to post single entries without a problem, but trying to post several entries at once is causing me some headaches. Can anyone check this code and hopefully give me some insight as to where I'm going wrong? Here's the form: Code: [Select] <?php include("opendatabase.php"); ?> <FORM Method = "POST" action ="insert_spreads.php"> <?php $weekID = $_POST[Week]; echo "<h2>Enter Spreads for Week $weekID</h2>"; print ("<br /><br />"); $result = mysql_query(" SELECT S.game_id, TH.team_name AS HomeTeam, TA.team_name AS AwayTeam FROM schedule AS S JOIN teams AS TH ON S.H_team = TH.team_id JOIN teams AS TA ON S.A_team = TA.team_id WHERE S.week_id = '$weekID' ORDER BY S.game_id;"); while ($row = mysql_fetch_array($result)) { printf('<input type="text" size="4" name="w%dg%dAspread">', $weekID, $row['game_id']); printf(" %s vs. %s ", $row['AwayTeam'], $row['HomeTeam']); printf('<input type="text" size="4" name="w%dg%dHspread">', $weekID, $row['game_id']); print("<br /><br />"); } mysql_close($con); ?> <br /><br /> <input type="Submit" value="Submit Spreads"> </FORM> And here's the "insert_spreads.php Code: [Select] <?php header("Location: admin_main_entry.php"); include("opendatabase.php"); $aspread=$_POST['w%dg%dAspread']; $hspread=$_POST['w%dg%dHspread']; $row=$_POST[$row['game_id']; $sql=" UPDATE schedule SET A_pt_spread= '$aspread',H_pt_spread= '$hspread' WHERE week_id = '$weekID' AND game_id = '$row'"; $result = mysql_query($sql); mysql_close($con) ?> Thanks! In my app, the users will take a multiplication test with 10 problems... I'm not sure how I would post the grade that the user got to the database. When the user finishes the test and hits score it should post their Name/Date & Time/ and Score to the database. I have the name and date & time working. Just not sure how I would approach the score. This is my application... It is small and simple to run in browser. Code: [Select] <!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>Lab 5</title> </head> <body> <?php require_once('database.php'); define ('ROWS', 3); define ('COLS', 3); define ('MAX_NUMBER', 12); date_default_timezone_set('America/New_York'); if (isset($_POST['btn_score'])) { $result_name=$_POST['result_name']; $sql = "INSERT INTO results (result_name, result_score, result_date_time) VALUES ('$result_name', 100, NOW());"; $db->exec($sql); //print_r ($_POST); $time1 = $_POST['ts']; $time1_object = new DateTime($time1); $now = new DateTime(); $time_span = $now->diff($time1_object); $minutes = $time_span->format('%i'); $seconds = $time_span->format('%s'); $seconds+= $minutes * 60; echo "It took $seconds seconds to complete the test<hr />"; foreach ($_POST as $problem => $answer) { if ($problem <> "btn_score" && $problem <> "ts") { //echo "$problem -- $answer <br />"; $problem = explode('_', $problem); $num1 = $problem[2]; $num2 = $problem[3]; $right = $num1 * $num2; if ($answer != $right) { echo "$num1 * $num2 = $answer , The right answer is $right<br />"; } } } } ?> <h1>Lab 5</h1> <form name="lab5" method="post" action="lab5b.php"> <?php $now = new DateTime(); //echo $now->format('Y-m-d H:i:s'); echo "<input type='hidden' name='ts' value='" . $now->format('Y-m-d H:i:s') . "'>"; ?> <table border="1" cellspacing="5" cellpadding="5"> <?php $no_of_problems = 0; for ($row=0; $row<ROWS; $row++) { echo "<tr>"; for ($col=0; $col<COLS; $col++) { $num1 = mt_rand(1,MAX_NUMBER); $num2 = mt_rand(1,MAX_NUMBER); echo "<td>$num1 * $num2 </td>"; echo "<td><input type='text' size='2' name=${no_of_problems}_mult_${num1}_${num2}></td>"; $no_of_problems++; } echo "</tr>"; } $colspan = 2 * COLS; echo "<tr><td colspan=$colspan align='right'><input type='submit' value='Score' name='btn_score'></td></tr>"; ?> </table> <br> <br> <label for="result_name">Student Name:</label> <input type="text" id="result_name" name="result_name" /><br /> </form> <br> <br> </body> </html> Hi there, I'm new to PHP so sorry if this is a really basic question. How do i post date of birth collected from a form, into a database? I have the fields in the form set up as 'day' 'month' 'year' all of which are drop-down boxes. I tried doing it one way which i saw on a different website, but it didn't work. Here is what i tried: Code: [Select] '$_POST[day] . - . $_POST[month]' . - . $_POST[year]', More info: In the database table this information is going to, the "date of birth" field is set to "DATE" type. Don't know if that makes any difference So I have an AJAX call that I'm using to POST 1 variable to a PHP script I have on a separate server. The PHP takes this variable and returns data based off of what the variable is. This works on all browsers except IE9 and below. IE9 returns data but it's an error saying the variable is missing which to me shows that it isn't sending the data. Below I have the AJAX call I'm making:
(function (jQ) { var inviteID = '00000000000'; jQ.ajax({ url: 'www.example.com/test.php', type: 'POST', dataType: 'json', cache: false, data: { classID: inviteID }, error: function (data, status, error) { jQ('.statusField').append('Failu ' + data + status + error); }, success: function (data, status, error) { jQ('.statusField').append('Success: ' + data); } }); })(jQuery); And below I have the PHP script that's being used: <?php //first POST to grab token function runPost($classID) { $postdata = array( 'username' => 'username', 'password' => 'password' ); //open connection $ch = curl_init(); //set the url, POST data curl_setopt($ch, CURLOPT_URL, "https://www.example.com/login"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postdata)); curl_setopt($ch, CURLOPT_USERAGENT, 'example'); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //execute post $result = curl_exec($ch); //close connection curl_close($ch); list($message, $time, $token, $userID) = split(',', $result); list($one, $two, $three, $four, $five) = split('\"', $token); $four = json_encode($four); $four = str_replace('"','',$four); $secondaryPostData = array( 'token' => $four, 'data' => array( 'invitationID' => $classID )); //open connection $chu = curl_init(); //set the url, POST data curl_setopt($chu, CURLOPT_URL, "https://www.example.com/classID"); curl_setopt($chu, CURLOPT_POST, 1); curl_setopt($chu, CURLOPT_POSTFIELDS, json_encode($secondaryPostData)); curl_setopt($chu, CURLOPT_USERAGENT, 'example'); curl_setopt($chu, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($chu, CURLOPT_RETURNTRANSFER, 1); //execute post $secondResult = curl_exec($chu); //close connection curl_close($chu); return json_encode($secondResult); } //Grab classID from javascript echo runPost(trim($_POST['classID'])); ?> Again, this works fine in everything except IE. I've tried using just $.post and even XDomainRequest() and get the same result. The network console in IE shows that the Request body does have the classID in it, but I'm guessing it's just not sending the data to the PHP script. I don't know if I'm missing something that IE needs to send this to the PHP script but any help with this would be GREATLY appreciated. Hi,
I have a database which holds results
Name | Car | etc \ etc | Round 1 | round 2 | round 3 // etc | Total
the points are in the format of;
e.g.
100.5 // 25.6 // 35.8 // 50.0
I input the data manually using a webpage, clicking on the relevant driver, update scores, click submit. I have to manually work out the total, is there a way I can it it automatically add the values from round 1,2,3, etc.
Hi there, OK, there is what I'm trying to accomplish - I want to send POST instantly when the page is loaded without "Submit" button or anything like that. Here how it looks using JavaScript: Code: [Select] <form name="postdata" action="http://www.mywebsite.com/post.php" method="post"> <input name="data" type="text" value="1"/> </form> <script type="text/javascript" language="JavaScript"> document.postdata.submit(); </script> Works fine with JavaScript, however i can't use it. Here is reference for CURL: http://php.net/manual/en/book.curl.php I found this curl_post function at php.net to simplify things up. <?php /** * Send a POST requst using cURL * @param string $url to request * @param array $post values to send * @param array $options for cURL * @return string */ function curl_post($url, array $post = NULL, array $options = array()) { $defaults = array( CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_URL => $url, CURLOPT_FRESH_CONNECT => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FORBID_REUSE => 1, CURLOPT_TIMEOUT => 4, CURLOPT_POSTFIELDS => http_build_query($post) ); $ch = curl_init(); curl_setopt_array($ch, ($options + $defaults)); if( ! $result = curl_exec($ch)) { trigger_error(curl_error($ch)); } curl_close($ch); return $result; } $test = curl_post("http://www.mywebsite.com/post.php", array("data" => "1")); print($test); ?> Looks like it uses GET instead POST (used sniffer to verify this). I'm trying to send POST data to other host, if that matters. Any help would be appreciated. Thanks in advance. I'm trying to figure out a way to post data directly to a URL. For example: <?php if (isset($_POST["pass"]) && ($_POST["pass"]=="$password")) { echo "You did it"; ?> <?php } else { echo "<form method=\"post\"><p align=\"left\">"; echo "<input name=\"pass\" type=\"text\" size=\"25\" maxlength=\"40\"><input value=\"Enter Pass\" type=\"submit\"></form>"; exit; } ?> Let's assume $password is 'password'. Why can't I simply pass the information through the URL to access the page with something like this: Code: [Select] http://mypage.com/the-same-page.php?pass=password Hi everyone! So, I have recently become interested in the world of webpage design and HTML coding. Thus far, I have created a few simple HTML webpages, the first of which includes some basic facts and information on the state of NC. Everything has gone rather smoothly for me until this point, but I would now like to incorporate a bit of PHP into my knowledge of web development. First, I would like to include a form on my NC page that once submitted, goes to a new PHP page displaying the inputted data to the screen. On the new page, I am attempting to include files: a header and footer. On my other couple of pages for which I would like to add server side includes. And lastly, if possible, it would be great if I could learn how to add some additional features like sending e-mails or displaying the date. Any advice or tips on how to go about this would be greatly appreciated! I'm having problems posting date from my MYSQL database. The date in my database is this "2011-01-08 02:53:14" but the it only echo's "01.01.70" Could someone help me figure out why? Here is my code: Code: [Select] <?php $servername='localhost'; $dbusername='root'; $dbpassword=''; $dbname='store'; connecttodb($servername,$dbname,$dbusername,$dbpassword); function connecttodb($servername,$dbname,$dbuser,$dbpassword) { global $link; $link=mysql_connect ("$servername","$dbuser","$dbpassword"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error()); } // Get all the data from the "example" table $result = mysql_query("SELECT * FROM henvendelser WHERE status = 'Ubehandlet' ORDER by id desc ") or die(mysql_error()); echo "<table cellspacing='12px' cellpaddomg='5px' align='center'>"; echo "<tr> <th>ID</th> <th> Opprettet </th> <th>Navn</th> <th>Telefon</th> <th>Emne</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array($result)) { $postTime = $row['date']; $thisTime = time(); $timeDiff = $thisTime-$postTime; if($timeDiff <= 604800) { // Less than 7 days[60*60*24*7] $color = '#D1180A'; } else if($timeDiff > 604800 && $timeDiff <= 1209600) { // Greater than 7 days[60*60*24*7], less than 14 days[60*60*24*14] $color = '#D1B30A'; } else if($timeDiff > 1209600) { // Greater than 14 days[60*60*24*14] $color = '#08C90F'; } echo '<tr style="color: '.$color.';">'; echo '<td>'. $row['id'] .'</td>'; echo '<td>'. date('d.m.y', $postTime) .'</td>'; echo '<td><a href="detaljer.php?view='. $row['id'] .'">'. $row['Navn'] .'</a></td>'; echo '<td>'. $row['Telefon'] .'</td>'; echo '<td>'. $row['Emne'] .'</td>'; echo '</tr>'; } echo '</table>'; ?> $day = $_POST['day']; $month = $_POST['month']; $year = $_POST['year']; $date = date("Y-m-d", time(0,0,0,$month, $day, $year)); $sql="INSERT INTO child_info (first_name,middle_name,first_family_name,second_family_name, gender,birthdate,mother_living,father_living,brothers,sisters,resident_time,dorm,school,grade_level,school_subject,speak_english,food,medical_allergies,physical_limits,future,instrument,work,social,special_people,hobby,sponsor) VALUES ('$_POST[first_name]','$_POST[middle_name]','$_POST[first_family_name]','$_POST[second_family_name]','$_POST[gender]','$_POST[date]','$_POST[mother_living]','$_POST[father_living]','$_POST[brothers]','$_POST[sisters]','$_POST[resident_time]','$_POST[dorm]','$_POST[school]','$_POST[grade_level]','$_POST[school_subject]','$_POST[speak_english]','$_POST[food]','$_POST[medical_allergies]','$_POST[physical_limits]','$_POST[future]','$_POST[instrument]','$_POST[work]','$_POST[social]','$_POST[special_people]','$_POST[hobby]','$_POST[sponsor]')"; I have an email form that is working wonderfully. I have a select box that has a list of names of people that you can email. That list is being pulled from a database. It is currently sending to the email related to the name selected in the dropdown menu. However, in the email that sends, I would like the name of the recipient to show up in the greeting. I.E. Dear "name from dropdown". How do I go about doing this. My select box that holds the query for the name is as folows: <?php echo '<select name="First_and_Last_Name">'; while( $array = mysql_fetch_assoc($result) ) { $text_for_select = $array["First_Name"] . " " . $array["Last_Name"]. " " . $array["District"]; $value_for_select = $array["Email"]; echo "<option></option>\n"; echo "<option value=\"$value_for_select\">$text_for_select</option>\n"; } echo '</select>';?> No, this is querying the First and Last Name and another variable called district in to a new variable called "text_for_select". I just want to either print the "text_for_select" after the "Dear", or better yet, just the "First_Name" and "Last_Name". How would I get this to print there? This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=346552.0 Ok, I have one database three tables. Table 1 is ncmr the main table where everything is to be entered. Table 2 is companies, where all the companies in pull down menu 1 is located. Table 3 is fabricators, where all the people who have had hands on the product are residing. I want the selected choices of table 2 and 3 to be inputed into table 1. I know this has to be possible, but I don't know how. I thought I wrote the code correctly, but it seems not. Can someone review my code and show me where my mistake is? Here is the page: http://kaboomlabs.com/PDI/post2.php Thanks. Code: [Select] <?php require_once('connectvars.php'); $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>PDI Non-Conforming Materials Report</title> <link rel="stylesheet" type="text/css" href="CSS/postie.css" /> </head> <body> <div id="logo"> <img src="images/PDI_Logo_2.1.gif" alt="PDI Logo" /> </div> <div id="title"> <h3 id="NCMR2">Non-Conforming Materials Report (NCMR)</h3> </div> <?php //Post Data if (isset($_POST['submit'])) { $ab = mysqli_real_escape_string($dbc,$_POST['ab']); $date = mysqli_real_escape_string($dbc,date('Y-m-d',strtotime ($_POST['date']))); $part = mysqli_real_escape_string($dbc,$_POST['part']); $rev = mysqli_real_escape_string($dbc,$_POST['rev']); $partdesc = mysqli_real_escape_string($dbc,$_POST['partdesc']); $ncmrqty = mysqli_real_escape_string($dbc,$_POST['ncmrqty']); $comp = mysqli_real_escape_string($dbc,$_POST['comp']); $ncmrid = mysqli_real_escape_string($dbc,$_POST['ncmrid']); $rma = mysqli_real_escape_string($dbc,$_POST['rma']); $jno = mysqli_real_escape_string($dbc,$_POST['jno']); $fdt = mysqli_real_escape_string($dbc,$_POST['fdt']); $cof = mysqli_real_escape_string($dbc,$_POST['cof']); $fab1= mysqli_real_escape_string($dbc,$_POST['fab1']); $fab2= mysqli_real_escape_string($dbc,$_POST['fab2']); $fab3= mysqli_real_escape_string($dbc,$_POST['fab3']); $non= mysqli_real_escape_string($dbc,$_POST['non']); $dis= mysqli_real_escape_string($dbc,$_POST['dis']); $comm= mysqli_real_escape_string($dbc,$_POST['comm']); $caad= mysqli_real_escape_string($dbc,$_POST['caad']); $po= mysqli_real_escape_string($dbc,$_POST['po']); $pod = mysqli_real_escape_string($dbc,date('Y-m-d',strtotime($_POST['pod']))); $dri = mysqli_real_escape_string($dbc,date('Y-m-d',strtotime($_POST['dri']))); $output_form = 'no'; if (empty($ab) || empty($date) || empty($part) || empty($partdesc)){ // We know at least one of the input fields is blank echo '<div id="alert">'; echo 'Please fill out all of the required NCMR information.<br />'; echo '</div>'; } $output_form = 'yes'; } //Access the Database if (!empty($ab) && !empty($date) && !empty($pod)) { $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error connecting to MySQL server.'); $query = "INSERT INTO ncmr (ab, date, part, rev, partdesc, ncmrqty, comp, ncmrid, rma, jno, fdt, cof, fab1, fab2, fab3, non, dis, comm, caad, po, pod, dri) VALUES ('$ab','$date','$part','$rev','$partdesc','$ncmrqty','$comp','$ncmrid','$rma','$jno','$fdt','$cof','$fab1','$fab2','$fab3','$non','$dis','$comm','$caad','$po','$pod','$dri')"; $data = mysqli_query($dbc, $query) or die("MySQL error: " . mysqli_error($dbc) . "<hr>\nQuery: $query"); // Confirm success with the user echo '<tr><td class="thank">'; echo '<p>Thank you for adding the NCRM, the correct person will be informed.</p>'; echo '<p><a href="post.php"><< Back to the form</a></p>'; $output_form = 'no'; echo '</td></tr>'; mysqli_close($dbc); } if ($output_form == 'yes') { echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>"; echo '<fieldset>'; //Part, Rev, Part Description, NCMR Qty echo '<div id="box1">'; echo '<div id="ab"><span class="b">Added By: </span><input type="text" name="ab" value="" /></div>'; echo '<div id="date"><span class="b">Date Filed: </span><input type="text" name="date" value="" /></div>'; echo '<div id="part"><span class="b">Part Number: </span><input type="text" name="part" value="" /></div>'; echo '<div id="rev"><span class="b">Part Revision: </span><input type="text" name="rev" value="" /></div>'; echo '<div id="partdesc"><span class="b">Part Description: </span><textarea name="partdesc" rows="3" cols="22" ></textarea></div>'; echo '<div id="ncmrqty"><span class="b">NCMR Qty: </span><input type="text" name="ncmrqty" value="" /></div>'; echo '</div>'; //Company, Customer NCMR, Internal RMA, and Job Number echo '<div id="box2">'; echo'<div id="comp">'; echo '<span class="b">Company: </span>'; $mysqli->select_db('comp'); $result = $mysqli->query("SELECT * FROM comp"); $i = 0; echo "<SELECT name='comp'>\n"; while($row = $result->fetch_assoc()) { if ($i == 4) echo '<option value="lines">-----</option>'; echo "<option value='{$row['user_id']}'>{$row['name']}</option>\n"; $i++; } echo "</select>\n"; echo '</div>'; echo '<div id="ncmrid"><span class="b">Customer NCMR ID: </span><input type="text" name="ncmrid" value="" /></div>'; echo '<div id="rma"><span class="b">Internal RMA #: </span><input type="text" name="rma" value="" /></div>'; echo '<div id="jno"><span class="b">Job #: </span><input type="text" name="jno" value="" /></div>'; echo '</div>'; //Type of Failure and Class of Failure echo '<div id="box3">'; echo '<h2>Failure</h2>'; echo '<div id="fdt">'; echo '<span class="b">Failure Due To: </span><br />'; echo '<select name="fdt">'; echo '<option value="none">----None----</option>'; echo '<option value="In House">In House</option>'; echo '<option value="Third Party">Third Party</option>'; echo '</select>'; echo '</div>'; echo'<div id="cof">'; echo '<span class="b">Class of Failu </span><br />'; echo '<select name="cof">'; echo '<option value="none">----None----</option>'; echo '<option value="Materials">Materials</option>'; echo '<option value="Fabrication">Fabrication</option>'; echo '<option value="Drawing">Drawing</option>'; echo '<option value="Assembly">Assembly</option>'; echo '<option value="Testing">Testing</option>'; echo '<option value="Electrical">Electrical</option>'; echo '<option value="Programming">Programming</option>'; echo '<option value="Machining">Machining</option>'; echo '<option value="Inspection">Inspection</option>'; echo '<option value="Purchasing">Purchasing</option>'; echo '<option value="Administrator">Administrator</option>'; echo '</select>'; echo '</div>'; echo '</div>'; //Fabricators echo '<div id="box4">'; echo '<h2>Fabricators</h2>'; echo'<div id="fab1">'; $mysqli->select_db('user'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='fab1'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['user_id']}'>{$row['user']}</option>\n";} echo "</select>\n"; echo '</div>'; echo'<div id="fab2">'; $mysqli->select_db('user'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='fab2'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['user_id']}'>{$row['user']}</option>\n";} echo "</select>\n"; echo '</div>'; echo'<div id="fab3">'; $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $mysqli->select_db('user'); $result = $mysqli->query("SELECT * FROM user"); echo "<SELECT name='fab3'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['user_id']}'>{$row['user']}</option>\n";} echo "</select>\n"; echo '</div>'; echo '</div>'; //Nonconformity, Disposition, Comments and Comments & Additional Details echo '<div id="box5">'; echo '<div id="non"><span class="b">Nonconformity: </span><br /><textarea name="non" rows="3" cols="110" ></textarea><br /></div>'; echo '<div id="dis"><span class="b">Disposition: </span><br /><textarea name="dis" rows="3" cols="110" ></textarea></div>'; echo '<div id="comm"><span class="b">Comments: </span><br /><textarea name="comm" rows="3" cols="110" ></textarea></div>'; echo '<div id="caad"><span class="b">Comments and/or Additional Details: </span><br /><textarea name="caad" rows="3" cols="110" ></textarea></div>'; //PO, PO Date, and Date Recieved echo '<div id="podr">'; echo '<div id="po"><span class="b">PO: </span><input type="text" name="po" size="7" value="" /></div>'; echo '<div id="pod"><span class="b">PO Date: </span><input type="text" name="pod" size="7" value="" /></div>'; echo '<div id="dri"><span class="b">Date Received: </span><input type="text" name="dri" size="7" value=""'; echo '</div>'; echo '<div id="button"><input type="submit" value="Submit NCMR" name="submit" /></div>'; echo '</div>'; echo '</fieldset>'; echo '</form>'; } ?> </body> </html> I ve been having trouble processing form data to the same page as the do on facebook comments. Can php scripts do that. Help me guys!! Hello. I currently have a web page that allows a user to enter text into a form then select a "Submit Query" button; upon doing this the entered text is saved to a database and displayed for the user on the same page (the page where the form and "Submit Query" button are located). My question is as follows: I wish the results to be displayed on a new page when the "Submit Query" button is clicked, not displayed on the same page. Is this achieved through targeting? I am a bit lost at this point on how to achieve this result. Thank-you in advance for any help. ~Matty Hello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. Hi, I've currently started to modify a chat script of mine to output a moderation panel but the moderation page seems empty(blank) every time I load it. What im trying to do is to take the ID part in my URL via the $_GET and look it up in my database table in the column named id, then select that specific row to be able to retrieve the StringyChat_ip and place it into another table to ban the IP and the second thing im trying to do is to be able to delete the specific row from my table.
My Http link look something like
http://imagecrab.fre.../ban.php?id=159
and my ban.php page where I want to lookup the 159 part and do the banning etc looks like
<? include("admin_code_header.php"); if ($_POST["DeletePost"]) { $id = $_POST['id']; $query = "DELETE FROM ".$dbTable." WHERE id='".$id."'"; mysql_query($query); echo "ID removed from system: ".$id; } if ($_POST["BanIP"]) { $IP_To_Add = $_POST["ip"]; $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")"; $result = mysql_query($sql); } $result = mysql_query("SELECT * FROM ".$dbTable." WHERE id='".$id."'",$db); while ($myrow = mysql_fetch_array($result)) { $msg = $myrow["StringyChat_message"]; $idm = $myrow["id"]; ?> <html> <form name="form<? echo $myrow["id"];?>" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input name="DeletePost" type="submit" id="DeletePost" value="Delete"> <input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $myrow["StringyChat_ip"];?>"> </form> </html> <? } ?> hi guys, im new to this forum I'm new also to php, I need help from you guys: I want to display personal information from a certain person (the data is on the mysql database) using his name as a link: example: (index.php) names 1. Bill Gates 2. Mr. nice Guy i want to click Bill Gates (output.php) Name: Bill Gates Country:xxxx Age: xx etc. How can i make this or how to learn this? |