PHP - Form Values Return Blank To Database
Hey all. I'm a noob so bare with me. Just started studying php and have an assignment due. At this phase of the project I have to create a form where a user can register data and I should retrieve that data and store it in my database. Now I have already created the form (student_reg.php) and a separate file with php code (demo.php)
My database is name "registration" and I am trying to put this info in the "student" table. It has about 15 fields but for now I am only trying trying to insert the 1 field of data to test if it works. Dont know if that may cause problems? So far my demo.php connects to the database successfully. The problem I am having is the information I submit does not showing in the database field. However, I have an id field in my case a student number field which is set to auto increment so it automatically updates (1,2,3,4) with each new sumbitted info. When I submit the info the id field gets updated each time with a new row ( so i assume some information is somehow going through ) however the info I entered will remain blank in its field. :banghead: Heres my form (student_reg.php) Code: [Select] <div id="apdiv3"> <FORM action = "demo.php" method ="post "> <p>Course name:</p> <INPUT TYPE = "text" name="input"/> <INPUT TYPE = "Submit" VALUE = "Submit"/> </div> </FORM> and heres my php code to retrieve the form info Code: [Select] <?PHP include 'includes/config.php'; //connect to database $link=mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); //error check if (!$link) { die('could not connect: ' . mysql_error()); } $db_selected=mysql_select_db(DB_NAME, $link); // error check if (!$db_selected) { die('can\t use ' . DB_NAME . ': ' . mysql_error()); } // Connected to database // retrieve form data $value=(isset($_POST['input'])); $sql = "INSERT INTO student (sname) VALUES ('$value')"; if (!mysql_query($sql)) { die ('Error: ' . mysql_error()); } mysql_close(); ?> I also recieved a notice "undefined index" or something like that from this part of the code "$value=(isset($_POST['input']));" before I inserted "isset" to the code. I'm not sure if what I did fixed the problem or only hid it, or whether that notice was related to the problem I'm having of not retrieving the info. Haha sorry guys know this is probably childs play for you but I just started out and really need to fix this so I can catch up with this project. Feel free to add tips and comments on other areas. Thanks :mrgreen: Similar Tutorialsafter cloasing connection of database i still got the values form database. Code: [Select] <?php session_start(); /* * To change this template, choose Tools | Templates * and open the template in the editor. */ require_once '../database/db_connecting.php'; $dbname="sahansevena";//set database name $con= setConnections();//make connections use implemented methode in db_connectiong.php mysql_select_db($dbname, $con); //update the time and date of the admin table $update_time="update admin set last_logged_date =CURDATE(), last_log_time=CURTIME() where username='$uname'limit 3,4"; //my admin table contain 5 colums they are id, username,password, last_logged_date, last_log_time $link= mysql_query($update_time); // mysql_select_db($dbname, $link); //$con=mysql_connect('localhost', 'root','ijts'); $result="select * from admin where username='a'"; $result=mysql_query($result); mysql_close($con); //here i just check after closing data baseconnection whether i do get reselts but i do, why? echo "after the cnnection was closed"; if(!$result){ echo "cont fetch data"; }else{ $row= mysql_fetch_array($result); echo "id".$row[0]."usrname".$row[1]."passwped".$row[2]."date".$row[3]."time".$row[4]; } // echo "<html>"; //echo "<table border='1' cellspacing='1' cellpadding='2' align='center'>"; // echo "<thead>"; // echo"<tr>"; // echo "<th>"; // echo ID; // echo"</th>"; // echo" <th>";echo Username; echo"</th>"; // echo"<th>";echo Password; echo"</th>"; // echo"<th>";echo Last_logged_date; echo "</th>"; // echo "<th>";echo Last_logged_time; echo "</th>"; // echo" </tr>"; // echo" </thead>"; // echo" <tbody>"; //while($row= mysql_fetch_array($result,MYSQL_BOTH)){ // echo "<tr>"; // echo "<td>"; // echo $row[0]; // echo "</td>"; // echo "<td>"; // echo $row[1]; // echo "</td>"; // echo "<td>"; // echo $row[2]; // echo "</td>"; // echo "<td>"; // echo $row[3]; // echo "</td>"; // echo "<td>"; // echo $row[4]; // echo "</td>"; // echo "</tr>"; // } // echo" </tbody>"; // echo "</table>"; // echo "</html>"; session_destroy(); session_commit(); echo "session and database are closed but i still get values from doatabase session is destroyed".$_SESSION['admin']; ?> session is destroyed but database connection is not closed. thanks hi , i have an error in my php . It will display successful only if all file being upload , if there have one file not upload . it go to blankpage not tell any error or success.I have file that being upload to different path folder
$fileName14 = basename($_FILES["penaja"]["name"]); $targetFilePath14=$targetDir14. $fileName14; $fileType14 = pathinfo($targetFilePath14,PATHINFO_EXTENSION); $allowTypes14= array('pdf','PDF','docx','DOCX'); //kesihatan $targetDir15 ="folder/pda-semakan/kesihatan/"; $fileName15 = basename($_FILES["umpapkp"]["name"]); $targetFilePath15=$targetDir15. $fileName15; $fileType15 = pathinfo($targetFilePath15,PATHINFO_EXTENSION); $allowTypes15= array('pdf','PDF','docx','DOCX'); //jhepa $targetDir16 ="folder/pda-semakan/jhepa/"; $fileName16 = basename($_FILES["umpajhepa"]["name"]); $targetFilePath16=$targetDir16. $fileName16; $fileType16 = pathinfo($targetFilePath16,PATHINFO_EXTENSION); $allowTypes16= array('pdf','PDF','docx','DOCX'); if(in_array($fileTypeg, $allowTypesg)){ if(in_array($fileType, $allowTypes)){ if(in_array($fileType1, $allowTypes1)){ if(in_array($fileType2, $allowTypes2)){ if(in_array($fileType3, $allowTypes3)){ if(in_array($fileType4, $allowTypes4)){ if(in_array($fileType5, $allowTypes5)){ if(in_array($fileType6, $allowTypes6)){ if(in_array($fileType7, $allowTypes7)){ // Upload file to server if(move_uploaded_file($_FILES["gambar"]["tmp_name"], $targetFilePathg)){ if(move_uploaded_file($_FILES["surat"]["tmp_name"], $targetFilePath)){ if(move_uploaded_file($_FILES["ic"]["tmp_name"], $targetFilePath1)){ if(move_uploaded_file($_FILES["sijilkelahiran"]["tmp_name"], $targetFilePath2)){ if(move_uploaded_file($_FILES["sijilspm"]["tmp_name"], $targetFilePath3)){ if(move_uploaded_file($_FILES["sijilberhenti"]["tmp_name"], $targetFilePath4)){ if(move_uploaded_file($_FILES["sijilmatrik"]["tmp_name"], $targetFilePath5)){ if(move_uploaded_file($_FILES["sejulai"]["tmp_name"], $targetFilePath6)){ if(move_uploaded_file($_FILES["bmjulai"]["tmp_name"], $targetFilePath7)){
Hi everyone, I'm new to this group and new to php. I have created a multi-part form that allows the user the option to add multiple input fields to a form to upload images. Here is the form structu Code: [Select] <form action="Scripts/processreports2.php" method="post" enctype="multipart/form-data" name="report_form" target="uploader" class="reportfrm"> <fieldset> <legend>Upload your images</legend> <ol id="add_images"> <li> <input type="file" class="input" name="files[]" /> </li> <li> <input type="file" class="input" name="files[]" /> </li> <li> <input type="file" class="input" name="files[]" /> </li> </ol> <input type="button" name="addFile" id="addFile" value="Add Another Image" onclick="window.addFile(this);"/> </fieldset> <p>* indicates a required field.</p> <input name="submit" type="submit" id="submit" value="Send Info!" /> </form> Through php a maximum of three input fields are fed into an array that checks to make sure that the uploaded files are images and not some other type of file. The uploading porition of this script works. Now I am trying to get the values of the input fields as a string and insert them into the database as one record. Let's say the user has three files they want to upload. I have managed to get the files as a string ie; file1.jpg, file2.jpg, file3.jpg but what is happening is that I am getting three separate records with file1.jpg, file2.jpg, file3.jpg in them. If the user has only two files to upload then I get two separate records with file1.jpg and file2.jpg in them. (Hope that makes sense). I want one record. I have been struggling with this since Monnday and while every day I get closer, this is as close as I can get. Below is the php code. #connect to the database mysql_connect("localhost", "root", ""); mysql_select_db("masscic"); //Upload Handler to check image types function is_image($file) { $file_types = array('jpeg', 'gif', 'bmp'); //acceptable file types if ($img = getimagesize($file)){ //echo '<pre>'; //print_r($_FILES); used for testing //print_r($img); used for testing if(in_array(str_replace('image/', '', $img['mime']), $file_types)) return $img; } return false; } //form submission handling if(isset($_POST['submit'])) { //file variables $fname = $_FILES['files']['name']; $ftype = $_FILES['files']['type']; $fsize = $_FILES['files']['size']; $tname = $_FILES['files']['tmp_name']; $ferror = $_FILES['files']['error']; $newDir = '../uploads/'; //relative to where this script file resides for($i = 0; $i < count($fname); $i++) { //echo 'File name ' . $fname[$i] . ' has size ' . $fsize[$i]; used for testing if ($ferror[$i] =='UPLOAD ERR OK' || $ferror[$i] ==0) { if(is_image($tname[$i])) { //append the tmp_name($tname) to the file name ($fname) and upload to the server move_uploaded_file($tname[$i], ($newDir.time().$fname[$i])); echo '<li><span class="success">'.$fname[$i].' -- image has been accepted<br></span></li>'; }else echo '<li><span class="error">'.$fname[$i].' -- is not an accepted file type<br></span></li>'; } if (is_array($fname)) $files = implode(', ',$fname); //else $files = $fname; $sqlInsert = mysql_query("INSERT INTO files (file_names) VALUES('$files')") or die (mysql_error()); } } Hi all, I am having some trouble with a script.. all works fine except for the calculation part. It isn't adding up, but the reason for this is because when I echoed all the variable it seems that they are blank, the problem is I can't figure out why? <?php # you don't display errors on in-use scripts, do you? ini_set('display_errors',0); error_reporting(E_ALL|E_STRICT); class webPoll { # makes some things more readable later const POLL = true; const VOTES = false; # number of pixels for 1% on display bars public $scale = 2; public $question = ''; public $answers = array(); private $header = '<form class="webPoll" method="post" action="%src%"> <input type="hidden" name="QID" value="%qid%" /> <h4>%question%</h4> <br /> <ul>'; private $center = ''; private $footer = "\n</ul>%button%\n</form>\n"; private $button = '<p class="buttons"><button type="submit">Vote!</button></p>'; private $md5 = ''; /** * --- * Takes an array containing the question and list of answers as an * argument. Creates the HTML for either the poll or the results depending * on if the user has already voted */ public function __construct($params) { $this->question = array_shift($params); $this->answers = $params; $this->md5 = md5($this->question); $this->header = str_replace('%src%', $_SERVER['SCRIPT_NAME'], $this->header); $this->header = str_replace('%qid%', $this->md5, $this->header); $this->header = str_replace('%question%', $this->question, $this->header); # seperate cookie for each individual poll isset($_COOKIE[$this->md5]) ? $this->poll(self::VOTES) : $this->poll(self::POLL); } private function poll($show_poll) { $replace = $show_poll ? $this->button : ''; $this->footer = str_replace('%button%', $replace, $this->footer); # static function doesn't have access to instance variable if(!$show_poll) { $results = webPoll::getData($this->md5); $votes = array_sum($results); } for( $x=0; $x<count($this->answers); $x++ ) { $this->center .= $show_poll ? $this->pollLine($x) : $this->voteLine($this->answers[$x],$results[$x],$votes); } echo $this->header, $this->center, $this->footer; } private function pollLine($x) { isset($this->answers[$x+1]) ? $class = 'bordered' : $class = ''; return " <li class='$class'> <label class='poll_active'> <input type='radio' name='AID' value='$x' /> {$this->answers[$x]} </label> </li> "; } private function voteLine($answer,$result,$votes) { echo "Answer: $answer"; echo "<br />"; echo "Result: $result"; echo "<br />"; echo "Votes: $votes"; echo "<br />"; echo "<br />"; $result = isset($result) ? $result : 0; $percent = round(($result/$votes)*100); $width = $percent * $this->scale; return " <li> <div class='result' style='width:{$width}px;'> </div>{$percent}% <label class='poll_results'> $answer </label> </li> "; } // remainder of script here ?> The ones that are returning blank a $result and $votes $results should be the number of votes a specific option has received while $votes is the total number of votes in the whole poll. My database contains the following data... QID AID votes 685b9628ca340529fa54208c65721dd7 2 205 685b9628ca340529fa54208c65721dd7 0 5 685b9628ca340529fa54208c65721dd7 1 2 It's from the following tutorial - http://net.tutsplus.com/tutorials/ph...poll-with-php/ Can anyone advise me here? Many thanks, Greens85 hello, normally when i query mysql, it returns my results line by line. im trying to make a print view now that will put 3 results in a row before going to the next row. any help appreciated. I am using Magento (Ver 1.9.x) If i try with my localhost success url like, http://192.168.1.65/magento/index.php/checkout/onepage/success/ and return success message with order id. if i try with live, success url like, https://abc.in/payubiz/redirect/success/ success page like blank page. How to solve the issue? Code : https://github.com/ZusZus/Payubiz Edited February 4, 2020 by aveevaSELECT field, (array of values from table 2) FROM $table1 t1 LEFT JOIN $table2 ON t1.id=t2.id ... is something like this possible? (where I return records from t1 in a LEFT JOIN, but also get an array of any of the fields/records from the table 2) not sure if this is possible but i do not know how to return multiple values and read them where the call was made. Code: [Select] $string = "clause1"; func1($string); // somehow read the response and use the return values seperately. // both $string2 and $string3 Code: [Select] function func1($input) { if ($input == "clause1") { $string2= "value2"; $string3= "value6"; } if ($input == "clause2") { $string2= "value3"; $string3= "value7"; } if ($input == "clause3") { $string2= "value4"; $string3= "value8"; } if ($input == "clause4") { $string2= "value5"; $string3= "value9"; } return ($requesttype, $messagetitle); } I have an issue with some code I have. All the code works correctly apart from when submit is clicked not only does it update a the current club but it creates a blank entry in the database! I cant see whats wrong. Here is the code......... //gets $validation = $_GET['new_club']; //Querys $qGetClub = "SELECT * FROM clubs WHERE validationID = '$validation'"; $rGetClub = mysql_query($qGetClub); $Club = mysql_fetch_array($rGetClub); //Query for category by name $qGetCat = "SELECT * FROM club_category WHERE catID = ".$Club['cat'].""; $rGetCat = mysql_query($qGetCat); $CatName = mysql_fetch_array($rGetCat); //query for related sub categorys. $qGetSub = "SELECT * FROM sub_categorys WHERE catID =".$Club['cat'].""; $rSubCat = mysql_query($qGetSub); // query for groups created $Groupq = mysql_query("SELECT * FROM groups WHERE memberID = '".$User['memberID']."'"); //end of querys if(isset($_POST['insert_clubbtn1'])){ //Process data for validation $subcat = trim($_POST['subcat']); $NewSubCat = trim($_POST['NewSubCat']); //Prepare data for db insertion $subcat = mysql_real_escape_string($subcat); //find the new category //insert $result = mysql_query("UPDATE clubs SET `sub_category` = '$subcat' WHERE validationID ='$validation'") or die(mysql_error()); if ($result!=="") { $otherg = trim($_POST['other_groups']); $newg = trim($_POST['new_group']); $newg = mysql_real_escape_string($newg); //if an item other than none from the list is selected then update the club with an ID relating to the group it belongs to if ($otherg !=='None') { $groupsq = mysql_query("UPDATE `clubs` SET groupID ='$otherg' WHERE validationID ='$validation'") or die (mysql_error()); } // If none is selected then $newg must have a value so create a new group in the groups table and then on the next page I will add the group in the club table else { $groupsq = mysql_query("INSERT INTO `groups` (`memberID`, `group`, `clubID`) VALUES ('".$User['memberID']."', '$newg', '".$Club['clubID']."')")or die (mysql_error()); } } if ($NewSubCat !="") { mail("mail","New Sub Category Request","Dear Ring Master, \n\nThe club in the name of $name with a validation code of $validationID would like a new sub category called $new_cat\n\n \nTeam Arena\n\n\n\n"); } $url = "/members/create/create_clubp3.php?new_club=$validation"; header("Location: $url"); } So I have an existing picklist that i am trying to tweak - I am making it into a multiselect and trying to return multiple values
I have been able to accomplish the first part by adding select 'multiple' but when i submit it only returns results for the last value selected.
Here is the code for the form (Left out the picklists that do not need to be multiple select)
<td align="center" valign="top"> <? // base64_encode(base64_encode( 'test1'))?> <br /> <br /> <form id='report_form' action="driverreport_sd.php" method="post" name="report_form"> <!--<div class="criteria_div">--> <table align="center" class="table_border" cellpadding="5" cellspacing="0" width="80%"> <tr> <td align="right" class="first_td"> Status: </td> <td align="left"> <select multiple name='Status' id='Status'> <? $statuslist=$ObjReport->ObjStatus->get_Status_List(); while($status=mysql_fetch_object($statuslist)) { if($status->Status=="Please Select") { ?> <option value="<?=$status->Status?>" <?=($status->Status==$_REQUEST['Status']?"selected=selected":"")?>> <?=$status->Status?></option> <? } else { ?> <option value="<?=$status->Status?>" <?=($status->Status==$_REQUEST['Status']?"selected=selected":"")?>> <?=$status->Status?></option> <? } } ?> </select> </td> </tr> <td align="center" colspan="2"> <input type="hidden" id='sort_by' name='sort_by' value="<?=$_REQUEST['sort_by']?>" /> <input type="hidden" name='search_val' id='search_val' value="<?=$_REQUEST['search_val']?>" /> <input type="hidden" name='search_by' id='search_by' value="<?=$_REQUEST['search_by']?>" /> <input type="hidden" name="report_submited" value='report_submited' /> <button type="submit" id="report_submited" name="" value='submit'>Submit</button> </td> and here is the return request <? if($_REQUEST['report_submited']) { $ReportData=$ObjReport->generate_report($_REQUEST['Status'],$_REQUEST['School'],$_REQUEST['Campaign'],$_REQUEST['State'],$_REQUEST['Stdtype'],$_REQUEST['Primbad'],$_REQUEST['Rep'],$_REQUEST['From_Date'],$_REQUEST['To_Date'],$_REQUEST['sort_by'],$_REQUEST['search_by'],$_REQUEST['search_val']); $currentTotalRow=mysql_num_rows($ReportData); if($currentTotalRow>0) { ?> Any suggestions would be appreciated Thanks! I call a web service and it retuens the values in the following format
$response = $client->submitRequest($requestParams);Which returns stdClass Object ( [return] => stdClass Object ( [result_code] => 0 [result_data] => City[0]=Chicago [message_text] => ) )what I want is just the value for [result_data] => City[0]=Chicagoassigned to a variable Psedo Code $city = [result_data] => City[0]=Chicago;so that $city = Chicago; Probably a silly question, but say you have a value in a mysql database that (naturally) can be either be blank or have characters in it. If in my PHP I am doing a check to see if that returned field from the database HAS or DOES NOT HAVE a value entered in it, what is the proper way to do it? For example, you could do either of the following below (and I'm sure there are probably 10 other ways to do it as well). Is one of these quicker/more efficient than the other? I know it probably does not matter in the grand scheme of things because it's such a quick check either way, but if one way is more "proper" than the other, please let me know... Code: [Select] if ($mysqlvalue!=="") OR if (strlen($mysqlvalue>0)) OR I have 2 files; Newfault.php and thankyou.php 1) Data is entered into a form in Newfault.php 2) The data from this form is retieved in thankyou.php and is then inserted into a table called "Calls" Problem: My entered record is being added to my database OK, but it is also adding a blank record for some reason and I can't work out why. Can anyone help? This is for my uni assignment. Thanks, Ladykudos hi all i am having a big problem that i have been trying to find out what is going on for weeks. i have a echo script that echos data that is in my database, and if i have to refresh the page it will add blank data in my database and the top echo info is blank as well. how can i fix this, and i was wanting to know how do i echo out my info in a textarea. i added a jepg to show you what i mean. here is my code echoforms.php <?php error_reporting(0); require_once('demo.php'); /*Open the connection to our database use the info from the config file.*/ $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); $sql = "SELECT company_name, contact_name, address, street_number, postcode, contact_number, contact_email, budget, description FROM 3dartactforms"; $results = mysql_query($sql); if (!$results) { die('Invalid query: ' . mysql_error()); } while($result = mysql_fetch_array( $results )){ echo '<div style="border: 1px solid #e4e4e4; padding: 15px; margin-bottom: 10px;">'; echo date("d/m/y"); echo '<p>Company Name: ' . $_POST['company_name'] . '</p>'; echo '<p>Contact Name: ' . $_POST['contact_name'] . '</p>'; echo '<p>Address: ' . $_POST['address'] . '</p>'; echo '<p>Street Number: ' . $_POST['street_number'] . '</p>'; echo '<p>Postcode: ' . $_POST['postcode'] . '</p>'; echo '<p>Contact Number: ' . $_POST['contact_number'] . '</p>'; echo '<p>Contact Email: ' . $_POST['contact_email'] . '</p>'; echo '<p>Budget: ' . $_POST['budget'] . '</p>'; echo '<p>Description: ' . $_POST['description'] . '</p>'; echo '</div>'; } ?> Hi there, I am using this code to send the users email address to the database. That works fine, but i keep getting blank info added to the database. Does anyone know how i can stop this? <?php $con = mysql_connect("*","*","*"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ogs_mailinglist1", $con); $sql="INSERT INTO mailinglist (email) VALUES ('$_POST[rec_email]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con); ?> Thanks, Hey guys, So im building a Content Management System for my A2 project in Computing, and i have a dataBase class. Now, i can return one thing, or do things like inserts however im having a problem returning a list of things such as: dataBase.class.php Code: [Select] public static function getNYCPost($table, $limit) { dataBase::_dbConnect(); if($limit == 0) { //debug: echo 'in as 0'; $data = mysql_query("SELECT id, linklabel FROM ".$table." WHERE showing='1' AND id >= 2"); } if($limit == 1) { //debug: echo 'in'; $data = mysql_query("SELECT id, linklabel FROM ". $table ." WHERE showing='1' AND id >= 2 ORDER BY id DESC LIMIT 5"); return $data; } } When i try to do this in the main code: index.php Code: [Select] <?php $list = dataBase::getNYCPost($pages,1); // echo $list; while ($row = mysql_fetch_array($list)) { $pageId = $row["id"]; $linklabel = $row["linklabel"]; $menuDisplay .= '<a href="index.php?pid=' . $pid . '">' . $linklabel . '</a><br />'; } echo $menuDisplay; ?> $list doesnt return anything, the previous method i used in the class was to make a list and an array and put the contents of the query in an array like: Code: [Select] list($list[] = $row); or something i cant quite remember i saw a youtube video tutorial and it worked for them, but it wasnt for me. If anyone knows how i can return various rows from a database it would be appreciated Thanks. Hi Everyone, Well I have a bit of a problem... I have created a search page that I would like to return results from my MySQL database. However for some reason I can not get my page to display the results. Instead I am getting an error page. Below is the code I am using: In addition to this, should I wish for a user to be able to edit the returned results by clicking a link, how would I do that? <?php session_start(); ?> <link rel="stylesheet" type="text/css" href="css/layout.css"/> <html> <?php $record = $_POST['record']; echo "<p>Search results for: $record<br><BR>"; $host = "localhost"; $login_name = "root"; $password = "P@ssword"; //Connecting to MYSQL MySQL_connect("$host","$login_name","$password"); //Select the database we want to use mysql_select_db("schedules_2010") or die("Could not find database"); $result = mysql_query("SELECT * FROM schedule_september_2010 WHERE champ LIKE '%$record%' ") or die(mysql_error()); // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row echo "<br><p>Your Schedule<BR></p><br>"; echo "<table border=1>\n"; echo "<tr> <td bgcolor=#444444 align=center><p><b>Champ</p></td> <td bgcolor=#444444 align=center><p><b>Date</p></td> <td bgcolor=#444444 align=center><p><b>Start Time</p></td> <td bgcolor=#444444 align=center><p><b>End Time</p></td> <td bgcolor=#444444 align=center><p><b>Department</p></td> <td bgcolor=#444444 align=center><p><b>First Break</p></td> <td bgcolor=#444444 align=center><p><b>Second Break</p></td> <td bgcolor=#444444 align=center><p><b>Login ID</p></td> </tr>\n"; do { printf("<tr> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> <td><p>%s</p></td> </tr>\n" , $row["champ"] , $row["date_time"] , $row["start_time"] , $row["end_time"] , $row["department"] , $row["first_break"] , $row["second_break"] , $row["login_id"] ); } while ($row = mysql_fetch_array($result)); echo "</table>\n"; } else { echo "$champ No Records Found"; } mysql_free_result($result); mysql_close($con); ?> </html> Hi People. Does anyone have any idea why this form is showing as a blank page on my site? Can you see what I've missed? 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=iso-8859-1" /> <title>Stranded Flyer</title> </head> <body> <?php $host = 'localhost'; $usr = "the_user"; $password = 'thepassword'; $db_name = 'thedbname'; //connect to database mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error()); mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error()); $surname = mysql_real_escape_string($_POST['surname']); $firstname = mysql_real_escape_string($_POST['firstname']); $phone1 = mysql_real_escape_string($_POST['phone1']); $phone2 = mysql_real_escape_string($_POST['phone2']); $location = mysql_real_escape_string($_POST['location']); $qualifications = mysql_real_escape_string($_POST['qualifications']); $expertise = mysql_real_escape_string($_POST['expertise']); $assistance = mysql_real_escape_string($_POST['assistance']); $languages = mysql_real_escape_string($_POST['languages']); $e-mail = mysql_real_escape_string($_POST['e-mail']); $consent = mysql_real_escape_string($_POST['consent']); $published = mysql_real_escape_string($_POST['published']); $comments = mysql_real_escape_string($_POST['comments']); $other_info = mysql_real_escape_string($_POST['other_info']); $errorstring = ""; // default value of errorstring function makeSafe($value) { if (get_magic_quotes_gpc()) { $value = stripslashes($value); } $value = mysql_real_escape_string($value); return $value; } if(isset($_POST['submit'])) { // Validate all the code inputs // Captcha Validation require_once('recaptchalib.php'); $privatekey = "6Ld2xscSAAAAADwh3mCFkTObSHLAEKUAcU3ocpSv"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly $errorstring = $errorstring. "Invalid CAPTCHA, please try again"; } else { if ($surname =="") $errorstring = $errorstring. "Surname<br>"; if ($phone1 =="") $errorstring = $errorstring. "phone1<br>"; if ($phone2 =="") $errorstring = $errorstring. "phone2<br>"; if ($location =="") $errorstring = $errorstring. "location<br>"; if ($qualifications =="") $errorstring = $errorstring. "qualifications<br>"; if ($assistance =="") $errorstring = $errorstring. "assistance<br>"; if ($languages =="") $errorstring = $errorstring. "languages<br>"; if ($e-mail =="") $errorstring = $errorstring. "e-mail<br>"; if ($consent =="") $errorstring = $errorstring. "consent<br>"; if ($published =="") $errorstring = $errorstring. "published<br>"; if ($comments =="") $errorstring = $errorstring. "comments<br>"; if ($other_info =="") $errorstring = $errorstring. "other info<br>"; // does the errorstring = "nothing"? } // Figure out which error message to show i.e. field validation or CAPTCHA if ($errorstring !="") if (strstr($errorstring,"CAPTCHA")) echo $errorstring; else echo "You have not put anything in the following fields: <br><br> $errorstring"; //echo "If you have nothing to put in the box please type the word \"None\" or \"N\/A\""; //die ("Please try again, ensuring that you fill out all the fields!"); else { //echo "Your data has been saved"; $insert_query = "INSERT INTO HelperFormData (surname, firstname,phone1, phone2, location, qualifications, expertise, assistance, languages, e-mail, consent, published, comments, other_info,) VALUES ('$surname', '$firstname', '$phone1','$phone2', '$location', '$qualifications', '$expertise', '$assistance', '$languages', '$e-mail', '$consent', '$published', '$comments', '$other_info')"; $insert_action = mysql_query($insert_query) or die ('Error During Insert :<br>'.mysql_error().'<br><br>Error occured running the following code :<br>'.$insert_query); $id = mysql_insert_id(); echo "Thank you, Your details have been submitted."; //include "resultcard.php"; // Output what the form looks like // End of how the form looks } } if(!isset($_POST['submit']) || (isset($_POST['submit']) && !empty($errorstring))) { ?> <form name = "form1" method ="post" action=""> <table width="700" border="0" cellspacing="5" cellpadding="5" bgcolor = "#dddddd"> <caption> Submit Your Details </caption> <tr> <td width = "50"> </td> <td width = "240"> </td> <td width = "250"> </td> <td width = "160"><b>Example Input</b></td> </tr> <tr> <td> </td> <td>Surname</td> <td><input type='text' name='surname' size = '40' maxlength='30' value = '<?php echo $surname; ?>'></td> <td>Smith</td> </tr> <tr> <td> </td> <td>First Name</td> <td><input type='text' name='firstname' size = '40' maxlength='30' value = '<?php echo $firstname; ?>'></td> <td>Bill</td> </tr> <tr> <td> </td> <td>Phone 1</td> <td><input type='text' name='phone1' size = '40' maxlength='30' value = '<?php echo $phone1; ?>'></td> <td>07777 777777</td> </tr> <tr> <td> </td> <td>Phone 2</td> <td><input type='text' name='phone2' size = '40' maxlength= '30'value = '<?php echo $phone2; ?>'></td> <td>0118 123 4567</td> </tr> <tr> <td> </td> <td>Location</td> <td><input type='text' name='location' size = '40' maxlength='40'value = '<?php echo $location; ?>'></td> <td>52.289071,-1.952004</td> </tr> <tr> <td> </td> <td>Qualifications</td> <td><input type='text' name='qualifications' size = '40' maxlength='30' value = '<?php echo $qualifications; ?>'></td> <td>Electrician</td> </tr> <tr> <td> </td> <td>Expertise</td> <td><input type='text' name='qualifications' size = '40' maxlength='30' value = '<?php echo $expertise; ?>'></td> <td>Flexwings</td> </tr> <tr> <td> </td> <td>Assistance Offered</td> <td><input type='text' name='assistance' size = '40' maxlength='50' value = '<?php echo $assistance; ?>' /></td> <td>Trailer and Tow Car</td> </tr> <tr> <td> </td> <td>Language Skills</td> <td><input type='text' name='published' size = '40' maxlength='50' value = '<?php echo $language; ?>' /></td> <td><p>English / Spanish</p></td> </tr> <tr> <td> </td> <td>E-Mail</td> <td><input type='text' name='comments' size = '40' maxlength='50' value = '<?php echo $e-mail; ?>' /></td> <td><p>example@mail.net</p></td> </tr> <tr> <td> </td> <td>Consent</td> <td> <select name = "surface"> <option value = "Yes" <?php if ($_POST['consent'] == 'Yes') { echo 'selected="selected"'; } ?>>Yes</option> <option value = "No" <?php if ($_POST['consent'] == 'No') { echo 'selected="selected"'; } ?>>No</option> </select> </td> <td>Yes</td> </tr> <tr> <td> </td> <td>Published</td> <td> <select name = "food"> <option value = "Yes" <?php if ($_POST['published'] == 'Yes') { echo 'selected="selected"'; } ?>>Yes</option> <option value = "No" <?php if ($_POST['published'] == 'No') { echo 'selected="selected"'; } ?>>No</option> </select> </td> <td>Yes</td> </tr> <tr> <td> </td> <td>Comments</td> <td><textarea name= "remarks" input type = 'text' rows = "5" cols = "29" /><?php echo $remarks; ?></textarea></td> <td>As much info as possible 500 characters max</td> </tr> <tr> <td> </td> <td>Other Info</td> <td><textarea name= "warnings" input="input" type = 'text' rows = "5" cols = "29" /><?php echo $warnings; ?></textarea></td> <td>As much info as possible 500 characters max</td> </tr> <tr> <td> </td> <td><input type='submit' name='submit' value='Submit Your Info' /></td> <td colspan="2"> <? require_once('recaptchalib.php'); $publickey = "6Ld2xscSAAAAAH3_KiJoRLR4sEWFFQR4yAr5F1xi"; // you got this from the signup page echo recaptcha_get_html($publickey);?></td> </tr> </table> </form> </body> </html> <?php } ?> Ok I dont understand why my php form keeps sending me blank emails. Because I have a checker with java script. Did I do something wrong in my coding with the php forms or is it just the javascript on the sites problem? Here is the php form code: Code: [Select] <script language="JavaScript"> function checkForm() { var cname, caddress, cphone, cemail, ccontact; with(window.document.msgform) { cname = name; caddress = address; cphone = phone; cemail = email; ccontact = contact; } if(trim(cname.value) == '') { alert('Please enter your name'); cname.focus(); return false; } else if(trim(caddress.value) == '') { alert('Please enter your address'); cemail.focus(); return false; } else if(trim(cphone.value) == '') { alert('Please enter your phone number'); cemail.focus(); return false; } else if(!isEmail(trim(cemail.value))) { alert('Email address is not valid'); cemail.focus(); return false; } else if(trim(ccontact.value) == '') { alert('Please enter your contact person'); cemail.focus(); return false; } else { cname.value = trim(cname.value); caddress.value = trim(caddress.value); cphone.value = trim(cphone.value); cemail.value = trim(cemail.value); ccontact.value = trim(ccontact.value); return true; } } /* Strip whitespace from the beginning and end of a string Input : a string */ function trim(str) { return str.replace(/^\s+|\s+$/g,''); } /* Check if a string is in valid email format. Returns true if valid, false otherwise. */ function isEmail(str) { var regex = /^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i; //regex = /^[-_.abcdefghijklmnopqrstuvwxyz0123456789]+@(([-abcdefghijklmnopqrstuvwxyz0123456789]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i; return regex.test(str); } </script> <form name="msgform" action="thankyou.php" method="post" > <table width="95%" border="0" cellspacing="1" class="tablestyle" cellpadding="1" align="center"> <tr><td>Name:</td> <td><input type="text" name="name" size="27"> </td> </tr> <tr><td>Address:</td> <td><input type="text" name="address" size="27"> </td> </tr> <tr> <td>Phone: </td> <td> <input type="text" name="phone" size="27"> </td> </tr> <tr> <td>Email: </td> <td> <input type="text" name="email" size="27"> </td> </tr> <tr> <td>Contact Person: </td> <td> <input type="text" name="contact" size="27"> </td> </tr> <tr> <td valign=top>I would like to participate at the: </td> <td valign=top> <input type="radio" name="level" value="5000">Platinum<BR> <input type="radio" name="level" value="2500">Gold<BR> <input type="radio" name="level" value="1000">Silver<br> <input type="radio" name="level" value="500">Bronze <br><br> </td> </tr> <tr> <td> <input type="radio" name="level" value="1250"option5<br> </td> </tr> <tr><td colspan="2"><input type="submit" value="submit" name="submit" onClick="return checkForm();"><input type="reset" value="Reset"></td></tr> </table></form> Here is the php process code: Code: [Select] <?php $con = mysql_connect(""); //Replace with your actual MySQL DB Username and Password if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("sponsorship", $con); //Replace with your MySQL DB Name $name=mysql_real_escape_string($_POST['name']); //This value has to be the same as in the HTML form file $address=mysql_real_escape_string($_POST['address']); //This value has to be the same as in the HTML form file $phone=mysql_real_escape_string($_POST['phone']); //This value has to be the same as in the HTML form file $email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file $contact=mysql_real_escape_string($_POST['contact']); //This value has to be the same as in the HTML form file $level=mysql_real_escape_string($_POST['level']); //This value has to be the same as in the HTML form file $sql="INSERT INTO sponsorship (name,address,phone,email,contact,level) VALUES ('$name','$address','$phone','$email','$contact','$level')"; /*form_data is the name of the MySQL table where the form data will be saved. name and email are the respective table fields*/ if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } ?> <?php $name = $_POST["name"]; $address = $_POST["address"]; $phone = $_POST["phone"]; $email = $_POST["email"]; $contact = $_POST["contact"]; $level = $_POST["level"]; echo "Name: ". $name . " <br />"; echo "Address: ". $address . " <br />"; echo "Phone: ". $phone . " <br />"; echo "Email: ". $email . " <br />"; echo "Contact: ". $contact . " <br />"; echo "Level: ". $level . " and up. <br />"; $recipient = "my email"; $subject = " subject "; $message = " '. name: .'$name '. contact: .' $contact '. address: .' $address '. phone: .' $phone '. email: .' $email '. level: .' $level "; mail($recipient, $subject, $message); ?> i keep thinking its the javascript fault but i have a navigation menu which is made from javascript and it works fine. So it leaves me to think its something i did wrong with the form or php? Can someone help me please? Thank you! |