PHP - Why Is Error Checking Being Skipped Upon Post?
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 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. 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 />" ; ?> This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=334287.0 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> 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 Hello there,
I would be really grateful if someone could advice please, how do I find this pesky entry in the 'db' table? This is what it says,
"Found an entry in the 'db' table with empty database name; Skipped." MySQL version is 5.5.40
I am pretty much stuck on it. Does it mean the table's name is db? Plus, I am not sure I understand the wording of it too. The empty database name cannot exist by default as it won't allow you to create a database without a name in the first place. I do not even know how and where to begin to look for it because honestly speaking I do not quite understand the phrase itself, because it does not make much sense to me. I would really highly appreciate it if someone could explain and suggest how do I find the... "whatever it says" :-) and to fix it. Many thanks in advance!
P.S. I know this warning may easily and safely be ignored as it is of minor inconvenience and not that important the more so as MySQL is working fine but my curiosity is just running wild for two reasons: 1. I do not really understand what this warning message is trying to tell me and 2. How do I find and adjust it to turn off the warning.
Simple regular things as running myisamchk -r *.MYI on where MySQL is did not help as this warning is actually out of scope of what myisamchk can fix.
And yes, I've Googled it long enough but couldn't seem to come up with anything reasonable solutions.
Thankful for any suggestions / pointers / assistance / comments at all.
Edited by Klaipedaville, 29 October 2014 - 06:17 AM. 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"); } ?> <?php class Post{ private $user_obj; private $con; public function __construct($con, $user){ $this->con = $con; $this->user_obj = new User($con,$user); } public function submitPost($body,$user_to){ $body = strip_tags($body);////Removing HTML TAGS $body = mysqli_real_escape_string($this->con,$body); $check_empty = preg_replace('/\s+/', '', $body);//delte all spaces if($check_empty != ""){ //Current Date and time $date_added = date("Y-m-d H:i:s"); //get username $added_by = $this->user_obj->getUsername(); //if user have not a profile send to the none if($user_to == $added_by){ $user_to = "none"; } ////insert query $query = mysqli_query($this->con,"INSERT INTO posts VALUES('','$body','$added_by','$user_to','$date_added','no','no','0')"); $retured_id = mysqli_insert_id($this->con); //insert notification //Update post count for user $num_post = $this->user_obj->getNumPosts(); $num_post++; $update_query = mysqli_query($this->con,"UPDATE users SET num_post = '$num_post' WHERE username = '$added_by'" ); } public function loadPostsFriends(){ $str = ""; //string to return $data = mysqli_query($this->con,"SELECT * FROM posts where deleted = 'no' ORDER by id DESC"); while($row = mysqli_fetch_array($data)) { $id = $row['id']; $body = $row['body']; $added_by = $row['added_by']; $date_time = $row['date_added']; /// Creating user post on other user profile if($row['user_to'] == "none"){ user_to = ""; else { $user_to_obj = new User($con,$row['user_to']); $user_to_name = $user_to_obj->getFirstandLastname(); $user_to = "to <a href='" . $row['user_to'] . "'>" .$user_to_name . "</a>"; } // check if user account was closed $added_by_obj = new User($this->con,$added_by); if($added_by_obj ->isClosed()){ continue; } $user_details_query = mysqli_query($this->con,"SELECT first_name,last_name,profile_pic FROM users where username = '$added_by'"); $user_row = mysqli_fetch_array($user_details_query); $first_name = $user_row['first_name']; $last_name = $user_row['last_name']; $profile_pic= $user_row['profile_pic']; ///time stamp $date_time_now = date("Y-m-d H:i:s"); $start_date = new Date_Time($date_time);////Time_of_post $end_date = new Date_Time($date_time_now);///Current_time $intervel = $start_date->diff($end_date); if($intervel->y >< 1 ){ if($intervel ==1 ) $time_message = $intervel->y . " year ago";/// 1 Year Ago else $time_message = $intervel->y . " years ago"; //1+ year ago } else if($intervel-> m >= 1 ){ if($intervel->d == 0){ $days = " ago"; } else if($intervel->d == 1){ $days = $intervel->d."day ago"; } else { $days = $intervel->d."day ago"; } if($intervel->m == 1){ $time_message = $intervel->m." month".$days; } else $time_message = $intervel->m." months".$days; } } else if($intervel->d >= 1){ if($intervel->d == 1){ $days = "Yesterday"; } else { $days = $intervel->d."days ago"; } } else if($intervel->h >= 1){ if($intervel->h == 1){ $time_message = $intervel->h." hour ago"; } else { $time_message = $intervel->h." hours ago"; } } else if($intervel->i >= 1){ if($intervel->i == 1){ $time_message = $intervel->i." minute ago"; } else { $time_message = $intervel->i." minutes ago"; } } else{ if($intervel->s < 30){ $time_message = "Just Now"; } else { $time_message = $intervel->s." seconds ago"; } } $str .= "<div class='status_post'> <div calss='post_profile_pic'> <img src='$profile_pic' width='50'> </div> <div calss='posted_by' style='color#ACACAC;'> <a href = '$added_by'> $first_name $last_name </a> $user_to ; ; $time_message </div> <div id = 'post_body'$body<br></div> </div> " } echo $str; } } ?> When i run this code this show me the error Parse error: syntax error, unexpected 'public' (T_PUBLIC) in C:\xampp\htdocs\social\Classes\Post.php on line 39 the line 39 is public function loadPostsFriends() I check the code again and again but i cant find the error please help in this error 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. Can someone help with this error message when I had the @ sign in front of include (db connection etc) I was able to post to my db now I inserted the error_reporting to see why sessions was not going to next page welcoming the member I took out @ added in the error_reporting and get this message. Notice: Undefined index: submit in /home/ebermy5/public_html/form.php on line 9 line 9 is the if($_POST["submit"]){ below <?php include_once ("Connections/connect_to_mysql.php"); error_reporting(E_ALL); ini_set("display_errors", 1); $err=''; if($_POST["submit"]){ // Validate form data if($_POST["firstname"]=='') $err.='Please enter First Name<br>'; if($_POST["email"]=='') $err.='Please enter Email<br>'; if($err==''){ // Check if there are duplicate entries in the 'contacts' table $results = mysql_query("SELECT id FROM `Members` WHERE firstname='".addslashes($_POST["firstname"])."' and Email='".addslashes($_POST["email"])."'"); if($row = mysql_fetch_array($results)){ $err.='Can not add duplicate entry<br>'; } else{ // adding new record to 'contacts' table mysql_query("INSERT INTO Members (firstname,lastname,country,Email) values ('".addslashes($_POST["firstname"])."','".addslashes($_POST["lastname"])."','".addslashes($_POST["country"])."','".addslashes($_POST["email"])."')"); // redirecting to success screen if($results){ header("Location: login.php"); }else die(mysql_error()); } } } ?> <html> <head> <title>Add New Contact</title> </head> <body> <h2>Register with us</h2> <?php echo $err==''?'''<p style="color:red;">'.$err.'</p>') ?> <form method="post" action="form.php"> <table border="0"> <tr> <td valign="middle">First Name:</td> <td><input type="text" name="firstname" size="30" value="<?php echo htmlspecialchars($firstname) ?>"></td> </tr> <tr> <td valign="middle">Last Name:</td> <td><input type="text" name="lastname" size="30" value="<?php echo htmlspecialchars($lastname) ?>"></td> </tr> <tr> <td valign="middle">Country:</td> <td><input type="text" name="country" size="30" value="<?php echo htmlspecialchars($country) ?>"></td> </tr> <tr> <td valign="middle">Email:</td> <td><input type="text" name="email" size="30" value="<?php echo htmlspecialchars($email) ?>"></td> </tr> </table><br> <input type="submit" name="submit" value=" Submit! "> </form> </body> </html> this is my next page after the top information is added to the db. <?php session_start(); session_id(); ?> <!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>Welcome</title> </head> <body> <?php /* Program: login.php * Desc: Displays the new member welcome page. Greets * member by name and gives a choice to enter * restricted section or go back to main page. */ error_reporting(E_ALL); ini_set("display_errors", 1); $firstname = ''; $id = ''; if (isset($_SESSION['id'])) { $id = $_SESSION['id']; } else { echo "can not get id"; } include('Connections/connect_to_mysql.php'); $result = mysql_query("SELECT firstname FROM `Members` WHERE id=$id"); $row = mysql_fetch_array($result); if ($firstname == ''){ //condition, is name equal to lower case firstname notice we use == and not = echo "Welcome, $firstname"; } else { //so incase the condition is not as expected echo "Sorry you are not $firstname"; } ?> <p>Your new Member accounts lets you enter the members only section of our web site. You'll find special discounts, a profile of matches, live advise from experts, and much more.</p> <p>Your new Member ID and password were emailed to you. Store them carefully for future use.</p> <div style="text-align: center"> <p style="margin-top: .5in; font-weight: bold"> Glad you could join us!</p> <form action="profile.php" method="post"> <input type="submit" value="Enter the Members Only Section"> </form> <form action="index.php" method="post"> <input type="submit" value="Go to Main Page"> </form> </div> </body> </html> I am working on a video-hosting site, something akin to YouTube. I converted whatever MySQLi I had to PDO. This piece of particular code is responsible for checking if the fields are filled in; then proceeds to upload the files and inserts data into the database. The code jumps straight to the error I created which is "empty fields". The var_dump prints out as null all the way. I cannot seem to figure out where the problem lies. I would say it could be that the file is not set? I am not quite sure. Here is what the log gives me: [Sat Feb 16 00:19:35.575770 2019] [php7:warn] [pid 16239] [client 127.0.0.1:42504] PHP Warning: POST Content-Length of 12263648 bytes exceeds the limit of 8388608 bytes in Unknown on line 0, referer: http://localhost/soapbox/upload.php [Sat Feb 16 00:19:35.576769 2019] [php7:notice] [pid 16239] [client 127.0.0.1:42504] PHP Notice: Undefined index: video_title in /var/www/html/soapbox/upload.php on line 15, referer: http://localhost/soapbox/upload.php [Sat Feb 16 00:19:35.576805 2019] [php7:notice] [pid 16239] [client 127.0.0.1:42504] PHP Notice: Undefined index: textarea-videoDesc in /var/www/html/soapbox/upload.php on line 16, referer: http://localhost/soapbox/upload.php [Sat Feb 16 00:19:35.576811 2019] [php7:notice] [pid 16239] [client 127.0.0.1:42504] PHP Notice: Undefined index: videoFile in /var/www/html/soapbox/upload.php on line 22, referer: http://localhost/soapbox/upload.php [Sat Feb 16 00:19:35.576829 2019] [php7:notice] [pid 16239] [client 127.0.0.1:42504] PHP Notice: Undefined index: thumbnailImage in /var/www/html/soapbox/upload.php on line 51, referer: http://localhost/soapbox/upload.php [Sat Feb 16 00:19:35.576845 2019] [php7:notice] [pid 16239] [client 127.0.0.1:42504] PHP Notice: Undefined index: thumbnailImage in /var/www/html/soapbox/upload.php on line 52, referer: http://localhost/soapbox/upload.php [Sat Feb 16 00:19:35.576849 2019] [php7:notice] [pid 16239] [client 127.0.0.1:42504] PHP Notice: Undefined index: thumbnailImage in /var/www/html/soapbox/upload.php on line 53, referer: http://localhost/soapbox/upload.php [Sat Feb 16 00:19:35.576854 2019] [php7:notice] [pid 16239] [client 127.0.0.1:42504] PHP Notice: Undefined index: thumbnailImage in /var/www/html/soapbox/upload.php on line 54, referer: http://localhost/soapbox/upload.php [Sat Feb 16 00:19:35.576858 2019] [php7:notice] [pid 16239] [client 127.0.0.1:42504] PHP Notice: Undefined index: thumbnailImage in /var/www/html/soapbox/upload.php on line 55, referer: http://localhost/soapbox/upload.php [Sat Feb 16 00:19:35.576862 2019] [php7:notice] [pid 16239] [client 127.0.0.1:42504] PHP Notice: Undefined index: thumbnailImage in /var/www/html/soapbox/upload.php on line 56, referer: http://localhost/soapbox/upload.php I have changed the allotted sizes in the php.ini file, so that rules out the POST Content-Length problem, I think. Here are the "undefined indexes": $videoTitle = $_POST['video_title']; $videoDesc = $_POST['textarea-videoDesc']; $file = $_FILES['videoFile']; $thumbnailImageName = $_FILES['thumbnailImage']['name']; $thumbnailImageTmpName = $_FILES['thumbnailImage']['tmp_name']; $thumbnailImageSize = $_FILES['thumbnailImage']['size']; $thumbnailImageError = $_FILES['thumbnailImage']['error']; $thumbnailImageType = $_FILES['thumbnailImage']['type']; $thumbnailImageExt = explode('.', $thumbnailImageName); And the corresponding form names to go with them: <form action="upload.php" method="POST" enctype="multipart/form-data" multiple><br> <p>Video File:</p><input type="file" name="videoFile" id="fileToUpload"><br> <p>Thumbnail Image File: </p><input type="file" name="thumbnailImage"><br> <p>Video Title: </p><input type="text" name="video_title" id="videoTitle" placeholder="Video title"><br> <p>Video Description</p><textarea name="textarea-videoDesc" placeholder="Video description..." rows="7" style="resize: none;"></textarea><br> <br><input type="submit" name="uploadBtn" value="Upload"> </form>
Hello! I am a 17 year old beginner Php student and I am currently creating a page for which I would like to create a blog management admin interface. I went very well, I can already add the categories to the database, through the admin interface or I can list them on the website. However, there would be a problem with creating a Blog post. Because I use the same create () function as for adding a category, but unfortunately the Blog Post does not add to the database. I don't get any php error code just when I try to list the post id after the create function. Instead of a value of 1, I get a 0. I enclose the code of the blog post and its control, as well as the data of my database!
Blog Posting form admin html and php code (ujblogposzt.php) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<?php require_once('templates/head.php') ?> <!-- includes database and user controll -->
<?php include('app/controllers/posztok.php');?> <!-- Add new blog post controll file -->
<!-- Main content -->
<div class="card-footer">
</div>
<!-- bs-custom-file-input --> <?php require_once('templates/footer.php') ?>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Blogpost controll code (posztok.php)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<?php
if (isset($_POST['add-post'])) {
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- I see everything okay in these codes, because I add the category to the database in the same way when adding a category my function called dd is at the end of the line of code, it's just for checking, it shows results. my create() function seen like this:
function create($table, $data)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- The strange thing is that if I add 1-2 items to the database statically without php code, it is detected and displayed in the blog editing menu, but I can't add a post to the database via the admin interface itself, that's why I wrote here ! :) From testing, I also print the end result of the create function at the end of the control code, which should return an id, but instead of id 1 I get a value of 0 and the post doesn't added to the database after pressing the post button['add-post'] and unfortunately I can't figure out why it is ?! I also attach the pictures of the problem!
The pictures of my problem can be viewed he https://drive.google.com/drive/folders/1WTVNv4LlbJiosWvBZoIRzjiUDkvhMgYk?usp=sharing
Thanks to anyone in advance !!!
hi there, seems like I'm getting a fairly common beginners php error but as I'm using a number of differant files and as I'm not entirley clear on a couple of things I thought I'd tap into the immense php talent on this site here's the error - Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Epointment\index.php:4) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Epointment\ot\views\header.php on line 38 I have an index page that allows a user to log on, the processing go's away and checks the usual stuff then reloads the login page with the user detail or just reloads the login page with the user/password fields blank. This seemed to be working ok until I put my files onto another web server that had output_buffering turned off. here's part of the login page Code: [Select] <html> <head><title></title></head> <body> <?php ini_set("display_errors", "1"); error_reporting(-1); $dir = dirname(__FILE__); require_once "$dir/ot/ot.php"; ot::include_view('header', array('account' => null)) ?> // various stuff <p>Please login below</p> <?php ot::include_view('login_form')?> the ot.php file doesn't have any echo's or print_r's etc if that helps?? here's the header.php file.. <?php Code: [Select] if (ot::get('do_logout', 0) == 1) { ot::destroy_session(); header("Location: http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}"); exit; } elseif (self::post('do_reset_password')) { ot::do_reset_password($err); echo "$err"; } $adb = ot::db('account'); $account = null; $error = ""; $id = ot::account_id(); if ($id) { $account = ot::account_from('id', $id); $res = ot::do_change_password($account, $err); if ($res) { echo "<p>Password Changed Successfully</p>"; $account = $res; } else if ($err) { echo "<p>Error: $err</p>"; } $res = ot::do_change_email($account, $err); if ($res) { echo "<p>Email Changed Successfully</p>"; $account = $res; } else if ($err) { echo "<p>Error: $res</p>"; } } else { $account = ot::do_login(); if ($account) { header("Location: http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}"); exit; } } ?> here's the ot::do_login function Code: [Select] public static function do_login(&$err="") { $adb = ot::db('account'); $e = self::post('email'); $p = self::post('pwd', '', false); if (self::post('do_login') && $e && $p) { $ao = self::account_from('email', $e); if ($ao) { if (self::validate_login($e, $p, $ao)) { //echo "\n"."hit2"; $_SESSION['id'] = $ao->id; return $ao; } } $err = "Invalid email or password"; return false; } } and here's the login_form.php, which is called from ot::do_login from header.php ... Code: [Select] <form action='<?php echo $_SERVER['REQUEST_URI']?>' method='post' > <p>Email:<br/><input type='text' name='email' /></p> <p>Password:<br/><input type='password' name='pwd' /></p> <p><input type='submit' name='do_login' value='Login' /> <input type='submit' name='do_reset_password' value='Reset Password' /></p> </form> Any pointers or useful things I've not posted? is this bit of code from above ok? as in I'm doing some php stuff before the header() function gets used? Code: [Select] <html> <head><title></title></head> <body> <?php ini_set("display_errors", "1"); error_reporting(-1); $dir = dirname(__FILE__); require_once "$dir/ot/ot.php"; ot::include_view('header', array('account' => null)) i created an array like this while{ $ir = 0; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['id_sub']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['seminar_topic']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['seminar_mark']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['attendance']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['internal_mark']; $ir++; $stud[$row_mrk['id_sub']][$ir]=$row_mrk['external_mark']; $ir++; } echo "<input type='hidden' name='ar_std' id='ar_std' value='$stud' /> </table>" ; and it is able to print in the same page using foreach ($stud as $v1) { echo "$v1\n<br>"; foreach ($v1 as $v2) { echo "$v2\n<br>"; } } and in the next page $ar_stud[]=$_POST["ar_std"]; I'm getting an error PHP Warning: Invalid argument supplied for foreach() in save.php on line 25 PHP Stack trace: Hello together, I'm still relatively new with PHP and I'm encountering an error with the error code (Warning: Undefined array key "title" in I:\xampp\htdocs\test\Datenspeichern.php on line 13 to 17.). Normally I wanted that when I enter the data in the fields from the CD_Website page, that it is inserted in my created database and displayed in the table on the page. Does anyone know where my error is? Thanks a lot
main Code= <!doctype html> <html> <head> <meta charset="utf-8"> <title>Unbenanntes Dokument</title> <style type="text/css"> table { border-collaps: collapse; width: 100%; font-family: serif; font-size: 35px; text-align: center; } td { font-size: 25px; text-align: center; font-family: serif; } </style> </head> <body> <table> <tr> <th>CD-Titel</th> <th>Artist</th> <th>Songtitel</th> <th>Musiklänge</th> <th>Lied Nummer</th> </tr> <?php $host = "localhost"; $user = "root"; $password = ""; $db_name = "cdaufgabe"; $con = mysqli_connect($host, $user, $password, $db_name); if(mysqli_connect_error()) { die("Verbindungsabbruch mit der Datenbank: ". mysqli_connect_error()); }; $check = "SELECT * FROM `cd-titel`"; $result = mysqli_query($con, $check); if ($result > null) { while ($row = $result->fetch_assoc()){ echo "<tr><td>" . $row['CD-Titel'] . "</td> <td>" . $row['Artist'] . "</td> <td>" . $row['Songtitel'] . "</td> <td>" . $row['Musiklänge'] . "</td> <td>" . $row['Lied-Nummer'] . "</td></tr>"; }; }; /*if (isset($_POST['submitted'])) { $titel = $_POST['titel']; $artist = $_POST['artist']; $songtitel = $_POST['songtitel']; $musicle = $_POST['musicle']; $liednr = $_POST['liednr']; $data_add = "INSERT INTO cd-titel (CD-Titel, Artist, Songtitel, Musiklänge, Lied-Nummer) VALUES ('$titel', '$artist', '$songtitel', '$musicle', '$liednr')"; if (!mysqli_query($db_name, $data_add)) { die('Fehler beim einfügen von Daten'); } } */ // $data_add = "INSERT INTO `cd-titel` (`CD-Titel`, `Artist`, `Songtitel`, `Musiklänge`, `Lied-Nummer`) VALUES ('$titel', '$artist', '$songtitel', '$musicle', '$liednr')"; // mysqli_query($con, $data_add); /*mysqli_query($con, $data_add);*/ ?> <form methode="post" action="Datenspeichern.php"> <input type="text" name="titel" placeholder="CD-Titel"/> <input type="text" name="artist" placeholder="Artist"/> <input type="text" name="songtitel" placeholder="Songtitel"/> <input type="text" name="musicle" placeholder="Musiklänge"/> <input type="text" name="liednr" placeholder="Lied-Nummer"/> <input type="submit" name="submitted" value="speichern"/> </form> </br></br></br> </table> </body> </html> second code(Datenspeichern.php)= <?php $con = mysqli_connect('localhost', 'root', ''); if (!$con) { echo'Nicht verfügbar'; } if (!mysqli_select_db($con, 'cdaufgabe')){ echo 'Datenbank nicht ausgewählt'; }; $titel = $_POST['titel']; $artist = $_POST['artist']; $songtitel = $_POST['songtitel']; $musicle = $_POST['musicle']; $liednr = $_POST['liednr']; $data_add = "INSERT INTO cd-titel (CD-Titel, Artist, Songtitel, Musiklänge, Lied-Nummer) VALUES ('$titel', '$artist', '$songtitel', '$musicle', '$liednr')"; if (!mysqli_query($con, $data_add)){ echo 'Fehler'; } else { echo'Eingefügt'; }; header("url=CD_Webseite.php"); ?> Does anyone knows the mistake i keep doing? Hello there,
I am coding Arduino micro controller, and intended to GET the data from server MySQL db through php to turn ON/OFF LED. I could able to GET the data from manually updated MySQL db value, even I could able to successfully change the data of MySQL db from micro controller POST method. But I am getting error when trying to change the MySQL db value from browser using online POST tool, Following is PHP code at server 8 $api_key_value ="XXXXXXXXX";//Sample 9 $api_key =""; 10 $status = ""; 11 $id =""; 12 13 if ($_SERVER["REQUEST_METHOD"] == "POST") { 14 $api_key = test_input($_POST["api_key"]); 15 if($api_key == $api_key_value) { $id = test_input($_POST["id"]); $status = test_input($_POST["status"]); // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } //$sql = "INSERT INTO led (status) //VALUES ('" . $status . "')"; $sql = "UPDATE led SET status='$status' WHERE id='$id'"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); } else { echo "Wrong API Key provided."; } } else { echo "No data posted with HTTP POST."; } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } Post Command: http://url/MySQL_POST.php?api_key=XXXXXXXXX&id=1&status=on Response/Error: Notice: Undefined index: api_key in <PATH>/MySQL_POST.php on line 14 Wrong API Key provided. Could be a basic issue, but I am very new to php coding and cannot solve this problem yet. Could someone please help? Thanks. Hi, I have an HTML and a PHP script inserting data into DB. My problem is when i submit the form, one of the arrays cannot be posted to my PHP Script. The first SELECT-OPTION Values (mail_select[]) are being posted correctly, however the second SELECT-OPTION Values (OS[]) are not. It brings empty value at all. If i put OS[] SELECT TAG to first place, -i mean put it before mail_select[] SELECT TAG-, this time mail_select[] brings nothing. And OS[] is being posted correctly. What could the possible problems be? Here is the HTML: Code: [Select] bla..bla.. <html> <form id="SK" action="post.php" method="POST"> <tr> <td> <?php $conn = getConn(); mysql_select_db(getDBName(),$conn); $query = "select MEMBERS,NAME from mail;"; $result = mysql_query($query,$conn); echo "<form>"; echo "<select name=\"mail_select[]\" id=\"mail_select[]\" multiple=\"multiple\">"; while($row = mysql_fetch_array($result)) { $NAME = $row['NAME ']; $MEMBERS = $row['MEMBERS']; echo "<option value='$MEMBERS'>$NAME</option>"; } echo "</select></form>"; mysql_close($conn); ?> </td> </tr> <tr><td> <?php $conn = getConn(); mysql_select_db(getDBName(),$conn); $query = "select mark from olsystem;"; $result = mysql_query($query,$conn); echo "<form style=\"margin:20px 0\">"; echo "<select name=\"OS[]\" id=\"OS[]\" multiple=\"multiple\">"; while($row = mysql_fetch_array($result)) { $isim = $row['mark']; echo "<option value='$mark'>$mark</option>"; } echo "</select></form>"; mysql_close($conn); ?> </td> </tr> <tr height="40"><td width="170"><div class="rowElem"><input type="submit" value="GO!" /><input type="reset" value="Clear" /></div></td></tr> </form> </html> Here is my PHP script: Code: [Select] <?php include("DB.php"); if(isset($_POST['OS'])){ $OS = implode(",",$_POST['OS']); $mail_select = implode(",",$_POST['mail_select']); register($OS,$mail_select); } function register($OS,$mail_select) { $conn = getConn(); mysql_select_db(getDBName(),$conn); $query ="insert into outage(OS,mail_select) values ('$OS','$mail_select')"; mysql_query($query,$conn); if(mysql_affected_rows()>0){ BLA BLA } else { } mysql_close($conn); } ?> I had a wordpress site setup for my maintenance company. I am not trying to setup a blog on the site. I have the blogroll showing up on this page: http://handymore.com/blog/ but when you click the individual articles the single post page shows a Error 404 message. Could anyone point me in the right direction as to how to fix this so that the individual post pages are found? Any guidance would be appreciated. Hello Team, My job changed a few years back but I'm once again trying to learn to become better with php. I wanted to catch up to where I was around this time a few years back and honestly the language is coming back quickly but the quirky bottle-neck errors are still lingering. Hoping someone can take a look at the simple page I created below - post/get/session globals do not seem to be working, additionally, the semicolon after echo command does not seem to end the php command on the semicolon(displays everything). It may be a browser or something more simple but am hoping someone can at least look at my code below to see if there are any red flags.
<?php <h2>Campus Information</h2>
<form action="campus_test_form.php" method="get">
</body> |