PHP - Db Returns Truncated Values When Hit A Spaces
Hi, the problem that I have goes like this. If i do a regular Select query and display it in a table everything is there but if i am filling a input box of a form to use for modifying the values it does not return the entire value:
Exemple with the same value in a table = product_name : Amd Athlon X2 In input field : Amd Here is my code Code: [Select] <? $sql = "SELECT * FROM tbl_product WHERE product_code = '$_POST[productcode]'"; $result = mysql_query($sql); if(!$result){ die("Error running $sql:" . mysql_error()); } ?> <? while($row = mysql_fetch_array($result)) { echo " <form action='functions/moditem.php' method='post'> <input type='hidden' name='productid' value=". $row['product_id'] ."> Product code : <input type='text' name='productcode' value=". $row['product_code'] ." /><br /> Product Name : <input type='text' name='productname' value=". $row['product_name'] ." /><br /> Product Price: <input type='text' name='productprice' value=". $row['product_price'] ." /><br /> <input type='submit' value='Modify' /> </form> "; } Similar TutorialsHello I am on to OOP now and I dont know how to write the syntax to print the results I want The scenario is I have the abstract class, its subclass and then the object that calls the subclass, all in different files. So: part of the subclass reads: Code: [Select] function __construct($v1, $v2, $v3) { $this->speed[] = $v1; // I dont like this either, it is not elegant. I tried to put an array as argument of the constructor and send the parameters $this->speed[] = $v2; // from the object being created, but it did not work, so I leave it like this for now, but I would have preferred to put that $this->speed[] = $v3; // array and then populate it by some looping. } // METHOD TO REPORT TABLE OF ACCELERATION public function acceleration() { return $this->acceleration1 = ($this->speed[1] - $this->speed[0])/5; // I actually need to return the other two speed differences from the other stages, but as you know, once the first return acts, it exits the function // so sure this "return" has to be abandoned and the results of the function have to be printed otherwise. That is the question. } =================================== And now from the Object file I am trying to call the function, but of course, I only get one value, even if I write 3 times return Code: [Select] $objeto = new Motorbike($v1, $v2, $v3); echo '<p>The speeds are ' . $objeto->acceleration() . '</p>'; // Yes, this call works, of course, but that is about it. I cant print any other result. Thanks a lot I have some data that when I type in a string in a text box, (e.g. John Smith), the data is trunctated when it is inserted into the database (only 'John; would show up). I noticed that it seems to cut the data off after a white space. If I combine the words, then they are inserted properly. Does this sound like something simple I'm missing or is it something more complex? The text size is 20 and the db field is Varchar 30. Any help would be appreciated. Thanks. Hello PHP geniuses, I'm having a bit of trouble here. I've built a WYSIWYG e-mail editor with the help of TinyMCE. I'm using a textarea to pull the innerHTML from the iframe where the actual editor is. The textarea will be hidden in production, but it's shown now for debugging reasons. I have a JS function that grabs the HTML from the iframe and puts it into the textarea, and this works great. The entire HTML gets populated in the textarea. When I go to save the e-mail (using a simple query that posts it and sends it straight to the database). The HTML is truncated in the database field to around ~255 characters. (it varies depending on what I have in there, but it's usually between 252 and 255) I really can't figure out why this would be cutting off like this. I've looked everywhere, I don't know what else to do. I wanted to add that the field is a text field in the database, that was the first and most obvious thing to check. I can confirm that my database holds the full text no problem. I can go into phpMyAdmin and copy+paste infinite amounts of data into the html field and it saves it without an issue. Thank you as always <3 If you need more information to help me, I will provide whatever helps. need your suggestion here is my problem i have field varchar(1000) in my sql server 2008 DB but if i mssql_fetch_object($result) my field value truncated and only show 256 character, why ? in my DB . my field value really 1000 character long . Hi Guys, My 2nd issue with my new blog is that the code used to limit the amount of content displayed from each post, is on occasion truncating the closing html tags along with the excess text! Very often this will result in any following posts being entirely italic or bold, which as you can imagine looks ridiculous. The Code that limits the content: # Limit Post function the_content_limit($max_char, $more_link_text = '', $stripteaser = 0, $more_file = '') { $content = get_the_content($more_link_text, $stripteaser, $more_file); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); $content = strip_tags($content, '<h1>,<h2>,<h3>,<strong>,<em>, '); if (strlen($_GET['p']) > 0) { I'd be very grateful if someone could help me out with this. Thanks Steve Hello, i have a query that returns the rows of certain parts of a databse. i made a button on the end of each echo, to make sure that, the button being printed with each echo, correlates to that echo. However, the SESSIONS only return the same varaibles each time. The last in the list. $sql = "SELECT p.Title, p.PerfDate, p.PerfTime FROM performance AS p INNER JOIN production AS r ON p.Title = r.Title"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo '<tr> <td>'.$row['Title'].'</td> <td>'.$row['PerfDate'].'</td> <td>'.$row['PerfTime'].'</td> <td><button name="availability" value="'.$row['Title'].'">Availability</button></td> </tr>'; $_SESSION["Title"] = $row['Title']; $_SESSION["PerfDate"] = $row['PerfDate']; $_SESSION["PerfTime"] = $row['PerfTime']; } } else { echo "0 results"; } $_SESSION["name"] = $_GET["name"]; ?> How am i able to make it so each button correlates to each row?
There's a screenshot of how it looks for reference Edited December 8, 2019 by AdamSteele I'm getting frusted over an if else statememt that won't work. It is calling one variable from the table. If the variable is in the table it will display one thing, if the variable is absent, it should display something else. I've tried !empty, isset, even $num_rows =1, but the content in the else doesn't display. Here's the code: Code: [Select] <? $result = mysql_query( "SELECT * FROM codeWords WHERE Mycode = '$MyCode' " ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); while ($row = mysql_fetch_array($result)) { extract($row); if (!empty( $MyCode )) { echo "here is the code word"; } else { echo "you need to go back and get the code"; } $row_count++; } mysql_close; ?> When the code variable is correct the "here is the code word" displays. when the code variable is incorrect, what should appear as "you need to go back and get the code" is just blank. Any thoughts on how to structure the query in such a way that eh incorrect text appears? Thanks, im not new enough for this to take so long to figure out, but for some reason $rs = mysql_query("SELECT * FROM cl"); returns the last record instead of all the records in the table. anyone know why it wouldnt take everything? I'm hoping someone can help me cos my hair's going white with this one. I'm trying to put together a script that acts as web-based interface to an SQL server. There are actually two parts, admin.htm and admin.php. The first part is just a form that passes login credentials to the PHP file. That part seems to work fine, but I'll post the source anyway: - Code: [Select] <!DOCTYPE HTML> <html lang="en"> <head> <title>SQL admin login</title> <meta charset="iso-8859-1" /> </head> <body> <form action="admin.php" method="post"> <label for="username">Username: -</label> <br /> <input type="text" name="username" id="username" /> <br /> <br /> <label for="password">Password: -</label> <br /> <input type="password" name="password" id="password" /> <br /> <br /> <label for="server">Server: -</label> <br /> <input type="text" name="server" id="server" /> <br /> <br /> <label for="database">Database: -</label> <br /> <input type="text" name="database" id="database" /> <br /> <br /> <input type="submit" value="Login" /> <input type="reset" value="Reset" /> </form> </body> </html> Following is the content of admin.php. By this point I can see the connection in MySQL Workbench, and when I submit the query 'SELECT * FROM subscribers' it's being stored in '$_POST['query']', but 'mysql_query($_POST['query'],$_SESSION['con']);' is returning nothing. There is definitely a record in that table, and the user I'm logging on with has permission to run the 'SELECT' command against this database, so I can't figure out why mysql_query(); is returning nothing: - Code: [Select] <!DOCTYPE HTML> <?php session_start(); if(!$_SESSION['con']) { if(!($_POST['username'] || $_POST['password'])) { if(!($_SESSION['username'] || $_SESSION['password'])) { $error="Username and password variables empty."; } } else { $_SESSION['username']=mysql_real_escape_string($_POST['username']); $_SESSION['password']=mysql_real_escape_string($_POST['password']); $_SESSION['server']=mysql_real_escape_string($_POST['server']); $_SESSION['database']=mysql_real_escape_string($_POST['database']); $_SESSION['con']=mysql_pconnect($_SESSION['server'],$_SESSION['username'],$_SESSION['password']); if(!$_SESSION['con']) { $error="Failed to connect to server."; } else { $database=mysql_select_db($_SESSION['database'],$_SESSION['con']); if(!$database) { $error="Failed to connect to database."; } } } } if(!$_POST['query']) { $error="No query submitted."; } else { $result=mysql_query($_POST['query'],$_SESSION['con']); if(!$result) { $error="Query returned nothing."; } } ?> <html lang="en"> <head> <title>SQL admin interface</title> <meta charset="iso-8859-1" /> </head> <body> <form action="admin.php" method="post"> <textarea name="query" rows="10" cols="50">SELECT * FROM subscribers</textarea> <br /> <br /> <input type="submit" value="Submit query" /> </form> <?php if($error) { echo $_POST['query']."<br /><br />".$result."<br /><br />".$error; die(); } else { while($row=mysql_fetch_assoc($result)) { echo $row['name']." ".$row['email']; echo "<br />"; } } ?> </body> </html> Can anyone help? MOD EDIT: [code] . . . [/code] tags added. this is supposed to display the distinct first two characters of a string(billnmbr) in a combobox ive tried this on phpmyadmin and it returns 08.. which is correct when i run this on my server, it returns nothing.. there must be something wrong with the way i called the billnmbr does anybody have an idea on how i could call and display this correctly? thanks and have a nice day. <?php $mquery = "select distinct(substring(`billnmbr`, 1, 2)) from `tbltest`"; $mres =mysql_query($mquery) or die(mysql_error()); while($mrow=mysql_fetch_array($mres)){ $mm = $mrow['billnmbr']; echo "<option value=" . $mrow['billnmbr'] . ">"; echo $mrow['billnmbr'] . "</option>"; } echo " </select>"; ?> Hi, I am trying to expand my very limited PHP by building a CMS. It's all new to me so please be courteous with your replies ? I little history of my problem. I am running xampp on a windows 10 running php 5.6.38
I have taken two video courses and on each I got stumped halfway through with a very similar problem. I am copying everything word for word and even downloaded the course file on the first one and still got the same problem so I'm wondering if there is something wrong with my setup - config?.
The problem.
This is the code: <?php error_reporting(E_ALL); ini_set('display_errors',1); include("includes/database.php"); include("includes/header.php"); if ($connection) { echo "Great, we're connected to the database<br><br>"; }else { echo "Bummer, it didn't connect to the database!"; } $query = "SELECT * FROM categories"; $result_set = mysqli_query($connection, $query) ; if (!$result_set) { die("Query Failed".msqli_error($connection)); } while ($row = mysqli_fetch_array($result_set)) { echo $row['cat_title']; } var_dump($result_set); ?>
Great, we're connected to the database object(mysqli_result)#3 (5) { ["current_field"]=> int(0) ["field_count"]=> int(2) ["lengths"]=> NULL ["num_rows"]=> int(0) ["type"]=> int(0) }
Question:
Thanks for your help. When you do a search at (right sidebar): http://ourneighborhooddirectory.org the $_GET result is always blank. The site is hosted at Bluehost and this is a Wordpress site. You can see the result of the query because I write them out. Here is the form code: Code: [Select] <form method="get" action="http://ourneighborhooddirectory.org/search-results/" > Search the Directory: <input type="text" name="srch"/> <input type="submit" value="Search" /> </form> Here is the PHP code on the action page: <?php $srchVal = $_GET["srch"]; echo $_GET['srch']; echo "------------ ". $srchVal." ------------"; print_r($_GET); echo $_SERVER['QUERY_STRING']; ?> Any ideas on why $_POST and $_GET always return blank? Thanks for the help... Hi i am running a wamp server on windows 7 i am trying to php exec command to run a command but the output returns 1 does this mean the cmd failed to execute ? Code: [Select] $openssl_cmd = "($OPENSSL mime -sign -signer $MY_CERT_FILE -inkey $MY_KEY_FILE ". "-outform der -nodetach -binary <<_EOF_\n$data\n_EOF_\n) | " . "$OPENSSL smime"." -encrypt -des3 -binary -outform pem $PAYPAL_CERT_FILE"; Me again.. I'm fetching data from MySQL but each person in people.php is displayed two times instead one.. The issue must be inside models_category_tbl table, because each person have more then one result. Any advice is appreciated. What should I do? I would like to display people something like that: 1 John Doe 1 IT developer, 3 mechanic models/model = person category = occupation/skills MySQL: model_index table +---------+------------+-------------+-------------------+---------------+----------------+ |model_id | model_name | model_title | model_description | model_country | model_slug | +---------+------------+-------------+-------------------+---------------+----------------+ | 1 | John Doe | Johns title | Johns desc | Hungary | john-doe | +---------+------------+-------------+-------------------+---------------+----------------+ models_category_tbl table +-------------+---------------------+---------------------+ | category_id | model_category_name | model_category_slug | +-------------+---------------------+---------------------+ | 1 | it developer | it-developer | | 2 | photographer | photographer | | 3 | mechanic | mechanic | +-------------+---------------------+---------------------+ models_category_ids table +----+----------+-------------+ | id | model_id | category_id | | 1 | 1 | 1 | | 1 | 1 | 3 | +----+----------+-------------+
PHP function to fecth data: public function getAllModels1 () { $sql = "SELECT * FROM models_index JOIN models_category_ids ON models_index.model_id=models_category_ids.model_id JOIN models_category_tbl ON models_category_tbl.category_id=models_category_ids.category_id" ; $stmt = $this->conn->prepare($sql); $stmt->execute(); $result = $stmt->fetchAll((PDO::FETCH_OBJ)); return $result; }
people.php <?php declare(strict_types=1); ob_start(); include "includes/connect.php"; include "includes/functions.php"; $model = new ModelsData(); $models = $model->getAllModels1(); foreach ($models as $model) { ?> <a href="model.php?id=<?= $model->model_id ?>"><img src="<?= $model->model_img_path ?><?=$model->model_img_name ?>"></a> <?php echo $model->model_id . " " . $model->model_name . " " . $model->category_id . " " . $model->model_category_name ; ?> <h3><?= $model->model_name ?></h3> <?php } ?>
Output: 1 John Doe 1 IT developer 1 John Doe 3 mechanic
Hi, I am trying to verify if the given url exists or not, by using file_exists() function. It always returns 'FALSE' , according to my understanding it happening because the file to be checked on the given url is located in safe mode. Could anyone please suggest as to how this could be overcome, by similar function or by using alternative method. Regards Abhishek Madhani Hi again everyone! I'm sitting here, developing the same site - on my localhost the site is working great! Then when I upload it, to another testserver (production for developers), I get following: Notice: Undefined variable: db in C:\xampp\htdocs\lucas\sidebar.php on line 3 Fatal error: Call to a member function prepare() on a non-object in C:\xampp\htdocs\lucas\inc\functions.php on line 13 I'm wondering why I get it, because if I do a try / catch on the db connection, and do a select * on the content table, it returns results, the paths should be almost the same.. On localhost I run: localhost/lucas/, on the prod-server I run liveip/lucas/ Can any spot the problem? I'm not a big xampp dude myself, I've attached an dump of my PHP info also, just rename the .php to .html Thank you a lot! Lucas R / Zerpex Hi All, I am pretty new to PHP ( I am a C Programmer). I am trying a simple shopping cart website for my friend. IN one of the pages, I am submitting some info, which is actually not showing up in my server side php. Below is the HTML code to submit. <a href="cart.php?action=add&p=5&size=small"> <img src="images/add_to_cart.gif"/> </a> I tried to check the values of the parameters using $action = $_GET['action'] ; Action stored empty. Then I checked the whole array print_r($_GET) which returned Array( ) So, for some reason the value is always empty. I tried the declaration GLOBAL $_GET, but no use. Any help/directions - much appreciated! <?php if('00' == '000') echo 'weired'; ?> Please consider the code above. Strangely it echoes the word "weired". Also if('00' == '000000000000000') returns true and so forth. What is really going on? Thanks in advance By the way the php version is 5.3.9 on wampserver 2.2 I am trying to unserialize this string: a:3:{s:3:\"zip\";s:5:\"55068\";s:4:\"city\";s:9:\"Rosemount\";s:5:\"state\";s:2:\"MN\";} but I unserialize is returning false. Why is it doing that? $info = unserialize($_COOKIE['zipcode']); var_dump($info); |