PHP - I Want Insert Data In Database With "spaces ".
<?php require_once('upper.php'); require_once('database.php'); echo $error_msg=''; if(isset($_POST['submit'])) { $LoginId=mysqli_real_escape_string($dbc,trim($_POST['LoginId'])); $Password1=mysqli_real_escape_string($dbc,trim($_POST['Password1'])); $Password2=mysqli_real_escape_string($dbc,trim($_POST['Password2'])); $Name=mysqli_real_escape_string($dbc,trim($_POST['Name'])); $Age=mysqli_real_escape_string($dbc,trim($_POST['Age'])); $BloodGroup=mysqli_real_escape_string($dbc,trim($_POST['BloodGroup'])); if(!isset($_POST['Sex'])) { echo 'Please enter Sex<br>'; } else{ $Sex= mysqli_real_escape_string($dbc,trim($_POST['Sex'])); } $Qualification=mysqli_real_escape_string($dbc,trim($_POST['Qualification'])); $ContactNumber=mysqli_real_escape_string($dbc,trim($_POST['ContactNumber'])); $Email=mysqli_real_escape_string($dbc,trim($_POST['Email'])); $Address=mysqli_real_escape_string($dbc,trim($_POST['Address'])); $AboutYourself=mysqli_real_escape_string($dbc,trim($_POST['AboutYourself'])); //$countCheck=count($_POST['checkbox']); //echo $countCheck; //$checkbox=$_POST['checkbox']; //$countCheck=count($checkbox); if(empty($LoginId)){echo 'Please enter Login Id';} elseif(empty($Password1)){echo 'Please enter Password';} elseif(empty($Password2)){echo 'Please confirm Password';} elseif($Password1!==$Password2){echo 'Password didn\'t match';} elseif(empty($Name)){echo 'Please enter Name';} elseif(empty($Age)){echo 'Please enter Age';} elseif(!isset($_POST['Sex'])){} elseif(empty($Qualification)){echo 'Please enter Qualification';} elseif(empty($ContactNumber)){echo 'Please enter Contact Number';} elseif(empty($Email)){echo 'Please enter Email';} elseif(empty($Address)){echo 'Please enter Address';} elseif(empty($AboutYourself)){echo 'Please enter About Yourself';} elseif(!isset($_POST['checkbox'])){ echo 'You have to register at least one activity.';} else { require_once('database.php'); $query="select * from registration where LoginId='$LoginId'"; $result=mysqli_query($dbc,$query); if(mysqli_num_rows($result)==0) { $checkbox=$_POST['checkbox']; $countCheck=count($_POST['checkbox']); $reg_id=' '; for($i=0;$i<$countCheck;$i++) { $reg_id=$reg_id.$checkbox[$i].','; } $query="insert into registration (LoginId,Password,Name,Age,BloodGroup,Sex,Qualification,ContactNumber,Email,Address,AboutYourself,Activity)values ('$LoginId',SHA('$Password1'),'$Name','$Age','$BloodGroup','$Sex','$Qualification','$ContactNumber','$Email','$Address','$AboutYourself',',$reg_id')"; $result=mysqli_query($dbc,$query) or die("Not Connect"); echo ' Dear '.$Name.'.<br>Your Account is waiting for approval<br>'; //header('Location: index.php'); // header('Location: Registration.php'); } else { echo 'Dear '.$Name. ', <br> An account already exist with login-id<b> '.$LoginId.'</b> <br>Please try another login-id'; }} } ?> <html> <body> <?php echo $error_msg; ?> <form action='<?php echo $_SERVER['PHP_SELF'];?>' method='post'> <div class="registration_and_activity"> <table border="0" width="400"> <tr><td colspan="2"> <h3>New User?</h3></td></tr> <tr><td width="120"> Enter Login id</td><td><input type='text' name='LoginId' value='<?php if(!empty($LoginId))echo $LoginId;?>' /></td></tr> <tr><td> Enter Password</td><td><input type='password' name='Password1' value='<?php if(!empty($Password1))echo $Password1;?>' /></td></tr> <tr><td> Confirm Password</td><td><input type='password' name='Password2' value='<?php if(!empty($Password2))echo $Password2;?>' /></td></tr> <tr><td> Enter Name</td> <td><input type='text' name='Name' value='<?php if(!empty($Name))echo $Name;?>' /></td></tr> <tr><td> Enter Age</td><HEAD> <SCRIPT language=Javascript> function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; } </SCRIPT> </HEAD> <td><INPUT onkeypress='return isNumberKey(event)' type='text' name='Age' value='<?php if(!empty($Age))echo $Age;?>'/></td></tr> <tr><td> Enter Blood</td><td><input type='text' name='BloodGroup'value='<?php if(!empty($BloodGroup))echo $BloodGroup;?>' /></td></tr> <tr><td> Enter Sex</td><td><input type='radio' name='Sex' style='width:16px; border:0;' 'value='Male' />Male <input type='radio' name='Sex' style='width:16px; border:0;' 'value='Female' />Female</td></tr> <tr><td> Enter Qualification</td><td><input type='text' name='Qualification' value='<?php if(!empty($Qualification))echo $Qualification;?>' /></td></tr> <tr><td> Enter Contact Number </td><td><input onkeypress='return isNumberKey(event)'type='text' name='ContactNumber' value='<?php if(!empty($ContactNumber))echo $ContactNumber;?>' /></td></tr> <tr><td> Enter Email</td><td><input type='text' name='Email' value='<?php if(!empty($Email))echo $Email;?>' /></td></tr> <tr><td> Enter Address</td><td><input type='text' name='Address' value='<?php if(!empty($Address))echo $Address;?>' /></td></tr> <tr><td> About Yourself :</td></tr> <tr><td colspan="2"><textarea rows='10' cols='40' name='AboutYourself' value='<?php if(!empty($AboutYourself))echo $AboutYourself;?>' /></textarea></td></tr> <tr><td> <?php echo" <tr><td colspan='2'><b>Select fields for which you want to register</b></td></tr>"; require_once('database.php'); $query="select * from activity"; $result=mysqli_query($dbc,$query); while($row=mysqli_fetch_array($result)){ $Title=$row['Title']; $ActivityId=$row['ActivityId']; echo "<tr><td>$Title</td>"; //echo $ActivityId; [B]echo "<td><input type='checkbox' name='checkbox[]' value=$Title [/B]style='width:14px; text-align:right;'/></td></tr>";//value=$ActivityId tells ActivityId variable extracts with name="checkbox" echo "<br/>"; } echo "<tr><td colspan='2' align='center'><input type='submit' value='Register' name='submit' style='background:url(./images/button_img2.png) no-repeat 10px 0px; width:100px; padding:3px 0 10px 0; color:#FEFBC4; border:0;'/></td></tr><br>"; echo " </td></tr></table> </div> </form> </body> </html>"; require_once('lower.php'); ?> In above code when $Title="Fire" or any single word, it inserts in database properly but when $Title="Terrist Attack" or any data more than one word it inserts only the first word "Terrist". I want to insert the whole "Terrist Attack " as it is in database......... What i should do??????????/ Plzzzzzzzzzzz help Anyone???????????? Similar TutorialsCan someone please help me with an array problem i can not figure out. I need the array to be numbered from 1 to how ever many fields that are needed in the form and have a mysql field name and the title of the field also in the array. 1, "mysql_field_name", "Title of form field" 2, "", "" and so on then the form will be shown based on the array. I have the following draft code which I am working with. any suggestions on how i may do this array ? Code: [Select] <?php $options = array( '1'=> array('fieldtext'=>'option1', 'mysqlfield'=>'option1'), '2'=> array('fieldtext'=>'option2', 'mysqlfield'=>'option2'), '3'=> array('fieldtext'=>'option3', 'mysqlfield'=>'option3'), '4'=> array('fieldtext'=>'option4', 'mysqlfield'=>'option4'), ); // $options = array(1 => "option1", "option2", "option3", "option4"); // the line above works but i want to include the name of the mysql field as well. $userid = 1; ?> <div style="align: center; margin: 12px; font-family:Tahoma;"> <br><br><?php if ($_POST['Update'] != "Update") { // check if form submitted yet, if not get data from mysql. $res = db_query("SELECT * FROM `users` WHERE `userid` = '" . $userid . "'"); foreach($options as $key => $value) { $_POST[$key] = mysql_result($res, 0, $value); } $ok_to_update = "no"; } elseif ($_POST['Update'] == "Update") { // check if form submitted yet, if so get POST data. // error checking // foreach($options as $key => $value) { // $_POST[$i] = ""; // } $ok_to_update = "yes"; } if ($_POST['Update'] == "Update" && $ok_to_update == "yes") { // $res = db_query("INSERT INTO `users` () VALUES ()"); // add user details to database. ?><p><br><br><br>Thank you for updating</p><?php } else { ?><form name="form1" method="post" action=""> <?php foreach($options as $key => $value) { ?><p><?php echo($value); ?>: <input type="text" name="<?php echo($key); ?>" value="<?php echo($_POST[$key]);?>"></p> <?php } ?> <input name="Update" type="submit" value="Update"> </form> <?php } ?> </div> ...added to an error log? Currently, my coding is as follows: Form to gather data: Code: [Select] <html><head><title>Car Accident Report Form</title></head> <form action="errorlog.php" method="post"> First Name: <br><input type="text" name="name"><br> Surname:<br> <input type="text" name="surname"><br> Age: <br><input type="text" name="age"><br> Weeks Since Accident: <br><input type="text" name="weeks"><br> <input type="submit" value="Submit"> </form> Coding for error log: Code: [Select] <html><head><title>Validating Car Accident Report Form Details</title></head> <?php $name=$_POST["name"]; $surname=$_POST["surname"]; $age=$_POST["age"]; $weeks=$_POST["weeks"]; $subtime = strftime('%c'); $pass = "The details uploaded are fine<br><br>"; if ((((trim($name)="" && trim($surname)="" && trim($age)="" && trim($weeks)="")))) { echo "It seems that you have not entered a value for the Name, Surname, Age or Weeks fields. This has been added to the error log.<br><br>"; error_log("<b><u>Error</b></u><br>The user has not entered any values", 3, "C:/xampp/htdocs/errorlog.txt"); } if (($age<18)&& ($weeks<=1)) { echo "It seems that you have entered an invalid age and number of weeks since the accident. This has been added to the error log.<br><br>"; error_log("<b><u>Error</b></u><br>The user has entered an age that is below 18 and the number of weeks since the accident is equal to or under 1 week!<br>Age entered:" . $age . "<br>Number Of Weeks Since Accident entered:" . $weeks . "<br>Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else if ($age<18) { echo "It seems that you have entered an invalid age. This has been added to the error log.<br><br>"; error_log("<b><u>Age Error</b></u><br>The user has entered an age that is below 18!<br>Age entered:" . $age . "<br>Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else if ($weeks<=1) { echo "It seems that you have entered an invalid age number of weeks since the accident. This has been added to the error log.<br><br>"; error_log("<b><u>Week Error</b></u><br>The user has entered a number of weeks since the accident that is equal to or under 1 week!<br>Number Of Weeks Since Accident entered:" . $weeks . "<br> Time that form was submitted:" . $subtime . "<br><br>", 3, "C:/xampp/htdocs/errorlog.txt"); } else { echo $pass; } echo "Car Accident Report Form details have been sent<br>"; echo "<a href='readlog.php'>Read Error Log</a>" ?> </html> How can I get it so that if a user presses the space bar in a field, then the trim function sees that there's no white space and then this gets added to the error log? Any help is appreciated! Using php, how can I replace spaces with hyphens (-) but only do this for the text within the title="" attribute of a specific set of links? Example: I have 2 sets of links and i want to replace the spaces within the title="" attribute but only on the links in the second div, not the first. Code: [Select] <div class="set1"> <a href="#" title="THIS IS THE TITLE"> <a href="#" title="THIS IS THE TITLE"> </div> <div class="set2"> <a href="#" title="THIS IS THE TITLE"> <a href="#" title="THIS IS THE TITLE"> </div> Is this possible? would like it to look like this: Code: [Select] <div class="set2"> <a href="#" title="THIS-IS-THE-TITLE"> <a href="#" title="THIS-IS-THE-TITLE"> </div> Hi, bit stuck on how to find and replace "<" and ">" with "<" and ">". I basically have a database record that outputs to screen and I need the code in the <code> tags to be rendered to the screen. I therefore need it to go through the whole array variable from the db and change the symbols just inside the code tags. Please be aware that the code tags might happen more than once here's an example below Code: [Select] <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> the desired output would be: <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> help on this would be great Cheers Rob Hello, I'm having a bit of a problem here, all help to this issues would be much appreciated I am trying to use text boxes to insert numbers into the database based on what is inputed. If I have a string, like this for example: $variable = 09385493; And I want to insert it into the database like this: mysql_query("INSERT INTO integers(number) VALUES ('$variable')"); When checking the integers table in my database, looking at the number field, the $variable that was inserted is outputted as 9385493 Notice the number zero was taken out of the front of the number. If the number is double 0's (009385493), both of those zero's would disappear, too. Thanks Hi guys I am a newbie with PHP and I have been trying to solve this problem for 3 days.. Ive set up a booking form on my website to be sent directly to my email once the client clicked on the send button.. The problem I am having while checking these pages on wamp is that the booking form is ok but when I click on the send button the following message error appears "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\fluffy_paws\booking_form2.php on line 27" When I check online I have this message "500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed." Are my codes wrong??? My webhosting is Blacknight.com , Im on Windows Vista, my internet is a dongle with O2 ireland Thanks for your help! I have a field in my database called `intro` In this field the user has entered spaces, different paragraphs and "" When it was entered into the field it was run through trim and mysql_real_escape_string. when its echoed I am just using echo "member['intro']; How do I make it display like it was entered? Is there a function for this? Hi guys I'm struggling a bit, I need to replace a word that occurs multiple times in text with an array("up","down","forward","backwards") of words. $find = "left"; $replace = array("up","down","forward","backwards"); $text = "left left left left"; echo str_replace($find,$replace,$text); The Output is: array array array array Did try this with a foreach statement as well, but no luck. Is there a better way of doing this? Thanks cant work out this mysql syntax error "operation":"medupdate","medid":"","name":"ibo","medyear":"5","medmonth":"21","medday":"1","recuser":1,"SuccFail":"fail","SuccFailMessage":"error occured 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 med_id=' at line 2","ResultData":""} Code: [Select] $sql="update metodology set med_description='".$req['name']."', med_year='".$req['medyear']."', med_month='".$req['medmonth']."', med_day='".$req['medday']."', med_recorddate= now(), med_recorduserid= 1'"; $sql.= " WHERE med_id=".$req['medid']; I want to do an sql query, but I want it to happen only after my user has clicked on a confirmation link. The link will be sent to their email address. What is the usual procedure for this? For the time being Ive chucked what ive got into 1 php file, but I pressume I will need a couple of php files, and some how pass some variables from 1 page to the next??? $first = $_GET['first']; $last = $_GET['last']; $age = $_GET['age']; $$emailad = $_GET ['emailad'] $query =mysql_query ("INSERT INTO treesurgeons (FirstName, LastName, Age) VALUES ('$first', '$last', '$age')"); echo mysql_error(); echo "<p>Thankyou for submiting your details.\r\n Please check your inbox and click on your confirmation link.</p>"; $message = "The following details have been submited to the tree directory and are awaiting confirmation; $first $last, $age. \r\n Please click on the link below to confirm these details are correct"; //Do I include a link to an html file or php file? $subject = "Your tree directory details"; $to = "$email"; $email = "$emailad"; mail( "$to", "$subject","$message", "$headers"); //How do I trigger this email upon confirmation ?></body></html> An insert function is not inserting. I keep getting "Could not store data, please try again." After some probing, it seems that "$result = $conn->query($user_degree_insert_query); " is where the problem is. Variables before it seem to pass testing. I can't figure out why this line is messing thins up though. Any idea? Thank you in advance for your help! The "//$degree_id = mysql_fetch_array($degree_id_query, MYSQL_BOTH) ;" is commented out because it was giving me trouble, i replaced it with the line above that $conn = db_connect(); $arraycount = count($degree_Array); //loop through the categories chosen and add them each into member-category for($i =0; $i < $arraycount; $i++){ $degree_id_query = "SELECT degree_id FROM degree WHERE degree_type ='".$degree_Array[$i]."'"; $result = $conn->query($degree_id_query); //place the id found into the array, which automatically cancatonates it. $degree_id = $result->fetch_array(); //$degree_id = mysql_fetch_array($degree_id_query, MYSQL_BOTH) ; $user_degree_insert_query = "INSERT INTO user-degree ( `user_id` , `degree_id` ) VALUES ( '".$user_id."', '".$degree_id[0]."' )"; $result = $conn->query($user_degree_insert_query); if($result) { header("Location: survey2.php"); }else { echo "<p>Could not store data, please try again.</p>"; exit; I am getting the following error when using composer: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? Just started. I am pretty sure composer.json wasn't changed. journalctl doesn't show anything. Maybe Doctrine related, however, nothing seems to help.
Any ideas? [michael@devserver www]$ php -v PHP 7.3.4 (cli) (built: Apr 2 2019 13:48:50) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.4, Copyright (c) 1998-2018 Zend Technologies with DBG v9.1.9, (C) 2000,2018, by Dmitri Dmitrienko [michael@devserver www]$ composer -V Composer version 1.4.2 2017-05-17 08:17:52 [michael@devserver www]$ yum info composer Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.us.oneandone.net * epel: mirror.rnet.missouri.edu * extras: mirror.us.oneandone.net * remi-php73: mirror.bebout.net * remi-safe: mirror.bebout.net * updates: mirror.us.oneandone.net Installed Packages Name : composer Arch : noarch Version : 1.8.4 Release : 1.el7 Size : 1.8 M Repo : installed From repo : epel Summary : Dependency Manager for PHP URL : https://getcomposer.org/ License : MIT Description : Composer helps you declare, manage and install dependencies of PHP projects, : ensuring you have the right stack everywhere. : : Documentation: https://getcomposer.org/doc/ [michael@devserver www]$ composer update Loading composer repositories with package information Updating dependencies (including require-dev) [ErrorException] "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [<packages>]... [michael@devserver www]$
This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=318175.0 I've been trying to simplify this code, let alone make it work. It's a loop to change the different question checkboxes to "checked" if certain degree_ids are found. All of the examples i have looked at are very strange and I'm not sure how to go about this, thought it seems to be a common question. Everyone seems to have their own way. Any advice would be greatly appreciated. for($i =1; $i <= $arraycount; $i++){ $query = "SELECT degree_id FROM `user-degree` WHERE `user_id` = '".$user_id."' AND degree_id = '".$i."'"; $result = $conn->query($query) or die(mysql_error()); $row = mysqli_fetch_array($result) ; echo $row['degree_id']; if(!$y){ $y = 0; } if ($row['degree_id'] == 1){ $q4[0] = 'checked'; } if ($row['degree_id'] == 2){ $q4[1] = 'checked'; } if ($row['degree_id'] == 3){ $q4[2] = 'checked'; } if ($row['degree_id'] == 4){ $q4[3] = 'checked'; } if ($row['degree_id'] == 5){ $q4[4] = 'checked'; } if ($row['degree_id'] == 6){ $q4[5] = 'checked'; } if ($row['degree_id'] == 7){ $q4[6] = 'checked'; } if ($row['degree_id'] == 8){ $q4[7] = 'checked'; } if ($row['degree_id'] == 9){ $q4[8] = 'checked'; } } I am currently creating a form and I want to populate a drop down selection menu with data from two fields in a form. For example, I want it to pull the first and last name fields from a database to populate names in a drop down menu in a form. I want the form to submit to the email address of the person selected in the drop down. Is this possible to do? The email is already a field in the record of the person in the database. Can anyone give me some pointers or advice on how I should go about setting up the "Select" box drop down? I am not sure how to code it to do what I am wanting. Any links to relevant help would be appreciated too. Thanks in advance! "BACK" or REFRESH: Preventing database interaction / code execution how to prevent database interaction / code execution when user presses back or refresh button? can i detect? can i disable back/refresh? Hello All, I have a custom session.set_save_handler to handler sessions for my application. It seems to work fine. The database table is of type innodb. I see some errors in my log file of the nature, "(1205) Lock wait timeout exceeded; try restarting transaction". I have a class which contains the session handler callbacks and have made it a singleton class. session_set_save_handler( array($this, "db_open"), array($this, "db_close"), array($this, "db_read"), array($this, "db_write"), array($this, "db_destroy"), array($this, "db_gc") ); In my "db_read" method, I am doing a "SELECT FOR UPDATE" on the row with the session id. So, while performing load testing on my app. which has a lot of ajax calls, I noticed the "lock wait timeout" errors. How do I resolve this problem? Any suggestions? 1) Should I catch these errors and issue a explicit "commit" in the read or write methods? 2) Should I specify a higher timeout value for "innodb_lock_wait_timeout"? Thanks I am creating a new forum software known as Iforum, it will use php and a database. I just started this yesterday and I all ready have the registration/login system up and working as well as connected to the database. I have selected the CKeditor for my forum (I was initially thinking of using the TinyMCE editor) I can't seem to figure out how when you click the "Post New Thread Button" How to send the information to the database and then carry the user back to the thread. (I am good with php, html, and CSS but I am not great with databases Any suggestions? I am having problems being able to find the data that needs to be posted in various translation websites. I think this is because the translation tools they have are using some kind of flash script to translate? So the new page isn't being loaded using the post data string?? I am not completely sure, anyways... I am using live http headers on firefox to try and get the content for the post data string. The sites I have tried to get the post data from are these: http://www.freetranslation.com/ http://www.free-translator.com/ I can get cURL to visit the page and do everything, I just cant find the post data string. or maybe I am way off here.. Thanks for any help Hi People. I run the following airfield site http://www.microlight.co Now on each airfield card there is a google iframe image that is held in the database and shows OK on the page. Anyone got any idea how I can get a hold of the co-ordinate information for each card so that I can display it somewhere else on screen? Here is a typical image of the airfield I use. Code: [Select] <iframe width="700" height="700" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://www.google.co.uk/maps?ie=UTF8&t=h&ll=53.952058,-1.17631&spn=0.008839,0.014999&z=16&output=embed"></iframe><br /><small><a href="http://www.google.co.uk/maps?ie=UTF8&t=h&ll=53.952058,-1.17631&spn=0.008839,0.014999&z=16&source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small> |