PHP - Whats The Correct Syntax For This Form
<form action="blabla">
<input type="hidden" name="user" value="<?php echo $player;?>"> </form or <input type="hidden" name="user" value=<?php echo $player;?>> or are they both wrong ^_^ Similar Tutorials[text]I created two tables in a database called 'members' and 'blogs'. The blogs table uses the primary key of the members table (member_id), as a foreign key. The member_id is an auto incremented column in the members table and when I query and print out the rows of this table, the member_id values for the two members I created, turn out to be 1 and 2 as expected. Now when I use a subselect query in an insert statement, to input member_id values into the blogs table, and then query the rows of this table, both member_id values show up as 0. I will display both tables and the insert query for the blogs table below. Can anyone identify the problem? I'm convinced there is something about the subselect query that I'm not getting right. Ill also include the select query that displays the results of the blogs table just in case. [/text] Code: [Select] <?php $query = "CREATE TABLE members ( member_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , username VARCHAR( 50 ) NOT NULL UNIQUE, firstname VARCHAR( 50 ) NOT NULL , lastname VARCHAR( 50 ) NOT NULL , title VARCHAR(10), password VARCHAR( 50 ) NOT NULL , primary_email VARCHAR(100), secondary_email VARCHAR(100), register_date DATE, ip VARCHAR( 50 ) NOT NULL , UNIQUE (username) )"; ?> <?php $query = "CREATE TABLE blogs ( blog_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , member_id INT UNSIGNED, like_id INT UNSIGNED, title VARCHAR( 500 ) NOT NULL, entry VARCHAR( 2000 ) NOT NULL , blog_date DATE )"; ?> <?php $query = "INSERT INTO blogs ( member_id, title, entry, blog_date) VALUES ( 'SELECT member_id FROM members', '{$_POST['title']}', '{$_POST['entry']}', NOW())"; ?> <?php $query= 'SELECT * FROM blogs'; if($r = mysql_query ($query)) {//Run the query. //Retrieve and print every record. while ($row = mysql_fetch_array ($r)) { print " {$row['title']}" ; print " {$row['entry']}" ; print " {$row['blog_date']}" ; print " {$row['member_id']}" ; } } else {//Query didn't run. die (' Could not retrieve the data becasue: .mysql_error(). '); }//End of query IF. mysql_close(); //Close the database connection. ?> Any help is appreciated. This is what i am trying to achieve for my URL categories=$pagename &id=$myid this is what i am currently doing having some syntax errors please would appreciate if some one can resolve this the code is below echo "<a href=\"./categories.php?name=".$pagename.&id=$myid."\">\".$myid.\".\"</a>\"\n"; $sql = "select * from {$tab} WHERE {$tab}_id ='".$id."'"; This was the error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE '_id' ='11/'' at line 1 I just had a curiosity that was bugging me and I'm unsure of how to google for the answer, so I thought I'd put it up to the test here. I learned that when writing if statements in php the syntax is as follows: if(condition){ //Execute Code... }else{ //Execute Other Code... } However, I also see it written like so: if(condition) { //Execute Code... } else { //Execute Other Code... } I thought that the later style was used for Javascript and the earlier for php. While they both work, I was wondering, which is more correct? Thanks Everybody! E I have just discovered ternary conditionals and really like the time and space saving, they seem pretty simple and look neater than a bunch of if else statements crammed together. The thing I would like to know is what is the best or correct method of usng the following; $page = isset($_GET['page']) ? $_GET['page'] : '1'; or do I need the extra parentheses like below; $page = (isset($_GET['page'])) ? $_GET['page'] : '1'; I understand that if I used a second conditon I would need the extra parentheses e.g $page = (isset($_GET['page']) && is_numeric($_GET[page'])) ? $_GET['page'] : '1'; Thanks! $tab is a variable for my table's name <?php while($row=mysqli_fetch_assoc($result)){ ?> <?php echo $row['{$tab}_name']?> <?php error_reporting(E_ALL); session_start(); include ("dbcon.php"); echo "include working"; $username1= ($_POST['username']); echo ($_POST['username']); if ($_POST) { if (!empty($_POST['username']) && !empty($_POST['pass'])) { $sql = "SELECT * FROM `user` WHERE `username`='($_POST['username'])' LIMIT 1"; $result = mysqli_query($sql); if (mysqli_num_rows($result) > 0) { //user is valid, check pass $query = mysqli_fetch_assoc($result); $password = ($_POST['pass']); if ($password !== $query['pass']) { //invaid pass, input error code echo "Wrong Password"; exit; } else { //valid user and pass, login $_SESSION['login'] = TRUE; $_SESSION['username'] = $_POST['username']; //echo "logged in"; header('location: home.php'); exit(); } } else { //user is not in database, input error code echo " User Not Found"; } } else { //form submitted but no username/password, input error code echo "Fields are Blank"; } } else { //page loaded, but no form submitted, input error code echo "Submition Error"; } ?>I can't figure out the problem........ Any help is appreciated! What would be the correct way to use returned sql results as variables. I have tried the way in my script, but Im unsure of how I can echo just one of the $nt variables further on in my script. $code = $_GET['postcode']; $shortcode = substr($code,0,2); $query =mysql_query ("SELECT email FROM treesurgeons WHERE postcode like '%" . $shortcode . "%' ORDER BY companyName LIMIT 3"); echo mysql_error(); echo "<p>The email addresses you have requested are;</p>"; while($nt=mysql_fetch_row($query)){echo "$nt[0],$nt[1],$nt[2]<br>";} echo "<p>please use $nt[2] if you ever want to contact me</p>"; //this line doesnt work for me ?></body></html> is there is a way to assign variables such as; $nt[0] = $firstemail $nt[1] = $secondemail $nt[2] = $thirdemail this way I could use each of my sql values, just as I would any other variable? I currently have a small 2 page message board, the main file is named index.php and the other core.php - I would like to rename the main file with the form to chat.php, but when I do that, the script no longer posts messages, and goes to the website root. Can someone tell me whats wrong? Here is the form info from the current index.php (that i wish to rename chat.php) Code: [Select] <form action="./" method="post"> <p>name (25 chars max)<br> <input id="name" name="author" maxlength="20" size="25"></p> <p>message (150 chars max)<br> <input id="message" name="message" maxlength="150" size="45"></p> <p>what is <?php echo "$num1 &#43; $num2?" ?><br> <input id="captcha" name="captcha" maxlength="2" size="10"></p> <p><input id="submit" name="submit" type="submit" value="submit"> (ip addresses are recorded)</p> </form> and the 2nd file core.php's function that I think is acting up (here or with the form above?) function getPosts() { $author = isset($_POST['author']) ? $_POST['author'] : false; $message = isset($_POST['message']) ? $_POST['message'] : false; global $nameMax; global $messageMax; global $error; if ($author && $message && ($error==false) ) { if (strlen($author) <= $nameMax && strlen($message) <= $messageMax) { $this->inputPost($author, $message); header('Location: ./'); } Why when I rename index.php to chat.php is it not working and falling back to the website root when I submit? any help would be great! I am sure it is something simple, but I am new... hey, I'm working on a contact form. The form is being checked on correct values. If not completed correctly, the form shows again with a warning at the wrong or forgotten fields and the right fields remain fild in. After submitting with correct inputdata, there is a message shown in the same page saying "thank you, we'll contact you as fast as possible,...". But I would like to redirect the page to the homepage about 5 seconds after the message is being shown. This is the form header part: <form method="post" action="' .$_SERVER['REQUEST_URI'] . '" /> How can I make this form say "thank you" when the values are right (in the same page or another, that doesn't really matter) and then make it jump to the homepage again? thanks in advance It's pretty simple to see what I am trying to do here. For some reason all results in the table are the same exact cityName replacing all existing records. The echoed results are correct. I've include a small dump of my table as well. $query = "SELECT cityName FROM sys_city_dev_2"; $resource = mysqli_query($cxn, $query) or die("MySQL error: " . mysqli_error($cxn) . "<hr>\nQuery: $query"); while($result = mysqli_fetch_assoc($resource)) { $nox = $result['cityName']; $toUpper = ucfirst($nox); echo "$toUpper" . "<br />"; $setString = "UPDATE sys_city_dev_2 SET cityName = '" . $toUpper ."' WHERE cityName != ''"; mysqli_query($cxn,$setString); } 100 Records of table dump (pre running my script above): -- -- Table structure for table `sys_city_dev_2_backup` -- CREATE TABLE IF NOT EXISTS `sys_city_dev_2_backup` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Mid` int(11) NOT NULL DEFAULT '0', `cityName` varchar(30) NOT NULL DEFAULT '', `forder` int(4) NOT NULL DEFAULT '0', `disdplay` int(4) NOT NULL DEFAULT '0', `cid` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=113970 ; -- -- Dumping data for table `sys_city_dev_2_backup` -- INSERT INTO `sys_city_dev_2_backup` (`ID`, `Mid`, `cityName`, `forder`, `disdplay`, `cid`) VALUES (84010, 1, 'dothan', 0, 0, 0), (84011, 1, 'alabaster', 0, 0, 0), (84012, 1, 'birmingham', 0, 0, 0), (84013, 2, 'flagstaff', 0, 0, 0), (84014, 1, 'auburn', 0, 0, 0), (84015, 1, 'florence', 0, 0, 0), (84016, 1, 'gadsden', 0, 0, 0), (84017, 1, 'huntsville', 0, 0, 0), (84018, 1, 'mobile', 0, 0, 0), (84019, 1, 'montgomery', 0, 0, 0), (84020, 1, 'tuscaloosa', 0, 0, 0), (84021, 2, 'mohave valley', 0, 0, 0), (84022, 2, 'phoenix', 0, 0, 0), (84023, 2, 'prescott', 0, 0, 0), (84024, 2, 'sierra vista', 0, 0, 0), (84025, 2, 'tucson', 0, 0, 0), (84026, 2, 'yuma', 0, 0, 0), (84027, 3, 'bakersfield', 0, 0, 0), (84028, 3, 'chico', 0, 0, 0), (84029, 3, 'fresno / madera', 0, 0, 0), (84030, 3, 'gold country', 0, 0, 0), (84031, 3, 'humboldt county', 0, 0, 0), (84032, 3, 'imperial', 0, 0, 0), (84033, 3, 'inland empire', 0, 0, 0), (84034, 3, 'los angeles', 0, 0, 0), (84035, 3, 'alhambra', 0, 0, 0), (84036, 3, 'merced', 0, 0, 0), (84037, 49, 'fayetteville', 0, 0, 0), (84038, 49, 'fort smith', 0, 0, 0), (84039, 49, 'jonesboro', 0, 0, 0), (84040, 49, 'little rock', 0, 0, 0), (84041, 49, 'arkadelphia', 0, 0, 0), (84042, 49, 'texarkana', 0, 0, 0), (84043, 3, 'modesto', 0, 0, 0), (84044, 3, 'alta sierra', 0, 0, 0), (84045, 3, 'alpine', 0, 0, 0), (84046, 3, 'pedley', 0, 0, 0), (84047, 3, 'redding', 0, 0, 0), (84048, 3, 'alondra park', 0, 0, 0), (84049, 3, 'sacramento', 0, 0, 0), (84050, 4, 'canon city', 0, 0, 0), (84051, 3, 'san luis obispo', 0, 0, 0), (84052, 3, 'santa barbara', 0, 0, 0), (84053, 3, 'stockton', 0, 0, 0), (84054, 3, 'aliso viejo', 0, 0, 0), (84055, 3, 'visalia', 0, 0, 0), (84056, 3, 'yuba city', 0, 0, 0), (84057, 4, 'boulder', 0, 0, 0), (84058, 4, 'colorado springs', 0, 0, 0), (84059, 4, 'denver', 0, 0, 0), (84060, 4, 'applewood', 0, 0, 0), (84061, 4, 'pueblo', 0, 0, 0), (84062, 4, 'air force academy', 0, 0, 0), (84063, 5, 'avon', 0, 0, 0), (84064, 5, 'hartford', 0, 0, 0), (84065, 5, 'new haven', 0, 0, 0), (84066, 5, 'ansonia', 0, 0, 0), (84067, 5, 'fairfield', 0, 0, 0), (84068, 7, 'daytona beach', 0, 0, 0), (84069, 7, 'sebastian', 0, 0, 0), (84070, 5, 'wallingford center', 0, 0, 0), (84071, 8, 'belvedere park', 0, 0, 0), (84072, 7, 'sarasota springs', 0, 0, 0), (84073, 7, 'sandalfoot cove', 0, 0, 0), (84074, 7, 'san carlos park', 0, 0, 0), (84075, 7, 'st. augustine', 0, 0, 0), (84076, 7, 'tallahassee', 0, 0, 0), (84077, 7, 'safety harbor', 0, 0, 0), (84078, 7, 'ruskin', 0, 0, 0), (84079, 8, 'athens-clarke county', 0, 0, 0), (84080, 8, 'atlanta', 0, 0, 0), (84081, 8, 'augusta-richmond county', 0, 0, 0), (84082, 8, 'brunswick', 0, 0, 0), (84083, 8, 'columbus', 0, 0, 0), (84084, 8, 'americus', 0, 0, 0), (84085, 8, 'acworth', 0, 0, 0), (84086, 8, 'valdosta', 0, 0, 0), (84087, 10, 'boise', 0, 0, 0), (84088, 10, 'ammon', 0, 0, 0), (84089, 10, 'moscow', 0, 0, 0), (84090, 10, 'blackfoot', 0, 0, 0), (84091, 10, 'twin falls', 0, 0, 0), (84092, 10, 'meridian', 0, 0, 0), (84093, 10, 'jerome', 0, 0, 0), (84094, 10, 'idaho falls', 0, 0, 0), (84095, 11, 'addison', 0, 0, 0), (84096, 10, 'garden city', 0, 0, 0), (84097, 10, 'eagle', 0, 0, 0), (84098, 10, 'chubbuck', 0, 0, 0), (84099, 10, 'caldwell', 0, 0, 0), (84100, 12, 'bloomington', 0, 0, 0), (84101, 12, 'evansville', 0, 0, 0), (84102, 12, 'fort wayne', 0, 0, 0), (84103, 12, 'indianapolis', 0, 0, 0), (84104, 12, 'muncie / anderson', 0, 0, 0), (84105, 12, 'lafayette / west lafayette', 0, 0, 0), (84106, 12, 'south bend / michiana', 0, 0, 0), (84107, 12, 'terre haute', 0, 0, 0), (84108, 12, 'northwest indiana', 0, 0, 0), (84109, 13, 'ames', 0, 0, 0); Hi, I need to add a function for a date field on a form being submitted to MySQL DB. Something similar to this for a website field, except it shoudl make sure the format is in 01/05/2010 or 2numbers/2 numbers/4 numbers format... if(!mb_eregi("^[a-zA-Z0-9-#_.+!*'(),/&:;=?@]*$", $website)) $this->setError('website', 'invalid website'); elseif(mb_strlen(trim($website)) > 120) $this->setError('website', 'too long! 120 characters'); thanks in advance for any assistance. I need some assistance with an error I get when trying to submit a form to my email address. the error is this: Warning: mail() [function.mail]: SMTP server response: 555 syntax error (#5.5.4) in E:\Contact\process.php on line 74 Sorry, unexpected error. Please try again later the form code is Code: [Select] <form id="form" action="process.php" method="post" name="ContactForm"> <label for="Name">Name</label> <input type="text" name="name" id="name" /> <label for="email">E-mail</label> <input type="text" name="email" id="email" /> <label for="website">Website</label> <input type="text" name="website" id="website" /> <label for="message">Message</label> <textarea class="resizable" name="comment"> </textarea> <input type="submit" name="submit" id="submit" value="Submit"> </form> and the process code [php] <?php //Retrieve form data. //GET - user submitted data using AJAX //POST - in case user does not support javascript, we'll use POST instead $name = ($_GET['name']) ? $_GET['name'] : $_POST['name']; $email = ($_GET['email']) ?$_GET['email'] : $_POST['email']; $website = ($_GET['website']) ?$_GET['website'] : $_POST['website']; $comment = ($_GET['comment']) ?$_GET['comment'] : $_POST['comment']; //flag to indicate which method it uses. If POST set it to 1 if ($_POST) $post=1; //Simple server side validation for POST data, of course, you should validate the email if (!$name) $errors[count($errors)] = 'Please enter your name.'; if (!$email) $errors[count($errors)] = 'Please enter your email.'; if (!$comment) $errors[count($errors)] = 'Please enter your comment.'; //if the errors array is empty, send the mail if (!$errors) { //recipient $to = 'My Name <email@gmail.com>'; //sender $from = $name . ' <' . $email . '>'; //subject and the html message $subject = 'Comment from ' . $name; $message = ' <!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></head> <body> <table> <tr><td>Name</td><td>' . $name . '</td></tr> <tr><td>Email</td><td>' . $email . '</td></tr> <tr><td>Website</td><td>' . $website . '</td></tr> <tr><td>Comment</td><td>' . nl2br($comment) . '</td></tr> </table> </body> </html>'; //send the mail $result = sendmail($to, $subject, $message, $from); //if POST was used, display the message straight away if ($_POST) { if ($result) echo 'Thank you! I have received your message.'; else echo 'Sorry, unexpected error. Please try again later'; //else if GET was used, return the boolean value so that //ajax script can react accordingly //1 means success, 0 means failed } else { echo $result; } //if the errors array has values } else { //display the errors message for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>'; echo '<a href="form.php">Back</a>'; exit; } //Simple mail function with HTML header function sendmail($to, $subject, $message, $from) { $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= 'From: ' . $from . "\r\n"; $result = mail($to,$subject,$message,$headers); if ($result) return 1; else return 0; } ?> [/php] Hi good people, i'm vary new in this and i'm having trouble with PHP while writing some project for school and because i find many answers on this forum till now i decide to post this.. so here is my problem: I'm trying to make a web page for students and profesors where students (when they are loged in) will be able to sign a date for their exam so i made a form like this : Code: [Select] <form method="POST" action=""> choose exam: <p><select name="exams"> <option value="k1D">exam 1</option> <option value="k2D">exam 2</option> <option value="k3D">exam 3</option> </select></p> choose date: <p><select name="dates"> <optgroup label="Zimski rokovi"> <option value="2011-02-01">01.02.2011.</option> <option value="2011-02-07">07.02.2011.</option> <option value="2011-02-15">15.02.2011 </option> <optgroup label="Ljetni rokovi"> <option value="2011-05-21">21.05.2011.</option> <option value="2011-05-28">28.05.2011.</option> <option value="2011-06-04">04.06.2011.</option> </select></p> <input type="submit" value="Prijavi ispit" name="prijavi"> </form> table for students in mysql has columns for every exam (k1D , k2D..) but how can i make so that student can pick wich exam he wants to sign on some of dates (wich column he wants to fill with wich of dates) ? i tryed some variations of : Code: [Select] $k1D = $_POST['dates']; $kol = $_POST['exams']; mysql_query(" UPDATE studenti SET '$kol' = '$k1D' WHERE ID = '3'"); but i'm just getting different errors.. Hope someone can help put with this - I have inherited a site and am trying to modify some PHP that I am unfamiliar with. I have gotten so far with it, but still have a problem with it.
Its a page on an online store offering optional extras depending on the product. The products are furniture, so and there was an option to buy cushions for some. The change I am trying to make is to have an option for two different sizes of cushion depending on the product.
So there was a field 'cushions' in the product table, and a page 'accessories.php' that offered the option to add cushions.
I have added a new field 'cushions2' and a new page 'accessories2.php' to cover the new size of cushions.
The site is here, with this example product:
http://www.lloydloom...oduct.php?id=32
If you click 'Add to cart' the next page offers you the option to add custom paintwork.
If you enter something there, and click on 'Add colour to order' it works - i.e. the next page is the one offering the cushions.
But if you just click on 'No thank you, proceed with order' it just reloads the page - basically the URL isn't being puled through as it should be.
On that page the PHP at the top of the page looks like this:
<?php session_start(); Hello, I am working with a SMTP class to send an email. It's all working perfectly fine, but when the email is received (sent from the online form), and I open my email and click reply, there are two email addresses. The correct one (which I entered when I sent the email), and my ftp username for the site?? I've got three files that could effect this, but I was unable to locate any problems: mailer.php ( smtp send mail class) mail.php ( submission data: title, subject, etc. ) contact_form.php ( form for submission ) I am only including the file which I think is applicable (mail.php), but let me know if you would also like to see the mailer.php class. Current output: reply-to ftpusername@domainname.com, correct_from_email@fromemail.com mail.php: <?php set_time_limit(120); function sendHTMLmail($from, $to, $subject, $message) { $message = wordwrap($message, 70); // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= "From: $from\r\n"; // Mail it mail($to, $subject, $message, $headers); } function sendHTMLmail2($fromid, $to, $subject, $message) { echo $fromid; echo $to; echo $subject; echo $message; include_once("mailer.php"); $mail = new PHPMailer(); $mail->IsMail(); // SMTP servers $mail->Host = "localhost"; $mail->From = $fromid; $mail->FromName = $fromid; $mail->IsHTML(true); $mail->AddAddress($to, $to); $mail->Subject = $subject; $mail->Body = $message; $mail->AltBody = "Please enable HTML to read this"; $mail->Send(); exit; } function isValidEmail($email) { return eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$", $email); } class smtp_mail { var $host; var $port = 25; var $user; var $pass; var $debug = false; var $conn; var $result_str; var $charset = "utf-8"; var $in; var $from_r; //mail format 0=normal 1=html var $mailformat = 0; function smtp_mail($host, $port, $user, $pass, $debug = false) { $this->host = $host; $this->port = $port; $this->user = base64_encode($user); $this->pass = base64_encode($pass); $this->debug = $debug; $this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if ($this->socket) { $this->result_str = "Create socket:" . socket_strerror(socket_last_error()); $this->debug_show($this->result_str); } else { exit("Initialize Faild,Check your internet seting,please"); } $this->conn = socket_connect($this->socket, $this->host, $this->port); if ($this->conn) { $this->result_str = "Create SOCKET Connect:" . socket_strerror(socket_last_error()); $this->debug_show($this->result_str); } else { exit("Initialize Faild,Check your internet seting,please"); } $this->result_str = "Server answer:<font color=#cc0000>" . socket_read($this->socket, 1024) . "</font>"; $this->debug_show($this->result_str); } function debug_show($str) { if ($this->debug) { echo $str . "<p>\r\n"; } } function send($from, $to, $subject, $body) { if ($from == "" || $to == "") { exit("type mail address please"); } if ($subject == "") $sebject = "none title"; if ($body == "") $body = "none content"; $All = "From:$from;\r\n"; $All .= "To:$to;\r\n"; $All .= "Subject:$subject;\r\n"; if ($this->mailformat == 1) { $All .= "Content-Type:text/html;\r\n"; } else { $All .= "Content-Type:text/plain;\r\n"; } $All .= "Charset:" . $this->charset . ";\r\n\r\n"; $All .= " " . $body; $this->in = "EHLO HELO\r\n"; $this->docommand(); $this->in = "AUTH LOGIN\r\n"; $this->docommand(); $this->in = $this->user . "\r\n"; $this->docommand(); $this->in = $this->pass . "\r\n"; $this->docommand(); if (!eregi("235", $this->result_str)) { $this->result_str = "smtp auth faild"; $this->debug_show($this->result_str); return 0; } $this->in = "MAIL FROM: $from\r\n"; $this->docommand(); $this->in = "RCPT TO: $to\r\n"; $this->docommand(); $this->in = "DATA\r\n"; $this->docommand(); $this->in = $All . "\r\n.\r\n"; $this->docommand(); if (!eregi("250", $this->result_str)) { $this->result_str = "Send mail faild!"; $this->debug_show($this->result_str); return 0; } $this->in = "QUIT\r\n"; $this->docommand(); socket_close($this->socket); return 1; } function docommand() { socket_write($this->socket, $this->in, strlen($this->in)); $this->debug_show("Client command:" . $this->in); $this->result_str = "server answer:<font color=#cc0000>" . socket_read($this->socket, 1024) . "</font>"; $this->debug_show($this->result_str); } } ?> I have been looking at this code most of the morning and do not have a clue what is wrong with the code. I am hoping its not a stupid mistake, can someone please help me out? thank you
<title>Inputing Travel Detials</title> <header> <h1 align="center"> Adding Travel Detials </h1> <body> <p> <center><img src="cyberwarfareimage1.png" alt="Squadron logo" style="width:200px;height:200px" style="middle"></center> <table border="1"> <tr> <td><a href="index.php"> Home Page </a></td> <td><a href="administratorhomepage.html">Administrator Home Page </a></td> <td><a href="viewhomepage.html">View Home Page </a></td> <td><a href="Inputhomepage.html">Input Home Page </a></td> <td><a href="traveldetials.html">Enter More Travel Detials </a></td> </table> </p> <?php include "connection.php"; $Applicant_ID = $_POST["Applicant_ID"]; $Method_Of_Travel = $_POST["Method_Of_Travel"]; $Cost = $_POST["Cost"]; $ETA = $_POST["ETA"]; $Main_Gate_Advised = $_POST["Main_Gate_Advised"]; $query = ("UPDATE `int_board_applicant` SET `Method_Of_Travel`=`$Method_Of_Travel', `Cost`=`$Cost', `ETA`='$ETA', `Main_Gate_Advised`='$Main_Gate_Advised' WHERE `Applicant_ID`='$Applicant_ID'"); $result = mysqli_query($dbhandle, $query) or die(mysqli_error($dbhandle)); if($result){ echo "Success!"; } else{ echo "Error."; } // successfully insert data into database, displays message "Successful". if($query){ echo "Successful"; } else { echo "Data not Submitted"; } //closing the connection mysqli_close($dbhandle) ?> Ok this is puzzleing. I am geting "Could not delete data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1". but its is deleting the entry that needs to be removed. The "1" is the entry. Just not sure what is causing the error. I do have another delete php but I have put that on the back burning for the time being.
<?php $con = mysqli_connect("localhost","user","password","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $result = mysqli_query($con, "SELECT * FROM amp20 "); $amp20ptid = $_POST['amp20ptid']; // escape variables for security $amp20ptid = mysqli_real_escape_string($con, $_POST['amp20ptid']); mysqli_query($con, "DELETE FROM amp20 WHERE amp20ptid = '$amp20ptid'"); if (!mysqli_query($con, $amp20ptid)); { die('Could not delete data: ' . mysqli_error($con)); } echo "Part has been deleted to the database!!!\n"; mysqli_close($con); } ?> Hi guys
I have this code below and all works fine when submitting this online application apart from when someone types either ' # & into one of the comment fields in which it throws up the error. Have tried various fixes from across the internet but no joy. Can anyone offer suggestions?
<?php
$con = mysql_connect("localhost:3306","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('sfapp', $con);
$sql="INSERT INTO 'sfapp' ('surname_add','forename_add','dob_add','hometele_add','mobiletele_add','homeadd_add','siblings_add','schoolname_add','headname_add','schooladd_add','schooltele_add','schoolem_add','alevel_add','personstate_add','nameprovided_add','pe_add','se_add','PredGrade_Art','PredGrade_AScience','PredGrade_BusStudies','PredGrade_Electronics','PredGrade_EnglishLang','PredGrade_EnglishLit','PredGrade_French','PredGrade_German','PredGrade_Geog','PredGrade_Graphics','PredGrade_History','PredGrade_Maths','PredGrade_SepScience','PredGrade_ProductDesign','PredGrade_Spanish','PredGrade_Other','Gender_Male','Gender_Female','Sub_EnglishLit','Sub_Maths','Sub_FurtherMaths','Sub_Biology','Sub_Chemistry','Sub_Physics','Sub_French','Sub_German','Sub_Spanish','Sub_Geography','Sub_History','Sub_RE','Sub_FineArt','Sub_Business','Sub_Computing','Sub_GlobPersp','Sub_DramaAndTheatre','Sub_PE','Sub_Dance','Sub_Politics','Sub_Psychology','Sub_Sociology','readprospect_chk','Sib_Yes','Sib_No','Current_Student_Yes','Current_Student_No','I_Understand_chk','Current_Education_chk','Local_Care_chk','Staff_Cwhls_chk','Sub_Film')
VALUES
('$_POST[surname_add]','$_POST[forename_add]','$_POST[dob_add]','$_POST[hometele_add]','$_POST[mobiletele_add]','$_POST[homeadd_add]','$_POST[siblings_add]','$_POST[schoolname_add]','$_POST[headname_add]','$_POST[schooladd_add]','$_POST[schooltele_add]','$_POST[schoolem_add]','$_POST[alevel_add]','$_POST[personstate_add]','$_POST[nameprovided_add]','$_POST[pe_add]','$_POST[se_add]','$_POST[PredGrade_Art]','$_POST[PredGrade_AScience]','$_POST[PredGrade_BusStudies]','$_POST[PredGrade_Electronics]','$_POST[PredGrade_EnglishLang]','$_POST[PredGrade_EnglishLit]','$_POST[PredGrade_French]','$_POST[PredGrade_German]','$_POST[PredGrade_Geog]','$_POST[PredGrade_Graphics]','$_POST[PredGrade_History]','$_POST[PredGrade_Maths]','$_POST[PredGrade_SepScience]','$_POST[PredGrade_ProductDesign]','$_POST[PredGrade_Spanish]','$_POST[PredGrade_Other]','$_POST[Gender_Male]','$_POST[Gender_Female]','$_POST[Sub_EnglishLit]','$_POST[Sub_Maths]','$_POST[Sub_FurtherMaths]','$_POST[Sub_Biology]','$_POST[Sub_Chemistry]','$_POST[Sub_Physics]','$_POST[Sub_French]','$_POST[Sub_German]','$_POST[Sub_Spanish]','$_POST[Sub_Geography]','$_POST[Sub_History]','$_POST[Sub_RE]','$_POST[Sub_FineArt]','$_POST[Sub_Business]','$_POST[Sub_Computing]','$_POST[Sub_GlobPersp]','$_POST[Sub_DramaAndTheatre]','$_POST[Sub_PE]','$_POST[Sub_Dance]','$_POST[Sub_Politics]','$_POST[Sub_Psychology]','$_POST[Sub_Sociology]','$_POST[readprospect_chk]','$_POST[Sib_Yes]','$_POST[Sib_No]','$_POST[Current_Student_Yes]','$_POST[Current_Student_No]','$_POST[I_Understand_chk]','$_POST[Current_Education_chk]','$_POST[Local_Care_chk]','$_POST[Staff_Cwhls_chk]','$_POST[Sub_Film]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
?>
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['pe_add'])) {
//Email information
$admin_email = $_REQUEST['pe_add'];
$forename = $_REQUEST['forename_add'];
$email = "autoreply@testing.com";
$subject = "Application";
$desc =
"Dear $forename
Thank you for submitting your online application, we will be in touch shortly.
"
;
//send email
mail($admin_email, "$subject", "$desc", "From:" . $email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
If you are seeing this, you need to go back and fill out the Personal Email section!
<?php
}
header("location:complete.php");
mysql_close($con)
?>
Thanks in advance.
Hi.. I create mysql syntax for query testing before i input to my php code here is my mysql code: Code: [Select] set @t = 0; set @rqty=31968; SELECT LOT_CODE as code, DATE_ENTRY, CASE WHEN @t+OUTPUT_QTY > @rqty THEN @rqty -@t ELSE OUTPUT_QTY END as qty, @t := @t + d.OUTPUT_QTY as cumulative FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = 'P28' AND (@t < @rqty); and i attach the sample output of the above query. Now that query test is work i will input that code to my php codes. $sql = "SELECT SKUCode, Materials, Comp, Qty FROM bom WHERE SKUCode = '$SKUCode'"; $res = mysql_query($sql, $con); ($row = mysql_fetch_assoc($res)); $Materials = $row['Materials']; $Qty = $row['Qty']; $Comp = $row['Comp']; //P28 //-----Compute Req Qty and Save to table---// $ReqQty = $Qty * $POReq; // 31968 $sql = "UPDATE bom SET ReqQty = '$ReqQty' WHERE SKUCode = '$SKUCode' AND Materials = '$Materials'"; $resReqQty = mysql_query($sql, $con); $t = 0; $sql = "SELECT LOT_CODE as code, DATE_ENTRY, CASE WHEN $t+OUTPUT_QTY > $ReqQty THEN $ReqQty -$t ELSE OUTPUT_QTY END as qty, $t := $t + d.OUTPUT_QTY as cumulative FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = '$Comp' AND ($t < $ReqQty)"; when I echo the query: I got this: SELECT LOT_CODE as code, DATE_ENTRY, CASE WHEN 0+OUTPUT_QTY > 31968 THEN 31968 -0 ELSE OUTPUT_QTY END as qty, 0 := 0 + d.OUTPUT_QTY as cumulative FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = 'P28' AND (0 < 31968) then I run it to the sql and I got an error: Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':= 0 + d.OUTPUT_QTY as cumulative FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = '' at line 1 (0 ms taken) Any help is highly appreciated Thank you so much |