PHP - Error Checking Code
Hi, I wrote a simple code to check to see if the user filled in the name field, but when I uploaded the file, it just displays the code. here 's the code.
Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $errors=array(); if(isset($_POST['submit'])) { validate_input(); if(count($errors) !=0) { display_form(); } else { display_form(); } } function validate_input() { global $errors; if($_POST['name'] == " "){ $errors['name']="dipshit, put your name"; } ?> <form action="" method="post" name="test"> Name: <input name="name" type="text" size="10" maxlength="15" value="<?php echo $_POST[name]; ?>"/><br /> <?php echo $errors['name']; ?> <input name="submit" type="button" value="submit" /> </form> </body> </html> Similar TutorialsI've decided to rewrite one a couple of my forms, to make them more user friendly. But I am having problems returning the error. I've created an array ($e) which has the field name ($e['field_name']) for the error, but it isn't displaying any errors. Here's the code: case "contact": $e = array(); if(isset($_POST['sb'])){ $fullname = $sql->real_escape_string($_POST['fullname']); $email_a = $sql->real_escape_string($_POST['email']); $email_r = $sql->real_escape_string($_POST['email_r']); $orderid = $sql->real_escape_string($_POST['orderid']); $subject = $sql->real_escape_string($_POST['subject']); $problem = $sql->real_escape_string($_POST['problem']); # Error Message function show_error($error,$evar){ $err = ' <span style="color: #ff0000"><strong>'.$error.'</strong></span>'; return $err; } # Check for isset if(!isset($_POST['fullname'])){ $e['fullname'] = show_error('Please enter your full name',$e['fullname']); } if(!isset($_POST['email_a'])){ $e['email_a'] = show_error('Please enter your email address.',$e['email_a']); } if(!isset($_POST['email_r'])){ $e['email_r'] = show_error('Please re-enter your email address.',$e['email_r']); } if(!isset($_POST['subject'])){ $e['subject'] = show_error('Select a subject.',$e['subject']); } if(!isset($_POST['problem'])){ $e['problem'] = show_error('Describe your problem.',$e['problem']); } if(isset($_POST['email']) AND isset($_POST['email_r']) AND $email_a != $email_r){ $e['email_r'] = show_error('Your email addresses do not match.',$e['email_r']); } } $content = '<h2> Customer Support - Contact</h2> <p> For technical support, sales and product related questions: <a href="'.$tech_support.'" target="_blank">Technical Support</a>.</p> <p> For downloading, ordering, refund or other store related questions, please fill out the form below:</p> <form method="post" name="csupport"> <p> Please enter your full name:<br /> <input name="fullname" type="text" value="'.$fullname.'" />'.$e['fullname'].'</p> <p> Please enter your email address:<br /> <input name="email_a" type="text" value="'.$email_a.'" />'.$e['email_a'].'<br /> Please re-enter your email address:<br /> <input name="email_r" type="text" value="'.$email_r.'" />'.$e['email_r'].'</p> <p> Please enter your order number:<br /> <input name="orderid" type="text" value="'.$orderid.'" /></p> <p> Please select a subject for your enquiry:<br /> <select name="subject"><option selected="selected" value="">--Select--</option><option value="Billing Question">Billing Question</option><option value="Cancel / Refund Order">Cancel / Refund Order</option><option value="Download Question">Download Question</option><option value="Password Issues">Password Issues</option><option value="Order Question">Order Question</option><option value="Shipping Question">Shipping Question</option><option value="Other">Other</option></select>'.$e['subject'].'</p> <p> Describe your problem as best you can:<br /> <textarea cols="45" name="problem" rows="4">'.$problem.'</textarea>'.$e['problem'].'</p> <p> <input name="sb" type="hidden" value="sb" /><input name="submit" type="submit" value="Submit" /></p> </form> '; $title = 'Contact Support'; break; Can anyone see what the problem is? Thanks can somebody please tel me how to make sure a field is a number? I have some error checking like if(empty($postcode)) { $errors[] = "Please enter your postcode"; } if(strlen($tel)<11) { $errors[] = "Please enter a phone number that is the correct length"; } But I dont know and cant find how to check for a number only. This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=334287.0 Code: [Select] <?php session_start(); mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("cute") or die(mysql_error()); $username = $_POST['username']; $_POST['pass'] = md5($_POST['pass']); $password = $_POST['pass']; if (isset($_POST["submit"])) { $log1 = "SELECT * FROM regis WHERE username = '$username'"; $login1 = mysql_query($log1); $log2 = "SELECT * FROM regis WHERE password = '$password'"; $login2 = mysql_query($log2); $log3 = "SELECT * FROM regis WHERE username = '$username' AND password = '$password'"; $login3 = mysql_query($log3); $row = mysql_fetch_array($login3); $number = mysql_num_rows($login3); if($login1==FALSE) { echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('This.$username.is not available.')</SCRIPT>"); } if($login2==FALSE) { echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('This.$password.is incorrect.')</SCRIPT>"); } if ($number == 0) { print "This user does not exist in our database. <a href=registration.php><input type='button' value='Register'></a>"; } if ($number > 0) { $_SESSION['username'] = $row['username']; $_SESSION['password'] = $row['password']; $_SESSION['userlevel'] = $row['userlevel']; $_SESSION['is_logged_in'] = 1; if($_SESSION['userlevel']==1) { $_SESSION['is_logged_in'] = 1; header("Location: form2.php"); } else if($_SESSION['userlevel']== 0) { $_SESSION['is_logged_in'] = 1; header("Location: form3.php"); } } } else { ?> <html> <head> <script type="text/javascript"> function a() { var x = document.login.username.value; var y = document.login.pass.value; if(x==""&& y=="") { alert("Please insert all message!"); return false; } if(x=="") { alert("Please insert an username!"); return false; } if(y=="") { alert("Please insert an password!"); return false; } } </script> </head> <body> <center> <table border="0" align="center"> <form name="login" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return a()"> <tr><td colspan=2><center><h1>Login</h1></center></td></tr> <tr><td>Username:<input type="text" name="username" maxlength="40"></td></tr> <tr><td>Password:<input type="password" name="pass" maxlength="50"></td></tr> <tr align=center><td><input type="button" value="Register" ONCLICK="window.location.href='registration.php'"></a> <input type="submit" name="submit" value="Login"></td> </tr> </form> </center> </body> <?php } ?> this is login code as im want it show the error if i put any username or password error but instead it will directly show this error "if ($number == 0) { print "This user does not exist in our database. <a href=registration.php><input type='button' value='Register'></a>"; } " but im want to show this if($login1==FALSE) { echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('This.$username.is not available.')</SCRIPT>"); } if($login2==FALSE) { echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('This.$password.is incorrect.')</SCRIPT>"); } error first. may i know which code or if statement im put wrong I have created a form where the user enters their first name, last name, work hours, and rate. I want to add a check so that once submit is pressed, the page will return an error if one of the fields was left blank. How can I do it?? I have been trying for hours... Here is my code: <html> <title> Pay Calculator </title> <form method='post' action='pay2.php'> First Name: <input type='text' name='first' value="<?php echo ($_POST['first']); ?>" <br/> Last Name: <input type='text' name='last' value="<?php echo ($_POST['last']); ?>" <br/> Hours of Work: <input type='text' name='hours' value="<?php echo ($_POST['hours']); ?>" <br/> Hourly Pay Rate: <input type='text' name='rate' value="<?php echo ($_POST['rate']); ?>" <br/> <input type='submit' value='submit'> </form> </html> <?php $pay = $_POST['pay']; $hours = $_POST['hours']; $extra = $_POST['extra']; $rate = $_POST['rate']; if ($hours > 40){ $extra=$hours-40; $hours=40; $pay=($extra*1.5*$rate)+($hours*$rate); } else { $pay=$hours*$rate; } if (empty($_POST['$first'])) {print "**Please enter your first name\n";} echo "\n Your pay is: <br /> $ $pay <br />" ; ?> First, I'd like to apologize for my behavior, I didn't really "do anything wrong per se" I just get impulsive sometimes haha bad start
I am so close to finishing this website, which I will use to sell myself as a person who fixes computers
I am stuck on this problem, for all the pages
Either I can error check but data is not recorded in the tables
Or the error checking works but data is not recorded
The problem seems to be "triggered" by removing $errors[]="";
Also I'd like to say hello to QuickOldCar
Anyway here is the php parts of a single web page, this problem is shared on all of them except the index page which has successful error checking, session data retrieval and redirecting / updating data
I've spent days trying to fix this amongst other things (pretty sad right) this is literally one of the final problems to be solved before I'm ready to get his website indexed / advertise it
Thanks for any help
<?php ob_start(); session_start(); global $nameErr,$emailErr,$commentsErr,$hourErr,$minuteErr; global $name,$comments,$email,$hour,$minute; mysqli_report(MYSQLI_REPORT_ALL); error_reporting(E_ALL); error_reporting(-1); function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } $servername = "localhost"; $username = " "; $password = " "; $dbname = " "; global $link; $link = new mysqli("$servername", "$username", "$password", "$dbname"); if($_SERVER['REQUEST_METHOD']=='POST'){ $errors = array(); if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = test_input($_POST["name"]); // check if name only contains letters and whitespace if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "The form of the name entered is not acceptable"; } } if (empty($_POST["email"])) { $emailErr = "An email is required"; } else { $email = test_input($_POST["email"]); } if (empty($_POST["comments"])) { $commentsErr = "A comment is required."; } else { $comments = test_input($_POST["comments"]); // check if name only contains letters and whitespace } $test = $_POST['hour']; $test1 = '$test'; if (empty($_POST['hour'])) { $hourErr = "Please specify an hour between 12 and 8"; } else { if (ctype_digit($_POST['hour'])) { $hour = test_input($_POST['hour']); }else { $hourErr = "Only numbers are allowed"; } } if (empty($_POST['minute'])) { $minuteErr = "Please specify a minute between 1 and 60"; } else { if (ctype_digit($_POST['minute'])) { $minute = test_input($_POST['minute']); } else { $minuteErr = "Only numbers are allowed"; } } if(empty($errors)){ $link = new mysqli("$servername", "$username", "$password", "$dbname"); $name = test_input($_POST['name']); $email = test_input($_POST['email']); $comments = test_input($_POST['comments']); $hour = test_input($_POST['hour']); $minute = test_input($_POST['minute']); // use the submitted data here... insert into database, send email, ... $stmt = mysqli_prepare($link, "INSERT INTO Dropoff VALUES (?,?,?,?,?)"); $stmt->bind_param('sssii',$name,$email,$comments,$hour,$minute); $stmt->execute(); $to = ' '; $subject = 'Dropoff scheduled'; $message = "Check the database"; $message = wordwrap($message,70,"\r\n"); $headers = 'From: service@jakes-bytes.us'."\r\n\r\n"; mail($to,$subject,$message,$headers); $to = $email; $subject = 'Jakes Bytes Your Dropoff Has Been Scheduled'; $message = "Thank you for choosing Jakes Bytes computer repair shop.\r\n\r\nAttached is the information you have sent.\r\n\r\n \r\n\r\nBelow is our address. Look for the Greek letters on our building.\r\n\r\nJake's Bytes is a private business. Please call upon arrival.\r\n\r\nThank you.\r\n\r\n169 Highgate Ave. Buffalo, NY 14215\r\n\r\nJake's Bytes is a property of Normalbus"; $message = wordwrap($message,70,"\r\n"); $headers = 'From: '."\r\n\r\n"; mail($to,$subject,$message,$headers); // set up a status message to be displayed one time $_SESSION['status_message'] = "Drop off scheduled successfully"; // after successfully processing any post form data, redirect to the same exact url of this page to clear the post data $host = $_SERVER['HTTP_HOST']; $uri = $_SERVER['REQUEST_URI']; // the path/file?query string of the page header("Location: http://$host$uri"); exit; $link->close(); } } ?> <HTML> <html break> <?php if(!empty($errors)){ foreach($errors as $error){ echo '<span style="color: red">'.htmlspecialchars($error).'</span>'.'</br>'.'</br>'; } } if(isset($_SESSION['status_message'])){ echo '<span style="color: #ccfb5d">'.htmlspecialchars($_SESSION['status_message']).'</span>'.'</br>'.'</br>'; unset($_SESSION['status_message']); // clear the message } ?> <html resume> </html>Awe it's too bad the code paste box doesn't have highlighting, I've been spending time at other PHP forums and codingforums uses highlighting which is very helpful Edited by mac_gyver, 28 December 2014 - 10:41 AM. link removed The below is flagging errors #3 and #9. Error #3 is being thrown even though the emails match. Code: [Select] <?php session_start(); $_SESSION['submitted']="yes"; $error=$_GET['error']; $date_rma="5/10/2011"; $content=' <div class="content_text"> <div class="content_header">Request RMA Number</div> <p>Enter the information you used on PayPal, that you completed your order with. The information must match, or a RMA Number will not be issued.</p> <form action="./rma_process.php" method="post"> <p><label>Name:</label> <input type="text" name="name" size="30" value="'.(isset($_SESSION['name']) ? $_SESSION['name'] : '').'" />'; if($error[0]==1){ $content.=' <span class="red bold">This field is required.</span>'; } $content.='</p> <p><label>E-Mail Address:</label> <input type="email" name="email" size="35" value="'.(isset($_SESSION['email']) ? $_SESSION['email'] : '').'" />'; if($error[1]==1){ $content.=' <span class="red bold">This field is required.</span>'; } $content.='</p> <p><label>Confirm E-Mail Address:</label> <input type="email" name="confirm_email" size="35" value="'.(isset($_SESSION['confirm_email']) ? $_SESSION['confirm_email'] : '').'" />'; if($error[2]==1){ $content.=' <span class="red bold">This field is required.</span>'; } if($error[3]==1){ $content.=' <span class="red bold">E-Mail addresses do not match.</span>'; } $content.='</p> <p><label>Phone Number:</label> <input type="text" name="phone" size="15" value="'.(isset($_SESSION['phone']) ? $_SESSION['phone'] : '').'" /> Ext. <input type="text" name="ext" size="4" value="'.(isset($_SESSION['ext']) ? $_SESSION['ext'] : '').'" />'; if($error[4]==1){ $content.=' <span class="red bold">A properly formatted phone number is required.</span>'; } $content.='</p> <p><label>Date of Purchase (MM/DD/YYYY):</label><input type="text" name="month" size="2" maxlength="2" value="'.(isset($_SESSION['month']) ? $_SESSION['month'] : '').'" /> <input type="text" name="day" size="2" maxlength="2" value="'.(isset($_SESSION['day']) ? $_SESSION['day'] : '').'" /> <input type="text" name="year" size="5" maxlength="4" value="'.(isset($_SESSION['year']) ? $_SESSION['year'] : '').'" />'; if($error[5]==1 || $error[6]==1 || $error[7]==1){ $content.=' <span class="red bold">A properly formatted date is required.</span>'; } $content.='</p><p><label>List the Products you wish to return. Sperate with a comma. <br />Use either the whole product name, or the GHP# Product Code:</label>'; if($error[8]==1){ $content.=' <span class="red bold">This field is required.</span>'; } $content.='<textarea name="products_returning" rows="10" cols="60"> '.(isset($_SESSION['products_returning']) ? $_SESSION['products_returning'] : '').''; $content.=' </textarea> <input type="hidden" name="submitted" value="yes" /> </p> <p><input type="submit" value="Submit" name="Submit" /></p> </form> </div> '; ?> Code: [Select] <?php session_start(); $name = $_POST['name']; $_SESSION['name']=$name; if($name==""){ $error0=1; } else{ $error0=0; } $email = $_POST['email']; $_SESSION['email']=$email; if($email==""){ $error1=1; } else{ $error1=0; } $confirm_email = $_POST['confirm_email']; $_SESSION['confirm_email']=$confirm_email; if($confirm_email==""){ $error2=1; } else{ $error2=0; } if($email!=$confirm_email){ $error3=1; } else{ $error3=0; } $phone = $_POST['phone']; $_SESSION['phone']=$phone; if($phone==""){ $error4=1; } else{ $error4=0; } $ext = $_POST['ext']; $_SESSION['ext']=$ext; $phone = $phone.' Ext.'.$ext; $month = $_POST['month']; $_SESSION['month']=$month; if($month=="" || !is_numeric($month)){ $error5=1; } else{ $error5=0; } $day = $_POST['day']; $_SESSION['day']=$day; if($day=="" || !is_numeric($day)){ $error6=1; } else{ $error6=0; } $year = $_POST['year']; $_SESSION['year']=$year; if($year=="" || !is_numeric($year)){ $error7=1; } else{ $error7=0; } $date="".$month."/".$day."/".$year.""; $products_returning = $_POST['products_returning']; $_SESSION['products_returning']=$products_returning; if($products_returning==""){ $error8=1; } else{ $error8=0; } if($_SESSION['submitted']=="yes"){ $error9=0; } else{ $error9=1; } $error="".$error0."".$error1."".$error2."".$error3."".$error4."".$error5."".$error6."".$error7."".$error8."".$error9.""; if($error!=="0000000000"){ header("Location: ./index.php?returns=rma&error=".$error0."".$error1."".$error2."".$error3."".$error4."".$error5."".$error6."".$error7."".$error8."".$error9.""); } else{ header("Location: ./index.php?returns=submitted"); } ?> In an .html, before : <!-- BEGIN myquery --> I need to stop output and check the content of "myquery" Is there a command for that ? Thank You. Thanks to everyone's earlier help, I pretty much have my "Upload a Photo" module done. However, I am wondering if the following code snippet can be streamlined? Do I really need to check for Width and Height when above I look at if ($imageDetails = getimagesize($tempFile)){?? // ******************** // Check File-Type. * // ******************** if (empty($errors)){ if ($imageDetails = getimagesize($tempFile)){ // Image-Array Exists. $width = $imageDetails[0]; $height = $imageDetails[1]; $imageType = $imageDetails['mime']; // IS IT REDUNDANT TO CHECK THE DIMENSIONS??? // ************************ // Check for Dimensions. * // ************************ if ($width && $height){ // Width and Height Exist. // File is Image. // ************************ // Determine Image-Type. * // ************************ if ($imageType !== 'image/gif' && $imageType !== 'image/jpeg' && $imageType !== 'image/png'){ // Invalid Image-Type. $errors['upload'] = 'Image-type must be either GIF, JPG, or PNG.'; }else{ // Valid Image-Type. // Continue Processing Upload... }//End of DETERMINE IMAGE-TYPE }else{ // File Not Image. $errors['upload'] = 'Only Images can be uploaded (i.e. GIF, JPG, or PNG).'; }//End of CHECK FOR DIMENSIONS }else{ // No Image-Array. // File Not Image. $errors['upload'] = 'Only Images can be uploaded (i.e. GIF, JPG, or PNG).'; } }//End of CHECK FILE-TYPE What do you think? I am leaning towards taking the second check out for brevity... Debbie Hi All, I'm having a major mind blank, and can't find anything in the previous posts resolving what I'm after. I'm setting $searchtext = $_POST['searchtext']; I want to check $seachtext is not null. I've seen isset($searchtext) but it doesn't solve my problem. Basiclaly; I want an if statement to say if(isset($searchtext)) {......} Thoughts? I found the code below which checks to make sure something the user entered into a text field is an actual URL. I am looking to confirm that something a user enters is an actual link to an IMAGE, so does anyone know how I could adjust this code below to do that? Basically, this code below would accept http://monkeys.com AND http://monkeys.com/images/monkey.jpg. I want to alter the code so that http://monkeys.com would NOT be accepted since it's not an image. Essentially, I want to make sure whatever the user enters ends with .jpg, .gif or .png. Anyone know how to do this? Code: [Select] url": { "regex": /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/, "alertText": "* Invalid URL" } I'm getting an error with this code:
<?php Why doesn't this code work? I can't figure it out. Database information: DB: abelltx table: homework Fields in table: id, pid, uid, name, url, approved, comment, SubmissionTime <?PHP $link = mysql_connect('xxxxxx', 'xxxxx', 'xxxxxxx') or die(mysql_error()); mysql_select_db("abelltx", $link) or die(mysql_error()); $uid=abelltx $query = "SELECT DISTINCT name FROM homework ORDER BY id ASC"; $result = query_db($query); while ($myrow = mysql_fetch_array($result)) { echo $myrow[name].", "; } ?> I get the following error: "Parse error: syntax error, unexpected T_VARIABLE in D:\Hosting\5366560\html\test.php on line 6" Fairly new to PHP and have the following code which should simply output into 3 columns - I have checked the query which does work - so I dont understand why I get this error mysql_fetch_array() expects parameter 1 to be resource,
// Create connection
// Check connection
$sql = “SELECT * FROM duration_matched WHERE groupm = '”.$coincidence ."’";
// set up loop counter
// start table and first tr ’;
while ($row=mysql_fetch_array($result)) {
’;
// always output the td
’;
// then close off the last row and the table ’ . $row[‘image’] . ‘ ’; $conn->close(); I have a page that displayes a table from my database. What I'm attempting to do is create a page where you can delete rows of that table. I'm creating 3 pages 1( select the student or row to delete) 2( comfirm whether you want to delete that student) and 3( where the student has been deleted) I'm already having trouble with my first page. This is my code to select the row or student you want to delete: <?php Code: [Select] <?php include 'includes/config.php'; $delete_sql ="SELECT sno,cname, sname FROM student ORDER BY sno DESC"; $delete_query = mysql_query($delete_sql) or die(mysql_error()); $rsDelete = mysql_fetch_assoc($delete_query); ?> <html> <head> </head> <body> <p> select student to delete </p> <?php do {?> <p><a href="deletecomfirm.php?sno= <?php echo $rsDelete['sno']; ?>"> <?php echo $rsDelete['cname']; ?> by <?php echo $rsDelete['fname']; ?> </a> </p> <?php} while ($rsDelete = mysql_fetch_assoc($delete_query)) ?> </body> </html>?> I keep getting this error: Parse error: syntax error, unexpected $end in C:\Program Files\EasyPHP-5.3.3\www\Project\selectdelstudent.php on line 32 I'm assuming this error indicates an improper closing tag or something? Though I can't see my mistake. Also if you have any tips on improving my code feel free to comment I have a website for ordering business cards, and have encountered an error with either the HTML or PHP coding. The website has a form with several text boxes and drop-down menus to fill in the order form, and at the end after clicking the "submit" button, it generates an e-mail through a PHP script that sends the order form to the printer of the business cards. For some reason, whenever a user has a "job title" with the word "specialist" in it, the e-mail never gets sent. I removed all job titles from the one drop-down menu, to try and fix the problem, but now when users type "specialist" in the comments box at the bottom of the form, that blocks the e-mail from being sent as well. I have tried looking online for possible reasons why this one word would cause such a problem, but have not found the answer yet. Does anyone on this forum know why the word "specialist" would cause this issue, or know where I can look for a solution? If you can help me, that would be greatly appreciated. Thanks! $bbreplace = array ( '/(\[[Bb]\])(.+)(\[\/[Bb]\])/', '/(\[[Ii]\])(.+)(\[\/[Ii]\])/', '/(\[[Uu]\])(.+)(\[\/[Uu]\])/', '/(\[[Ss]\])(.+)(\[\/[Ss]\])/', '/(\[url=http://)(.+)(\])(.+)(\[\/url\])/', '/(\[img\])(.+)(\[\/img\])/', '/(\[IMG\])(.+)(\[\/IMG\])/', '/(\[COLOR=)(.+)(\])(.+)(\[\/COLOR\])/', '/(\[color=)(.+)(\])(.+)(\[\/color\])/', '/(\[SIZE=)(.+)(\])(.+)(\[\/SIZE\])/', '/(\[size=)(.+)(\])(.+)(\[\/size\])/', '/(\[list\](.+)(\[\/list\])/', '/(\[list=1\](.+)(\[\/list\])/', '/(\[lLIST\](.+)(\[\/LIST\])/', '/(\[LIST=1\](.+)(\[\/LIST\])/', '/(\[*\](.+)/' ); $bbreplacements = array ( '<b>\\2</b>', '<i>\\2</i>', '<u>\\2</u>', '<s>\\2</s>', '<a href="\\2">\\4</a>', '<img src="\\2">', '<img src="\\2">', '<font color="\\2">\\4</font>', '<font color="\\2">\\4</font>', '<font size="\\2">\\4</font>', '<font size="\\2">\\4</font>', '<ul>\\2</ul>', '<ol>\\2</ol>', '<ul>\\2</ul>', '<ol>\\2</ol>', '<li>\\2</li>' ); $PostText = preg_replace($bbreplace, $bbreplacements, $PostText); This is what I have to do BB Codes so Far. Now when I go to view the thread I get: Warning: preg_replace() [function.preg-replace]: Compilation failed: missing ) at offset 25 in /home/rayth/public_html/forum/viewthread.php on line 95 Line 95: $PostText = preg_replace($bbreplace, $bbreplacements, $PostText); From testing I didn't get this error untill I added the tags so I have been making a php chat service, and when i use this code:
Welcome <?php echo $_COOKIE["username"]; ?><br> chatroom: <?php echo $_COOKIE["chatroom"]; ?> <?php $phpfile=$_COOKIE["chatroom"]; $chpage = $phpfile .".php"; $chtext = $phpfile .".txt"; $filename = $_COOKIE["chatroom"] . ".txt"; $myfile = fopen($filename, "r") or die("Unable to open file!"); fopen($myfile); fclose($myfile); include $chtxt; ?> <form action="post.php" method="post"> message: <input type="text" name="msg"><br> <input type="submit"> </form>I get a 403 error. I does anyone know that is wrong with the code? there are more files that set the cookies but they work fine. I can't find anything wrong. please help. Hey all, Basically I have this code which technically should work, but I have put an error in the logic somewhere and am really struggling to find it, I've been going over it for about an hour now :/ The error is that in the second part (// Enter them into the activities database if they're not already there), it won't enter them, and it won't show the word 'Randomevent1' either, so clearly somehow I have put in something to prevent it performing that step. Can anybody help me out? I'd be amazingly grateful, I have no clue how I've screwed it up. if(isset($_POST['submit'])){ $ownerid = $_SESSION['id']; // If completed = Y give an error $completeyn = "SELECT completed FROM activities WHERE playerno='$ownerid' AND activityno = '1'"; $completecheck=mysql_query($completeyn) or die(mysql_error()); while($row = mysql_fetch_array( $completecheck )) { if($row['completed'] == 'Y'){ echo 'Oops, you\'ve already done this twice today!';} else { // Enter them into the activities database if they're not already there $stepno2 = "SELECT playerno, timesdone FROM activities WHERE playerno='$ownerid' AND activityno = '1'"; $stepnoanswer2=mysql_query($stepno2) or die(mysql_error()); $num_rows2 = mysql_num_rows($stepnoanswer2); echo $num_rows2; if($num_rows2 == '0'){ $putintodb2 = mysql_query("INSERT INTO activities (playerno, activityno, timesdone) VALUES ('$ownerid', '1', '1')") or die("Error: ".mysql_error()); echo 'Randomevent1'; }else{ // If they are already there update their stepcount $updatestepcount2=("UPDATE activities SET timesdone=timesdone+'1' WHERE playerno='$ownerid' AND activityno = '1'"); $newstepcount2=mysql_query($updatestepcount2); echo 'Randomevent2';} // If this new stepcount is equal to 2, set completed to Y $checkstep = "SELECT timesdone FROM activities WHERE playerno='$ownerid' AND activityno = '1'"; $checkstepresult=mysql_query($checkstep) or die(mysql_error()); while($row = mysql_fetch_array( $checkstepresult )) { if($row['timesdone'] == '2'){ echo $row['timesdone']; $updatestepcount22=("UPDATE activities SET completed = 'Y' WHERE playerno='$ownerid' AND activityno = '1'"); $newstepcount22=mysql_query($updatestepcount22); } }}}} <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); include 'helpers.php'; $foldername = uniqid(); $destination = "vierkant/$foldername"; $locatie = "circles/$foldername"; createDirectory($locatie); createDirectory($destination); $upload_files = []; for ($i = 0; $i < count($_FILES['file']['name']); $i++) { move_uploaded_file( $_FILES['file']['tmp_name'][$i], $destination . '/' . $_FILES['file']['name'][$i] ); $target_name = $_FILES['file']['name'][$i]; // Remove the extension and replace it with .png. imagepng(imagecreatefromstring(file_get_contents($_FILES["file"]["tmp_name"] )), "output.png"); // One method for this is to use the "explode" function with a dot as a delimiter. // variable we are going to split print_r (explode(".",$target_name)); // Then replace the last part with png and then stick the string back together with "implode" $upload_files[] = [ 'square' => $destination . '/' . $_FILES['file']['name'][$i], 'circle' => $locatie . '/' . $_FILES['file']['name'][$i], ]; } foreach ($upload_files as $loopdata) { print_r($loopdata['circle']); toCircle($loopdata['square'],$loopdata['circle'],'450'); }
I have to do this but i get this error: https://ibb.co/mFzxqXL can anyone help me? // Remove the extension and replace it with .png.
// variable we are going to split: // Then replace the last part with png and then stick the string back together with "implode" |