The context is: e-commerce, the problem stands in adding items to the cart.
I created a while loop to iterate through each item my query returns and each item has a button that redirects to a "info on the item" page. My problem is that since there's a loop, the values to submit (e.g. the ID of the item) is overloaded and every button submits the values of the last item.
I can pass all the IDs of all the plants but i have no idea how to, in the "item detail" page, to show the correct item among the array.
lista-piante.php: (summarized)
<?php session_start();
// connect to the database
$connessione = new mysqli('localhost', 'root', 'root', 'mio');
//query
$user_check_query = "SELECT Pianta.NOME as nome, PIANTA.ID as pid, Item.PREZZO as prezzo, Item.ID as id
FROM Item, Pianta WHERE Pianta.ID = Item.PIANTA";
$result = mysqli_query($connessione, $user_check_query);
if($result->num_rows > 0) {
echo"<h3>Lista delle nostre piante</h3>";
echo"<ul class=\"plant-flex\">";
// loop through records
while($row = $result->fetch_array(MYSQLI_ASSOC)){
echo"<form method='get' action='../html/details-pianta.php'>";
echo"<li>";
echo"<div class='plant-preview'>";
echo"<div class='plant-preview-description'>";
//dichiarazione variabili (per leggibilità)
$nome= $row['nome'];
$pid = $row['pid'];
// PRINT NAME
echo"<div class='plant-preview-description-name'>";
echo "<p class='bold'>" . $nome . "</p>";
echo "<input type='hidden' name='name' value='$nome' />";
echo"</div>";
echo "<input type='hidden' name='pid[]' value='$pid' />";
echo"<div>";
echo"<button type=\"submit\" class=\"btn\" name=\"details_plant\">Dettagli" . $item . "</button>";
echo"</div>";
echo"</li>";
echo"<form/>";
}
$result->free();
}
echo "<ul/>";
$connessione->close();
details-pianta.php: (summarized, it will contain the style of the page)
<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
<head> <!-- meta tag and other stuff --> </head>
<body>
<div>
<?PHP include('../php/dettagli-pianta.php'); ?>
</div>
</div>
</body>
</html>
dettagli-pianta.php: (summarized, it should contain the info of each item)
<?php
session_start();
// connect to the database
$connessione = new mysqli('localhost', 'root', 'root', 'mio');
$pid = mysqli_real_escape_string($connessione, $_GET['pid']);
//but pID is either the last item's id, or an array with all items' ids, so i can't chose the only one i want
//the URL shows always more pIDs (from the lista-piante.php get form)
$user_check_query = "SELECT * FROM Pianta, item WHERE Pianta.ID = '$pid' ";
$result = mysqli_query($connessione, $user_check_query);
if($result->num_rows > 0) {
echo"<h3>Dettagli della pianta</h3>";
echo"<ul>";
//loop thought query records
while($row = $result->fetch_array(MYSQLI_ASSOC)){
echo"<form method='post' action='../php/add-carrello.php'>";
echo"<li>";
echo"<div>";
//dichiarazione variabili (per leggibilità)
$nome =$row['NOME'];
//$genere= $row['GENERE'];
//$specie= $row['SPECIE'];
//etc etc
// PRINT NAME
echo"<div>";
echo "<p class='bold'>" . $nome . "</p>";
echo"</div>";
//echo"<div>";
//echo "<p class='bold'>" . $specie. "</p>";
//echo"</div>";
//echo "<input type='hidden' name='pid' value='$pid' />";
echo"<div>";
echo"<button type=\"submit\" class=\"btn\" name=\"add-carrello\"> Aggiungi al carrello</button>";
echo"</div>";
echo"</li>";
}
$result->free();
}
echo "<ul/>";
$connessione->close();
There is an error with form closing, but... I have a feeling you are complicating it for yourself by using all those forms/buttons.
I would clean up the code and get rid of the form/button scheme altogether, and use simple a href links with ?id=$pid
Something like this (shortened, if needed post a comment and I can expand):
while($row = $result->fetch_array(MYSQLI_ASSOC)){
echo "<li>";
echo "<div class='plant-preview'>";
echo "<div class='plant-preview-description'>";
//dichiarazione variabili (per leggibilità)
$nome = $row['nome'];
$pid = $row['pid'];
// PRINT NAME
echo "<div class='plant-preview-description-name'>";
echo "<p class='bold'>" . $nome . "</p>";
echo "</div>";
echo "<div>";
echo "<a href ='../html/details-pianta.php?pid=$pid'>Dettagli " . $nome . "</a>";
echo "</div>";
echo "</li>";
}
You can use CSS later to make your a-href link look like a button, add image, or play with it any way you like.
Then in the product details page (dettagli-pianta.php) use your product id pretty much same as you already do:
$pid = $_GET['pid']
...
$user_check_query = "SELECT * FROM Pianta WHERE Pianta.ID = '$pid' ";
Here is one Stack Overflow that talks about using link instead form:
How send parameter to a url without using form in php?
Edit (mistakes found, more suggestions, in case you still want to keep forms/buttons):
you did not close ?> in your examples, but ok, probably just copy/paste here
you have $item variable that isn't defined, and not pulled from SELECT query, so I can only assume that is supposed to be $nome (or you deleted something to make it shorter in question and forgot about it)
you also probably wanted a space like this (note space after Dettagli)
echo "<button type='submit' class='btn' name='details_plant'>Dettagli " . $nome . "</button>";
not sure why you keep files in folders "../html/" and "../php/" when both are with extensions .php, could be confusing for others later working on your code, or ... maybe it's just me
you have <?php session_start();?> then under it you include a file that also has <?php session_start();?> ... no need for one of them. Since "details-pianta.php" is in folder "html" I guess you can remove it from there, as you don't need session just to include another PHP file
in form you submit name='pid[]' when you should just use name='pid' (no brackets), like this:
echo "<input type='hidden' name='pid' value='$pid' />";
in "dettagli-pianta.php" you have a select like this: $user_check_query = "SELECT * FROM Pianta, item WHERE Pianta.ID = '$pid' "; where you name two tables but don't join them, and I can only assume it should be $user_check_query = "SELECT * FROM Pianta WHERE Pianta.ID = '$pid' ";
be careful of uppercase/lowercase in database and column names, try to standardize
in one line you echo with mixed quotes something like echo "<bla name='bla'>" and in next you escape quotes like echo "<bla name=\"bla\">" ... make it easy on yourself and - standardize. Unless absolutely necessary, first way (mixing single and double quotes) is preferable, and only when you have something really complicated to echo like mix of HTML+JavaScript, then resort to escaping quotes
And finally, but actually a direct answer to your issue - you closed your form in the wrong way (yeah, had to look real hard to see it):
echo"<form/>";
You need to have (space is optional, reads better):
echo "</form>";
Non the less, as others too have already commented, using forms just to get buttons is an overkill. Try using simple links (<a href> elements) and style them with CSS to your liking, making them look like buttons...
And last, but... I believe it to be important... Try not to mix Italian and English in code (including database structure). It is obvious you are just learning but havin database called "mio" with table "pianti" and column "prezzo" ... then use something like "item". Also, names of files like "details-pianta", then you have another file "detaggli_pianta", and in button name you use "details_plant", it is huge mashup of two languages. you seem to be fluent English speaker judging from your question, so - why not use English everywhere in code? Name your database "my_first_web_store", name your table "plants", name your column "price", name your PHP files "plant_details" (or details_plant, whatever), use comments in English in your code (nobody but you and other developers see that). You will be thankful later when your plant-selling company expands worldwide, and when you will have multi-language webshop, and maybe 3 more developers working from India and US, all working on same project... :)
Have fun learning!
Related
I have a searchresult.php file where I pull all the menus names out of my database and print them with a button close to them where the button has a input type hidden where I associated the name of the menu through the variable $nameofmenu . Something like
Menu1 --> Button (See Menu)
Menu2 --> Button (See Menu)
Menu3 --> Button (See Menu)
<?PHP
while($myrow = pg_fetch_assoc($result)) {
$nameofmenu = $myrow[name];
echo $nameofmenu; //It prints correctly the name of the menu
echo '<form name"formname" method="post" action="resultsmenu.php">';
echo "<input type='hidden' name='menuname' value=' $nameofmenu ' />";
echo "<input type='submit' name='submit' value='See Menu' />";
}
?>
Then I have my resultsmenu.php file that will open when I click in any of the buttons.
<?php
$nameofmenu = $_POST['menuname'];
$db = pg_connect('host=localhost dbname=test user=myuser password=mypass');
$query = "SELECT * FROM menu where name='$nameofmenu'";
$result = pg_query($query);
if (!$result) {
echo "Problem with query " . $query . "<br/>";
echo pg_last_error();
exit();
}
$myrow = pg_fetch_assoc($result);
$description = $myrow[description];
?>
I have 2 Issues:
First issue: in the searchresult.php, even it prints out correctly all the different menu names, whenever I click any of the buttons, all the buttons return my the same menu (The last one, in the example: Menu 3 in the $nameofmenu = $_POST['menuname']; of the resultsmenu.php file.
Second issue: this issue happend in the resultsmenu.php file. Even for Menu 3, it seams that the recognized the value in the variable. Meaning I don't get back any result or value from the query: $query = "SELECT * FROM menu where name='$nameofmenu'";
However, if I set up the value Manually like $nameofmenu = "Menu3"; then It works.
I even tried this code to see if there is any different in the value passed from $_POST['menuname'] and the value typed in manually and it seams to be the same value because it prints "Both variables are the same"
$nameofmenu2 = "Menu3";
$nameofmenu = $_POST['menuname']; //where the value in menuname is Menu3
if ($nameofmenu2 = $nameofmenu){echo "Both variables are the same";}
Thank you so much
You overwrite the same input field (=name) over and over again, so only the "last" overwrite is returned/available. To avoid this, put the data as POST-ARRAYs like this (also switch your quotes):
echo '<input type="hidden" name="menuname[]" value="'.$nameofmenu.'" />';
After submitting, you now will see that $_POST['menuname'] is an array! e.g.
var_dump($_POST['menuname']);
As mentioned by David, your are assigning nameofmenu2 to nameofmenu. But furthermore, when you echoed:
echo "<input type='hidden' name='menuname' value=' $nameofmenu ' />";
you included whitespace on either side of $nameofmenu. This could cause problems when you go to make your query. Try using:
var_dump($_POST['menuname']);
to check your expected post data.
First of all this is my first question on here, and altohugh I have searched the site none of the answers I've seen resolve my current problem.
I am a PHP novice and am currently working on an end project for a course. The object is to make a rudimentary blog where users can post, delete and edit their news, admins can edit or delete everything etc. I am mostly doing fine, but am having a bit of trouble with the editing feature.
The following code displays all blog posts, their authors and dates of posting. If the currently logged in person is the author of a post or a admin, they have the option of deleting or editing each individual post. A small form appears that contains the title and post text. When the user types something else in clicking on the edit button should change the values in the database to the new values the user specified. The problem is that whenever i click on the edit button in the current setup, nothing happens. If i move the if statement outside of the other if statement, the posts do update, but become blank in the database.
Running print_r($_POST) after the fact shows that the array it builds has correct names and updated values, but still they aren't updated in the database. Here is the code, the pertinent part starts at the last if statement( I know, it isn't injection proof, will get to that as soon as it works):
$query = "SELECT id, title, body, pub_date, user_id FROM posts ORDER BY id desc";
$query_fetch = mysql_query($query);
while ($blog_post = mysql_fetch_assoc($query_fetch)) {
$author_id = $blog_post["user_id"];
$post_id = $blog_post["id"];
$post_id2 = $blog_post["id"] . 2;
$title = $blog_post['title'];
$body = $blog_post['body'];
$query = "SELECT username FROM users WHERE id = '$author_id'";
$query_run = mysql_query($query);
$author = mysql_fetch_assoc($query_run);
echo "<h2>" . censor($blog_post["title"]) . "</h2>" . "<br> <p> Autor: " . $author["username"] . "</p><br><p>Objavljeno: " . $blog_post["pub_date"];
if ($_SESSION['admin'] == 1 or $_SESSION['username'] == $author["username"]) {
echo "<form action='' method='POST'><input type='submit' name= '$post_id' value= 'Obriši objavu'></form>";
echo "<form action='' method='POST'><input type='submit' name= '$post_id2' value= 'Uredi objavu'></form>";
}
echo "<p>" . censor($blog_post["body"]) . "</p>";
if (isset($_POST["$post_id"])) {
$del_post = "DELETE FROM posts WHERE id = '$post_id'";
mysql_query($del_post);
}
if (isset($_POST["$post_id2"])) {
echo "<form action='' method= 'POST'>New title<input type='text' value = '$title' name='title'>New text<textarea name='body' id='' cols='30' rows='10'>$body</textarea><input type='submit' name='edit' value='edit'></form>";
if (isset($_POST['edit'])) {
$edit_title = $_POST['title'];
$edit_body = $_POST['body'];
$query = "UPDATE posts SET title= '$edit_title', body= '$edit_body' WHERE id= '$post_id'";
mysql_query($query);
}
}
}
Any help would be appreciated.
This last piece of code
if (isset($_POST["$post_id2"])) {
echo "<form action='' method= 'POST'>New title<input type='text' value = '$title' name='title'>New text<textarea name='body' id='' cols='30' rows='10'>$body</textarea><input type='submit' name='edit' value='edit'></form>";
if (isset($_POST['edit'])) {
$edit_title = $_POST['title'];
$edit_body = $_POST['body'];
$query = "UPDATE posts SET title= '$edit_title', body= '$edit_body' WHERE id= '$post_id'";
mysql_query($query);
}
}
gets activated when post_id2 is sent, but generates a form where post_id2 is not contained anymore. So when you submit that form, the IF is not entered.
You can modify it like this:
if (isset($_POST["$post_id2"])) {
echo "<form action='' method= 'POST'>New title<input type='text' value = '$title' name='title'>New text<textarea name='body' id='' cols='30' rows='10'>$body</textarea><input type='submit' name='edit' value='edit'></form>";
}
if (isset($_POST['edit'])) {
$edit_title = $_POST['title'];
$edit_body = $_POST['body'];
$query = "UPDATE posts SET title= '$edit_title', body= '$edit_body' WHERE id= '$post_id'";
mysql_query($query);
}
In general I think you would find it easier to use forms differently, specifically by using some sort of action tag:
input type="hidden" name="command" value="edit"
input type="hidden" name="post" value="{$post_id}"
This way you could run one single query immediately, without the need for browsing all the posts in a cycle.
One other useful possibility is to split your code between different PHP files, and keeping common code in one include:
<?php // this is delete.php
include "common.php";
$post_id = my_get_var('post_id');
my_sql_command("DELETE FROM posts WHERE...");
used from
<form action="delete.php" method="post" ...>
As you can see this allows for different ways of retrieving post_id (centrally defined in a single function my_get_var in common.php) and the central definition of SQL functions. How this function interfaces to MySQL can then be updated, specifically passing from mysql_ functions (which are deprecated, and soon will no longer be available) to e.g. PDO.
It also allows you to test a single command independently, by directly entering delete.php in the browser (you need for my_get_var to accept both POST and GET variables to do this).
Details
You want to inspect and/or modify a collection of posts. You then require initially at least the following operations: list, edit, and delete.
Only the first works against all posts.
So you could have a list.php file running the SELECT. Also, it is only in this SELECT that you need information about the user, so your query could become:
$query = "SELECT posts.id, title, body, pub_date, user_id, username FROM posts JOIN users ON (posts.user_id = users.id) ORDER BY posts.id desc";
In the display cycle we would display this information:
$query_fetch = mysql_query($query);
// This file will receive requests to edit or delete
// We can use a single form.
echo '<form action="manage.php">';
while ($post = mysql_fetch_assoc($query_fetch)) {
echo "<h2>" . censor($post["title"]) . "</h2>" . "<br> <p> Autor: " . $post["username"] . "</p><br><p>Objavljeno: " . $post["pub_date"];
if ((1 == $_SESSION['admin']) or ($_SESSION['username'] == $post["username"]) {
echo "<input type=\"submit\" name=\"Obriši objavu\" value=\"{$post['id']}\" />";
echo "<input type=\"submit\" name=\"Uredi objavu\" value=\"{$post['id']}\" />";
}
echo "<p>" . censor($blog_post["body"]) . "</p>";
}
echo "</form>";
This way you need only one form, and it will submit one field with a name describing the action to be taken, and the post on which to do it.
The file manage.php will then receive this information -- and can also be used to update it:
foreach(array(
"delete" => "Obriši objavu", // from list.php
"edit" => "Uredi objavu", // " "
"update" => "update" // from this file itself (see below)
)
as $test_todo => $var) {
if (array_key_exists($var, $_POST)) {
$id = $_POST[$var];
$todo = $test_todo;
}
}
if (isset($id)) {
switch($todo) {
case "delete":
mysql_query("DELETE FROM posts WHERE id = '{$id}'");
break;
case "edit":
// Get this post.
$query = "SELECT posts.id, title, body, pub_date, user_id, username FROM posts JOIN users ON (posts.user_id = users.id) WHERE posts.id = '{$id}';";
echo '<form action="manage.php" method= "POST">';
// This is how we tell this file what to do, and to what.
echo "<input type=\"hidden\" name=\"update\" value=\"{$id}\">";
// run query, fetch the one record, display info...
echo "</form>";
break;
case "update":
// Build the update query from $_POST.
mysql_query("UPDATE posts SET ...");
}
At first check that your query is correct. Then try to hard-code your query. Also test your query in phpMyAdmin Also you can try to remove the '' from your number variables on every query.
Please, can you give us your error?
There is a possibility also that your database has already been updated. So double check it.
This is how I usually debug. echo the query. Run it in PHPmyadmin, and see the error.
so, in your case.
echo "UPDATE posts SET title= '$edit_title', body= '$edit_body' WHERE id= '$post_id'";
echo that and you will have the query that the script will be trying to run.
Try running it in phpmyadmin and check what the error is.
how can i set it that the section drop down list shows all sections available for a certain subject, depending on the previous drop down list that contains subjects. For example: if i chose the subject A , it should show me all sections of subject A available. Currently the drop down of the subject works, it fetches all subjects available but im unable to make the second drop down fetch the sections since i want to make such that:
select section from class WHERE (name of subject chosen above is equal to the name column in the database.
Please ignore my code style since im a beginner after all. Thank you in advance.
My code:
<div>
<label for="subjects" accesskey="o">Subject</label>
<?php
$conn = new mysqli('localhost', 'afhfhdfhf', 'fhfhhfhfhfhf', 'fhfhfhfh')
or die ('Cannot connect to db');
$result = $conn->query("select name from class");
echo "<html>";
echo "<body>";
echo "<select name='subject'>";
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$name = $row['name'];
echo '<option value="subject">'.$name.'</option>';
}
echo "</select>";
echo "</body>";
echo "</html>";
?>
</div>
<br>
<div>
<label for="section" accesskey="o">Section</label>
<?php
$conn = new mysqli('localhost', 'fgfgfgfg', 'rfgfgfgfg!~fgfgf', 'fgfgfgf')
or die ('Cannot connect to db');
$result = $conn->query("select section from class WHERE name = '$name'");
echo "<html>";
echo "<body>";
echo "<select name='id'>";
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$name = $row['name'];
echo '<option value="">'.$name.'</option>';
}
echo "</select>";
echo "</body>";
echo "</html>";
?>
</div>
<br>
(n.b. this really should have been a comment, but it was too long for that, so answer it is :-)
You've got a few problems there... first, you are echoing out <html> and <body> tags, you already have those on the page, so you don't need to do that.
The second problem is that $name doesn't really exist in the way you are looking in the second query. In fact, it'll be the value of the last name you echo'd out in the first loop.
So, the fundamental issue is that PHP runs on the server and then is passed to the client and you want to limit a select based on user input that happens in the browser. So what you need to do is either on selection of the subject, submit back to the server to get the section OR you could use something like jQuery to do an AJAX call back to the server to retrieve this info (either as JSON that you can parse and use, or as HTML that you can plop into the form). 2nd option is definitely the way to go.
Have a google about this kinda thing and you'll find LOADS of examples and come on back here if you hit a road block :-)
I have a site where an admin can enter exam marks for papers which are part of an exam.
I am on the final part of actually giving a user their mark. But I just can't seem to do it.
So far what I have done is:
Allow the admin to view all of the exams, click on a specific exam and view the papers for that exam, then click on a paper and view all of the people who took that paper.
Then, click on a user and enter their marks and feedback. This is the part which I cannot do. I have pasted my code below along with what I am trying to do but it just is not working, any help would be great!
So, along with their mark and feedback I am also inserting into the marks table the, paperID and the examID.
CODE:
<?php
$epsID = $_GET['epsID'];
$sql = "SELECT * FROM ExamPaperStudent WHERE epsID = '$epsID'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$epID = $row ['epID'];
$sID = $row ['sID'];
echo "<p><form>";
echo "<b>Mark: <input type=text name=mark></b><br>";
echo "<b>Feedback: <input type=text name=feedback></b><br>";
echo $epID;
echo $sID;
echo "</form>";
echo "<a href='insertmark.php?epsID=". $row['epsID']."'>Add Data</a>";
}
?>
INSERTMARK.php code: (At this form I already know the exam/paper ID, which I also am trying to insert (along with marks/feedback).
CODE:
$mark = $_POST["mark"];
$feedback = $_POST["feedback"];
if(isset($_REQUEST['submit']))
{
$sql = mysql_query("insert INTO exammarks (mark, feedback, epID, atID) values ('$mark', '$feedback', '$epID', '$sID')");
$result = mysql_query($result);
}
epsID = exampaperstudent
epID = exampaper
sID = student
your form is wrong .
change this
echo "<p><form>";
to
echo "<p><form action='INSERTMARK.php' method='POST' name='myform'>";
OMG everything is wrong inside your inputs. i just give one and you correct the others
echo "<b>Mark: <input type='text' name='mark'></b><br>";
^----^------^----^---//use single quotes around here
didnt you miss submit button ?
Source can be found here: results.php
and the zip: Results zip
<?php
// create short variable names
$searchtype=$_POST['searchtype'];
$searchterm=trim($_POST['searchterm']);
if (!$searchtype || !$searchterm) {
echo '<p><strong>You have not entered search details. Please go back and try again.</strong></p>';
exit;
}
if (!get_magic_quotes_gpc()){
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
# $db = new mysqli("*","*","*","*");
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$query = "select * from acronymns where ".$searchtype." like '%".$searchterm."%' ORDER BY title ";
$result = $db->query($query);
$num_results = $result->num_rows;
echo "<p>Number of records found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo "<p><strong>".($i+1).". ";
echo $row['acro'];
echo " - ";
echo $row['title'];
echo "</strong><br />";
echo $row['desc'];
echo "</p>";
}
// $result->free();
$db->close();
Output looks like:
Americans with Disabilities Act (ADA)
The Americans with Disabilities Act was enacted in 1990 to establish the prohibition of discrimination on the basis of disability, which may include autism. The ADA is divided into three Titles. Title I speaks to employment law, Title II covers State and Local activities (including public transportation), and Title III relates to accommodations in public buildings and businesses.
The link is: www.ada.com target="_blank" Americans with Disabilities Act</a> (within the MySql db.
The actual link shows: http://mysiteishere.com/"www.ada.com" which of course makes a 404 Error.
Thanks ahead of time.
Just because the desc filed contains URL's doesn't mean they will autmoatically show up as links in your HTML. You need to output the links as an href value in an <a> element to make a clickable link. You are probably best off not storing full HTML in your DB, but rather just the link. It looks like you combination now is producing an invalid link. Simple look at your HTML source and fix it.
From what you said, it seems that you're not including the link correctly. It doesn't have anything to do with the $row['desc'] but what's inside it. When you're inserting the link from whatever form you're using, use the following.
ex:
Americans with Disabilities
You can use the below function while fetching 'DESC' column
function make_links_clickable($text){
return preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9#:%_+.~#?&;//=]+)!i', '$1', $text);}
For Eg.
$text = 'Here is link: http://google.com And http://example.com inside. And another one at the very end: http://test.net';
echo make_links_clickable($text);
Went ahead and changed my code and the text in the db. In the db I removed the Text.. and put the in between parentheses. The Php I changed to the following and now it shows the links with the urls, so it works. It's the "a href.." that I can't make work. I don't understand why though.
for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo "<strong>".($i+1).". ";
//echo $row['acro'];
//echo " - <br />";
//echo "<br>";
echo $row['title'];
echo " - ";
echo "<br>";
echo "</strong>";
$text = $row['desc'];
$text = preg_replace('/(^|[^"])(((f|ht){1}tp:\/\/)[-a-zA-Z0-9#:%_\+.~#?&\/\/=]+)/i','\\1\\2', $text);
echo $text;
}
The link in the MysqlDB should be:
Americans with Disabilities Act
Now lets assume you got this right, you should look at your charset of your DB, just making sure they match your editors charset.
That said, please post the output of HTML "Show source".