PHP - Required Field
Trying to make the email field in my form mandatory. Im new to php, more used to javascript but from everything i have read php is more universal. Here is my code, any help would be great.
Code: [Select] <?php $emailsubject = 'Golf Registration'; $webMaster = 'dustin@duncantek.com'; $namea = $_POST['namea']; $nameb = $_POST['nameb']; $namec = $_POST['namec']; $named = $_POST['named']; $total = $_POST['total']; $sponsor = $_POST['sponsor']; $email = $_POST['email']; $comments = $_POST['comments']; $body = <<<EOD <br><hr><br> Golfer1: = $namea <br> Golfer2: = $nameb <br> Golfer3: = $namec <br> Golfer4: = $named <br> Total Owed: = $total <br> Sponsorship Name: = $sponsor <br> Comments: = $comments<br> EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailsubject, $body, $headers); $theResults = <<<EOD <!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>Thanks For Registering</title> <link href="golf-website.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="border"> <div class="name">Thanks For Registering!</div> <div id="links_bg"> <div class="toplinks"><a href="default.html">Homepage</a></div> <div class="toplinks"><a href="file:///C|/Users/Dustin/Desktop/Templates/Golf-Website/index.html">About Us</a></div> <div class="toplinks"><a href="file:///C|/Users/Dustin/Desktop/Templates/Golf-Website/index.html">Donations</a></div> <div class="toplinks"><a href="tourneyinfo.html">Events</a></div> <div class="toplinks"><a href="file:///C|/Users/Dustin/Desktop/Templates/Golf-Website/index.html">Contact us</a></div> </div> <div class="gap"></div> </div> </div> <div id="heading-bg"> <div align="left">Registration Complete</div> </div> <div id="main"> <p>Thank you for taking the time to register, we will email you back shortly to confirm registration along with an invoice via paypal. This is strictly for your convenience, we will also accept payment at the course on the day of the tournament. Thanks Again!</p> </div> <div id="bottom"> <div class="bottomlink"><a href="default.html">Home</a></div> <div class="sap">|</div> <div class="bottomlink"><a href="aboutus.html">About Us</a></div> <div class="sap">|</div> <div class="bottomlink"><a href="file:///C|/Users/Dustin/Desktop/Templates/Golf-Website/index.html">Donations</a></div> <div class="sap">|</div> <div class="bottomlink"><a href="tourneyinfo.html">Events</a></div> <div class="sap">|</div> <div class="bottomlink"><a href="file:///C|/Users/Dustin/Desktop/Templates/Golf-Website/index.html">Contact Us</a></div> </div> <center><div class="quicklinks"></div> </div> </body> </html> EOD; echo "$theResults"; ?> <!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>Tournament Info</title> <link href="golf-website.css" rel="stylesheet" type="text/css" /> </head> <body> <td width="104"><label for="namea"> <div align="right">Golfer #1:</div> </label> </td> <td width="387"><div align="left"> <input name="namea" type="text" id="namea" size="35" maxlength="80" /> </div></td> </tr> <tr> <td><label for="name2"> <div align="right">Golfer #2:</div> </label> </td> <td><div align="left"> <input name="nameb" type="text" id="nameb" size="35" maxlength="80" /> </div></td> </tr> <tr> <td><label for="namec"> <div align="right">Golfer #3:</div> </label> </td> <td><div align="left"> <input name="namec" type="text" id="namec" size="35" maxlength="80" /> </div></td> </tr> <tr> <td><label for="named"> <div align="right">Golfer #4:</div> </label> </td> <td><div align="left"> <input name="named" type="text" id="named" size="35" maxlength="80" /> </div></td> </tr> <tr> <td><div align="right"></div></td> <td><div align="left">The option to sponsor a hole is also available, the price per hole is $200.00, please enter in the box below what you would like the sponsorship to be if any.</div></td> </tr> <tr> <td><div align="right"> <label for="total">Total:</label> </div></td> <td><div align="left"> <input name="total" type="text" id="total" size="35" maxlength="80" /> </div></td> </tr> <tr> <td><div align="right"> <label for="sponsor">Sponsorship:</label> </div></td> <td><div align="left"> <input name="sponsor" type="text" id="sponsor" size="35" maxlength="80" /> </div></td> </tr> <tr> <td><div align="right"> <label for="email">Email: </label> </div></td> <td><div align="left"> <input name="email" type="text" id="email" size="35" maxlength="80" /> </div></td> </tr> <tr> <td><label for="comments">Additional Comments:</label></td> <td><textarea name="comments" cols="35" rows="6" id="comments"></textarea></td> </tr> </table> <p> </p> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <p> <input type="submit" name="send" id="send" value="Submit" /> <input type="reset" name="reset" id="reset" value="Reset" /> </p> </blockquote> < </body> </html> MOD EDIT: code tags added. Similar TutorialsOk well i've been trying to figure this out for a while now and really havent been able to find out how to implement this, I currently have it so that my email form requires you enter your name and email but you don't have to enter your phone number, I need to change it soo that it requires you enter a valid phone number aswell. Heres my code below, my boss is really getting on my case over this and I'm not a .php developered so any help would be really appretiated. The codes below I also attached it in a file for those who want it. Code: [Select] <?php $my_email = "email@emailhere.co.uk"; $continue = "/"; $errors = array(); if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}} function recursive_array_check_header($element_value) { global $set; if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}} else { foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);} } } recursive_array_check_header($_REQUEST); if($set){$errors[] = "You cannot send an email header";} unset($set); if(isset($_REQUEST['email']) && !empty($_REQUEST['email'])) { if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";} $_REQUEST['email'] = trim($_REQUEST['email']); if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}} } if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";} function recursive_array_check_blank($element_value) { global $set; if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}} else { foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);} } } recursive_array_check_blank($_REQUEST); if(!$set){$errors[] = "You cannot send a blank form";} unset($set); if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;} if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");} function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");} $message = build_message($_REQUEST); $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL.""; $message = stripslashes($message); $subject = "Website Query"; $headers = "From: " . $_REQUEST['email']; mail($my_email,$subject,$message,$headers); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Tracey Bell - Contact Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#ffffff" text="#000000"> <div> <center> <b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b> <br>Your message has been sent <p><a href="<?php print $continue; ?>">Click here to continue</a></p> </center> </div> </body> </html> I am trying to add another "required field" to my PHP form, but I'm not sure what I'm doing wrong. The form and "required fields" work fine, but I am now trying to make the "Select skill level which is an "input type="radio" as a required field, but it is not working. As you can see below, I just tried adding the new "required" field the same way as the other 4 were set up, but it is not working (I think I have to do something different because the new "required field" is a "radio" type and the rest are "text"). The relevant parts of the code are below. Any assistance would be appreciated Code: [Select] <script type="text/JavaScript"> function verify() { var Skill = document.indiv_reg.skill.value; var Fname = document.indiv_reg.name.value; var Hphn = document.indiv_reg.home_num.value; var Email = document.indiv_reg.email.value; var Tname = document.indiv_reg.tname.value; if ((Fname =="") || (Skill =="") || (Hphn =="") || (Email =="") || (Tname =="")) { alert('Please Fill Out ALL Required Fields'); } else { document.indiv_reg.submit(); } } </script> <?php $url = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6Y76L7TX6FVRW"; $sport = $_GET['sport']; $league = $_GET['league']; $visitor = $_GET['name']; $skill = $_GET['skill']; $tname = $_GET['tname']; $tcap = $_GET['tcap']; $homephn = $_GET['home_num']; $cellphn = $_GET['cell_num']; <?php * Denotes a Required Field<br /> <br /> <form name="indiv_reg" method="GET" action="tourney_mailRedirect.php"> Sport:<br /> <input type="text" name="sport" value="'.$sport.'" readonly="readonly" /><br /> <br /> Tournament:<br /> <input type="text" size="90" name="league" value="'.$league.'" readonly="readonly" /><br /> <br /> * Please select preferred skill level:<br /> <input type="radio" name="skill" value="recreational" /> Recreational<br /> <input type="radio" name="skill" value="competitive" /> Competitive<br /> <br /> * Name:<br /> <input type="text" name="name" /><br /> <br /> * Team Name:<br /> <input type="text" name="tname" /><br /> <br /> Team Captain:<br /> <input type="text" name="tcap" /><br /> <br /> * Home Phone:<br /> <input type="text" name="home_num" /><br /> <br /> Cell Phone:<br /> <input type="text" name="cell_num" /><br /> <br /> * Email:<br /> <input type="text" name="email" /><br /> <br /> ?> This is my first real jump into PHP, I created a small script a few years ago but have not touched it since (or any other programming for that matter), so I'm not sure how to start this. I need a script that I can run once a day through cron and take the date from one table/filed and insert it into a different table/field, converting the human readable date to a Unix date. Table Name: Ads Field: endtime_value (human readable date) to Table Name: Node Field: auto_expire (Converted to Unix time) Both use a field named "nid" as the key field, so the fields should match each nid field from one table to the next. Following a tutorial I have been able to insert into a field certain data, but I don't know how to do it so the nid's match and how to convert the human readable date to Unix time. Thanks in advance!. Hi: I'm going crazy trying to do the following: I'm making a job registration process where the user registers on one php page to the website, must acknowlege and email receipt using an activate php page, then is directed to upload their C.V. (resume) based on the email address they enter in the active page output. I then run an upload page to store the resume in teh MySQL db based on the users email address in the same record. If I isolate the process of the user registering to the db, it works perfectly. If I isolate the file upload process into the db, it works perfect. I simply cannot upload teh file to the existing record based on teh email form field matching the user_email field in the db. With the processes together, teh user is activated, but teh file is not uploaded. Maybe I've simply been at this too long today, but am compeled to get through it by end day. If anyone can help sugest a better way or help me fix this, I will soo greatly appreciate it. My code is as follows for the 2 pages. ---------activate.php------- <?php session_start(); include ('reg_dbc.php'); if (!isset($_GET['usr']) && !isset($_GET['code']) ) { $msg = "ERROR: The code does not match.."; exit(); } $rsCode = mysql_query("SELECT activation_code from subscribers where user_email='$_GET[usr]'") or die(mysql_error()); list($acode) = mysql_fetch_array($rsCode); if ($_GET['code'] == $acode) { mysql_query("update subscribers set user_activated=1 where user_email='$_GET[usr]'") or die(mysql_error()); echo "<h3><center>Thank You! This is step 2 of 3. </h3>Your email is confirmed. Please upload your C.V. now to complete step 3.</center>"; } else { echo "ERROR: Incorrect activation code... not valid"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Job application activation</title> </head> <body> <center> <br/><br/><br/> <p align="center"> <form name="form1" method="post" action="upload.php" style="padding:5px;"> <p>Re-enter you Email : <input name="email" type="text" id="email"/></p></form> <form enctype="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="4000000"> Upload your C.V.: <input name="userfile" type="file" id="userfile"> <input name="upload" type="submit" id="upload" value="Upload your C.V."/></form> </p> </center> </body> </html> --------upload.php---------- <?php session_start(); if (!isset($_GET['usr']) && !isset($_GET['code']) ) { $msg = "ERROR: The code does not match.."; exit(); } if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $email = $_POST['email']['user_email']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } include 'reg_dbc.php'; $query = "UPDATE subscribers WHERE $email = user_email (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); mysql_close($dbname); } ?> <center> <br/> <br/> <br/> <br/> Thank you for uploading your <?php echo "$fileName"; ?> file, completing your registration, and providing us your C.V. for this position. <br/> <br/> <br/> We will contact you if your canditature qualifies. </center> (Another quite newbie...) I have already an online booking form. The Form works fine now and I would like to add on one more issue, but the code ignores what I want to check. I have 4 fields: arrival, departure, no. of persons and comments to check. Scenario 1: All field mentioned above are emtpty: Workes fine and message appears: "You have not provided any booking details". Scenario 2: If arrival (date_start) and departure (date_end) is entered, there should be at least an entry either in the field "comment", or in the field "pax". If not, there should be a message: "You have not provided sufficient booking details". INSTEAD: The booking request is sent, which should not be the case. The code is currently: # all fields empty : arrival, departure, pax and comments - error if(empty($data_start) && empty($data_end) && empty($pax)&& empty($comment)){ exit("You have not specified any booking details to submit to us. <br>Please use your browser to go back to the form. <br>If you experience problems with this Form, please e-mail us"); exit; } #If arrival and departure date is entered, there should be at least an entry either in the field "comment", or in the field "pax". if(!isset($data_start) && !isset($data_end) && empty($pax) && empty($comment)){ exit("You have not provided sufficient booking details. <br>Please use your browser to go back to the form. <br>If you experience problems with this Form, please e-mail us"); exit; } The form can be tested at http://www.phuket-beachvillas.com/contact-own/contact-it.php Can someone please check and tell me what's wrong with the code ? Thanks to anyone for any hint. Code: [Select] $new_array2=array_diff($my_array,$itemIds); $updatedb = mysql_query("UPDATE content_type_ads SET field_expire_value = '666' WHERE $new_array2 = field_item_id_value"); "$new_array2" has only 12 digit numbers for each item in the array, and I want to match them to the "field_item_id_value" field in the table, updating the "field_expire_value" field for the record where they match. I know I am close because the UPDATE code works before I add the WHERE statement (it of course adds '666' to EVERY field, but for a noobie it's a start!). Hi, I'm developing an app using flash AS2 as the front end via PHP and a mySQL database at the backend on my server. what i'm looking to do is update/insert into a table called 'cards' and at the same time update/insert into another table called 'jingle'. There is a field called 'cardID' in jingle that should be the same as the ID number created in 'cards' thus creating a link between entries in the different tables that can be called up as i choose. hope i've been clear i just wouldn't know where to start any help would be appreciated. MySQL client version: 5.0.91 PHPmyAdmin Version information: 3.2.4 thanks in advance How should it look if I want to make a query where a field value should be lower than another field? Code: [Select] ....WHERE total_points<max_points"); Hi Friends, I am trying to do an API with oracle database. The JSON request from 3rd party will look like below. { "contact_id": "1", "serial_no": "100", "name": "baby", "inv_date": "2018-06-27", "due_date": "2018-06-27", "currency": "KD", "subtotal": "143", "tax_total": "13", "shipment_data": [ { "serial_no": "33", "master_no": "55", "house_no": "77", "cost_revenue_items": [ { "charge_ref": "rr", "currency": "INR", "quantity": "2", "selling_rate": "45", "exchange_rate": "7", "taxes": [ { "serial_no": "1", "ref": "INR", "voiding_remarks": "oo" },{ "serial_no": "2", "ref": "KWD", "voiding_remarks": "asd" } ] } ] } ] }
how to handle request for JSON in which master is updated (PUT) and child record is (Either INSERTED, UPDATED or DELETED) ? One of my virtual hosts contained php_value upload_max_filesize 8M which resulted in error when running as php-fpm. Also, looks like .htaccess files are no longer used. Any other gotcha's??? Reading up on it, looks like I want to move all .htaccess instructions to a https://www.php.net/manual/en/configuration.file.per-user.php file. Should be straight forward enough. Looking at https://www.php.net/manual/en/configuration.changes.php, looks like I should scan /etc/httpd/* as well as any virtual sites defined elsewhere for "php_" and move these requirements elsewhere. Will this also have to be a per directory .user.ini file? Reason I ask is I always thought it was better performance to when possible use apache's conf file than a .htaccess file. I have a login page that after logging in it sets a session Code: [Select] $_SESSION['user_info'] = $_POST['username']; and takes me to a start page (and checks for the session) which all works wonderfully. The problem is that no matter what link is clicked on that page it takes me to the login page again after checking to see if that same session is set Code: [Select] session_start(); if(!isset($_SESSION['user_info'])){ header("Location: http://website.com/folder/log_in.php"); } After logging in a second time every link on that same start page works wonderfully. If it works the second time why not the first? I am trying to update task based progress updates. I've got a very simple database that needs to be updated with:
Database name: progress
1. ID (auto increment)
2. admin (name of the project manager)
3. adminid (ID of the project manager in the project manager db)
4. member (name of the member of the project in the members db)
4. project (particular project being updated)
5. status (progress of the project as a number between 10 and 90)
6. timestamp
I have the following php script update insert a new line into my progress table:
if (!empty($_POST['progress'])) { if(Input::exists()) { if(Token::check(Input::get('token'))) { $adminprogress = Input::get('admin'); $adminidprogress = Input::get('adminid'); $memberprogress = Input::get('member'); $projectprogress = Input::get('project'); $statusprogress = Input::get('status'); $timestamp = date('Y-m-d H:i:s'); $progressupdate = DB::getInstance()->insert(progress, array( 'admin' => $adminprogress, 'adminid' => $adminidprogress, 'member' => $memberprogress, 'project' => $projectprogress, 'status' => $statusprogress, 'timestamp' => $timestamp )); Redirect::to('memberattire1.php'); } } }And I have the following code in the body of my page: <form method="post" action=""> <label> <select name="status"> <option value=choose>---Please Select---</option> <option value = "0">(10%) Bunker Registered</option> <option value = "10">(20%) First discussions held</option> <option value = "20">(30%) Initial research undertaken</option> <option value = "30">(40%) Ideas shared</option> <option value = "40">(50%) Enquiries made</option> <option value = "50">(60%) Results of enquiries shared</option> <option value = "60">(70%) Preferences shared</option> <option value = "70">(80%) Decisions made</option> <option value = "80">(90%) Decisions being executed</option> <option value = "90">(100%) Project Completed</option> </select> </label> <br><br> <input type="hidden" name="member" value="<?php echo $membername; ?>"> <input type="hidden" name="admin" value="<?php echo $admin; ?>"> <input type="hidden" name="adminid" value="<?php echo $adminid; ?>"> <input type="hidden" name="project" value="attire1"> <input type="hidden" name="token" value="<?php if(isset($token)) { echo $token; } else { echo $token = Token::generate(); } ?>" > <input type="submit" value="Submit Update" name="progress"> </form>I know my $membername, $admin and $adminid are ok because I can simply echo them out to confirm them, so there is something silly in my coding that I've overlooked. Can someone with a fresh pair of eyes see a typo or missed semi-colon or whatnot? Many thanks for any help. I have a html/php i am creating but getting the following error:
[10-May-2019 09:42:13 UTC] PHP Fatal error: Uncaught Error: Call to a member function prepare() on null in C:\inetpub\wwwroot\SupportDesk\php\Add_New_Engineer.php:88
<?php $server = htmlentities($_SERVER['PHP_SELF']); if (isset($_POST['submit'])) { $result = create_eng(); } ?> <!DOCTYPE html> <html lang="en"> <head> <title>Add A New Engineer | DDS Dashboard</title> <meta charset="utf-8" /> <link rel="icon" type="image/png" href="../images/favicon-16x16.png"/> </head> <body> <?php include('nav.php'); include('ConnectionDB.php'); ?> <div class="jumbotron"> <div class="container"> <h1><br><img src="../images/clipboard-customer.png"/> Add New Engineer:</br></h1> </div> </div> <form class="form-horizontal" role="form" id="add_eng" action="<?php $server ?>" method = "post"> <div class="form-group"> <!--<?php //display_msg($msg);?>--> <label for="EngineerName" class="col-sm-2 control-label">Engineer Name:</label> <div class="col-sm-6"> <input type="text" class="form-control" id="EngName" name="EngineersName" placeholder="Enter Engineer's Name"></input> <small class="form-text text-muted"> Enter the new engineer's name above to enter them into the database. </small> </div> <input name="submit" type="submit" value="Create Engineer" class="btn btn-primary default"></input> <input name="reset" type="Reset" value="Reset Form" class="btn btn-primary default"></input> </div> </form> <br><br> </body> </html> <?php $sql = "Select * from [Engineers] where [Engineer] not like '%\_%' Escape '\' order by [Engineer] asc"; $stmt = $conn->prepare($sql); $stmt->execute(); $results=$stmt->fetchAll(PDO::FETCH_ASSOC); ?> <div class="containerenglist"> <div class="col-sm-5"> <table id="alleng" class="table table-bordered"> <tr> <th>Active Engineer's Names:</th> </tr> <?php foreach ($results as $row) { echo "<tr><td>"; echo $row['Engineer']; echo "</td>"; echo "</tr>"; } ?> </table> </div> </div> </body> </html> <?php Function create_eng(){ global $msgID; global $msg, $conn; include('ConnectionDB.php'); $conn = null; $msgID = 0; //Get POST from submit $eng_name = $_POST['EngineersName']; //SQL Query $sql_count = "select count(*) as num from [Engineers] where [Engineer] = :eng_name"; //Query SQL Statement //echo $eng_name; $stmt = $conn->prepare($sql_count); $stmt->bindValue(':eng_name', $eng_name); //Execute SQL Statement $stmt->execute(); $results=$stmt->fetchAll(PDO::FETCH_ASSOC); If($results['num'] > 0){ echo $msg = "Engineer $eng_name exist's in the database"; $msgID = 1; }else{ $sql_insert = "insert into [Engineers](Engineer) values '$eng_name'"; //Prepare SQL Statement $stmt = $conn->Prepare($sql_insert); //Execute SQL Statement $stmt->execute(); $results=$stmt->fetchAll(PDO::FETCH_ASSOC); echo $msg = "Engineer $eng_name added to the database"; $msgID = 2; } } ?> Everything works correctly until i try submitting a name to the DB the line that is being pulled is $stmt = $conn->prepare($sql_count);
How can I make it so that if file_get_contents cannot find the file else <?php $file = file_get_contents("http://www.example.com/lol.txt"); if ( $file == true ) { } else { } Hi Buddy I'm new to Php and downloaded shopping cart for www.phpwebcommerce.com/download/plaincart.zip With this code, i'm unable to update the shopping cart. On clicking the update button, it goes to previous page. But in demo version the update is working properly. Kindly help. Thanks Sakhsen Okay, so below I have posted my code, the problem I am having is not knowing how PDO works that well. So what I have attempted to do here is use SQL to check if the user and password are correct, but I'm not sure how to carry on. I realize I have to determine if the database found the matching password and/or username but I have no idea how, any help will be much appreciated. <html> <head> <title>Database login</title> <?php if (isset($_POST['submit'])) { print_r($_POST); $password = md5($_POST['password']); echo'<p>'.$password.'</p>'; $username = ($_POST['username']); echo'<p>'.$username.'</p>'; } ?> </head> <body> <?php $db = new PDO('sqlite:login.sqlite'); $login = 'SELECT * FROM login WHERE userid="'.$username.'" AND password="'.$password.'";'; echo'<p>'.$login.'</p>'; $attempt = $db->query($login); ?> <form method="post" action="Db_login.php"> <p>Username:<br /><input type="text" name="username" /> </p> <p>Password:<br /><input type="password" name="password" /></p> <p><input type="submit" name="submit" value="Log In!" /></p> </body> </html> Hi All, I am new to PHP and HTML and I am trying to write an interface to MySQL 5.1 data base on Ubuntu 10.04LTS using PHP. My database has following tables 1) parts---> Part_no, Part_name--->PK is Part_no 2) operation---> Part_no,op_id--->PK is op_id, FK is Part_no 3)tool_list---->tl_id,op_id, tool---->PK is tl_id, FK is op_id 4)tool---->tool_part_no, tool_desc---->PK is tool_part_no I have many rows of data in 'tool' table. I want to referance/add these tools in to 'tool_list' table. these 'tool_list's are specific to a operatiom which once again is specific to a part. So Part_no--->op_id--->tool_list---->tool I have created 'one.php' which will aske the user for part no. This is a list which is populated from database. once the user selects the part_no and submits. it loads 'two.php' and lists operations specific to that part_no. Here once operation is selected and submited it calls 'three.php'. Here I need to add tools on to this selected operation. There can be as many as 20 different tool that can be added in to an operation. What i am looking to do is to list all tool in the 'tool' table as a list and add each tool in to the 'tool_list' table. once all tools are added press another button caled Exit which will take the user to Home page. The question is how do i accomplish this. 1) once a tool is selected it has to be added as a new row in to tool_list and the page need to be reloaded but has to remember the part_no, op_id for subsequent additions. 2) once all tools are added and exit is pressed it needs to goto home page. How do i accomplish these. Can a HTML page have two forms in it like on inside the other?. Or can this be accomplished with PHP only?. Thanks SKN Hi,
I am fairly new to PHP, I am tryin to put a code together that would see my incoming CLI as 44 and remove the 44 from it and add a 0 to it. I have managed to do this so far, now I am stuck, as any number thats not matching the length (10 digits ) or is not starting with 44 is also not forwarded to my database for query.
$input = ($cid); if(preg_match('/^(44|0)(\d{10})$/',$input,$matches)){ $phone = '0'.$matches[2]; }else die("Invalid Phone Number") ; What I would like is that any number starting with 441234567890 to become 01234567890, but should not involve 10 digits criteria. Any help would be appreciated. Hi, I need a preg_match for the following criteria: - no leading or trailing white space allowed - only alphanumeric characters and spaces are allowed (no full stops, commas apostrophe's, explanation marks, quotes, etc) - only one space allowed between each word (if there is more than one word) Thanks. |