send_email($fname,$email,$phone,$subject,$message);
You are using $fname
instead of $name
, that's the first thing I see that might go wrong. And where is the textarea/input in your form with the name "message"? Can it even get set? :o
send_email($fname,$email,$phone,$subject,$message);
You are using $fname
instead of $name
, that's the first thing I see that might go wrong. And where is the textarea/input in your form with the name "message"? Can it even get set? :o
Well if you need only one row, using the mysql extension you could do the following:
<?php
$query = 'SELECT something
FROM table
ORDER BY id DESC
LIMIT 1';
$result = mysql_query($query) or die(mysql_error());
$fetch = mysql_fetch_assoc($result); // Contains only the first row, as we're not using it in a loop.
// $fetch now contains the first row. We have added a ORDER BY to your query and a LIMIT 1.
// This ensures that only one result, and, because of the ORDER BY, only the most recent
// result will be fetched (if "id" is your auto_increasing primary key field).
What your while() loop actually does is traverse to your result set and, after each loop execution, place the internal marker (which points to which result of the result set is being used) one further.
So, if your result sets contains 5 rows, for example, what it does is:
while(...)
{
// Do stuff with first record.
// ...
// Loop finishes, on to the next record!
// This continues until the internal point can go no further, which is when the 5th item has been parsed. Your $fetch would then contain the data of the last element in the returned records set.
}
Is this of any help? I'm not 100% sure I fully understand what you want to do :).
Is it not easier to just let him on your computer for a couple of minutes while you're in class? :) Or aren't you in class?
For as far as I can say now: I like the new looks. Only thing is that I find the topic overview pages too busy. I think it is because there are suddenly so many images and colors because all avatars are now shown. A bit too many colors, if you ask me, but the topics themselves look great :)! Oh, and I'm typing this message right now, and underneath it are 4 options: join daniweb, log in using x, x or x, but no login using daniweb option :(.
I'm using IE10. Might be caused by me removing some lines from my CSS font file. I'm trying if it works if I specify a .ttf font only, but apparently it doesn't (at least not over here). Only Chrome appears to be loading the correct font file on the fist page load; Firefox and IE both aren't over here. Weird but I guess I'll have to do with this for now.
Well that is some useful info, thank you :)! I will look into it. If anyone has any other solutions, I'd be very happy to hear them.
Apache (XAMPP)
Hm yes, now that you mention it, it appears only to occur in Firefox.
EDIT: And in IE as well.
Okay so I've been going through my HTML lately and I discovered that I was still using the <base> element to define my website's base path. I want to get rid of that - I would like to be able to use relative URLs all the time, without having to rely on the <base> element.
Now, the problem is that using URLs like "/this/that" doesn't work the way I want it to on "localhost/project". It would lead to "localhost/this/that" instead of to "localhost/project/this/that". I don't want to prepend <?php echo $site_root_variable; ?>
to all my URLs either. Does anyone know a good solution for this? Maybe adding one or two lines to my .htaccess file?
I certainly have: http://bit.ly/1ct3Vhr
The website is written in Dutch but I think you won't have to read the website's content to discover how the architecture is built ;).
Does anybody know of a reason why a custom font would not load directly when a web page is loaded? When I visit the main page of my website, it uses a standard font instead of the custom font I selected, but if I then go to another page, that page does use the custom font, and when I then go back to the main page, the custom font is working all of a sudden. Anyone know how to fix this?
You're welcome :)!
Well I guess it means that you have tried to initate too many connections. You should only construct your PDO object once. After it is constructed, you can work with that object the entire time (except if you need another connection, but I don't think you need that ;)?).
Maybe a better question: what is it that you are trying to make? :)
Oh yea I see I have a little mistake in my code. In PDO you bind parameters to values. For example if you have
WHERE field = :field AND field2 = :field2
you still need to tell PDO what :field and :field2 are, which you do using $statement->bindParam(). You are getting the error because you replaced :key
by "1"
. You could use this code instead:
$query = 'UPDATE settings
SET value = :value
WHERE id = :id';
// Prepare the statement.
$statement = $db->prepare($query);
// Bind parameters.
$id = 1; // Change to what you want :id to be.
$statement->bindParam(':value', $_POST['value'], PDO::PARAM_STR);
$statement->bindParam(':id', $id, PDO::PARAM_INT); // If this is an integer, you should use PDO::PARAM_INT instead.
By the way, why are you using both the mysql_ functions AND the PDO class to connect to MySQL? :) I recommend using PDO only, as it is more secure.
This query:
SELECT value FROM settings WHERE value = "Login Script"
seems a bit odd to me. You are selecting the value field of records of which you already know what the value field contains (namely "Login Script"). It is something like saying:
SELECT "Login Script" AS value FROM settings WHERE value = "Login Script"
Now that must seem a bit odd, does it not? ;) If you want to get the value of value of a record of which you don't know the value of value yet, you should use another field to make a comparison. For example you could use
WHERE anotherfield = "Anothervalue"
, E.g. WHERE id = 5
or something like that.
As for your update query, I think you have misplaced your WHERE clause (but I'm not sure if it is not allowed to place it before your SET clause). I think it should be something like:
UPDATE settings SET value = "' . $new_value . '" WHERE field = yourvalue
An example:
<?php
// Changed it to include_once() as I think you will only need this file once per page load.
include_once('include/session.php');
$db = new PDO('mysql:host=localhost;dbname=******x2_login', '******x2_login', '********');
/***********************************************************************
Settings
*/
// Do we need to fetch data, or do we need to update data?
if($_POST)
{
// We need to update data.
$action = 'update';
}
else
{
// We need to fetch data.
$action = 'fetch';
}
switch($action)
{
case 'fetch':
// This query may return 1 - unlimited results, as we're …
Well have you checked if the file of which the servers says it is missing is actually there? :)
Could be that it's overheating, and if it is, you could (like caperjack said) try to clean the dust inside. You could also buy a laptop cooling platform (with vents in it) or put something underneath the back side of your laptop so that it is tilted a bit, so that the heat can flow out of your laptop more easily.
You could check from which website the user is referred to a page? Check out $_SERVER['HTTP_REFERER']. You can also add CAPTCHA validation to your form, which should be different for every form that is submitted. You store the correct CAPTCHA answer in a session when the form page is loaded, for example, and then validate if the answer is correct in the file in which the form data is processed.
By the way, AJAX requests are not simply always that much faster. It depends on which resources need to be loaded when you execute your AJAX file. If your base page needs to include 10 big files, and if your AJAX file needs those same files, you will have to include them again in your AJAX file, which does not necessarily speed up your application that much.
Oh and another thought: not only AJAX files are accessible through $_POST. Regular pages with a form on it can also be read; the target of a form can always be accessed.
Do you have any NULL values in your database? Because then you would have to append "AND value IS NOT NULL" to your query :).
Have you tried any MySQLi tutorials? Like:
http://www.xphp.info/mysqli-tutorial/
or
http://codular.com/php-mysqli
?
So $contentToSave equals $_POST['contentText']?
My question would be the same as jkon's, what's in $contentToSave? And maybe you could read a bit about MySQL Injection, because your script seems not to be as secure as you might think :).
A couple of things:
session_register() appears to be a deprecated function. You don't need to use it. Using only$_SESSION['key'] = 'value';
will suffice if you run a PHP version from less than a long time ago ;).
Should you not start a session using session_start() in the first line of your script, so that your session actually works?
About the following code:
ob_start();
include('../../../page_title.php');
ob_end_clean();
Any output in the file that you are including here will not get printed. Why are you using output buffering here, anyway? :)
What happens if you remove the @ from your mysql_connect() function? Does an error get printed to your screen?
Why are you even using the define() function to define your database connection info? As you seem to already have them placed inside variables. Why don't you just use your $account_user vars and alike?
True, I'd also recommend using PDO/mysqli instead of just mysql :)
In PHP (using mysql), fetching one result:
<?php
$q = "SELECT `download` FROM `images` WHERE `owner_un`='$owner' AND `url`='$url' LIMIT 1";
$rq = mysql_query($q);
$fetch = mysql_fetch_assoc($rq);
echo '<p>Result: ' . $fetch['download'] . '</p>';
Fetching all results:
<?php
$q = "SELECT `download` FROM `images` WHERE `owner_un`='$owner' AND `url`='$url' LIMIT 1";
$rq = mysql_query($q);
while($fetch = mysql_fetch_assoc($rq))
{
echo '<p>Result: ' . $fetch['download'] . '</p>';
}
Your <form> element should have an "action" attribute that tells it which page to load and a "method" attribute to define what kind of request is being done. E.g.
<form action="do_action.php" method="post">
Then, on do_action.php, in this example, you should validate the user's input. If it is not valid, you can save in a session that errors have occurred and redirect the user back to where he came from, and display the errors that you have saved in the session. Then unset the session, so that he won't see the same errors again when he does another form submission.
If the user's input is valid, you could save in a session that everything worked out well. You could then insert his input into your database and redirect him to a page which displays a success message.
Redirection can be done by setting a redirection header. E.g.:
header('Location: my_location.php');
This tells the page to redirect the user to my_location.php when the script finishes executing or reaches a custom exit point. If you want to redirect the user to where he came from, you could set the "Location" to $_SERVER['HTTP_REFERER']. For more info about $_SERVER variables, click here.
Database insertion can be done, for example, by using MySQL functions.
Great! Good to hear :).
You seem indeed to be using the output buffer while there is nothing you are buffering for output :). What an output buffer does is, shortly explained, this:
Instead of writing your output to the screen, it buffers it. It allows you to set headers and do other stuff in the meanwhile, and when everything you needed to do before outputting stuff to your the has been done, you flush the output buffer and output what's inside it to the screen. In your scenario there is nothing to be buffered before your headers are set, so you probably don't need those output buffers and can remove them if you want.
More info on Javascript timing events can be found here. I guess you could use the setTimeout() function. E.g.:
var timeout_time_in_seconds = 10;
var timeout = setTimeOut(function()
{
//* Type here what needs to happen after the timer times out.
}, (1000 * timeout_time_in_seconds));
You are aware of the fact that you have
for($i = 0;$i <= count($info);$i++)
{
which loops through the info of a user, not through the array of users, and that in your echo's you are trying to access a user using the counter of the user info loop instead of the users loop? :)
I'm not sure if this will work, but I think it should:
$facename = $_SESSION["facename"];
// The file() function will just put every line in your file in a new array record. Therefore
// I've named your var $lines instead of $UserInfo.
$lines = file('datatext/users.txt', FILE_IGNORE_NEW_LINES);
echo "<table>";
// Check if $lines exists, as a foreach() loop will generate an error if it does not.
if($lines)
{
// No special keys are present, therefore I've replaced the "$key => $value" part by just $value.
foreach($lines as $line)
{
// Convert the line to a user.
$users[] = explode(':', $line);
}
}
// Uncomment if you would like to check the value of $users here.
// echo '<pre>'; print_r($users); echo '</pre>';
for($i = 0; $i < count($users); $i++)
{
$user = $users[$i];
if($user[10] == $facename)
{
//* Apparently we've found a user you need?
// Echo some stuff.
echo "<tr>";
echo "<td> UserID </td>";
echo "<td> : </td>";
echo "<td> .$user[0].</td>";
echo "</tr>";
echo "</table>";
echo "<tr>";
echo "<td> Name </td>";
echo "<td> : </td>";
echo "<td> .$user[1].</td>";
echo "</tr>";
echo "</table>";
echo "<tr>";
echo "<td> IC </td>";
echo "<td> : </td>";
echo "<td> .$user[2].</td>"; …
Well "6135" is not really something we can work with, I think :). Is there anything else that shows? Any errors? Something like: Fatal error: .... on line 132 of file index.php
Yes that should work :). It checks if the given input ($address) consists of only alphabetical and numerical characters and hyphens, backslashes, dots and comma's.
Oh wait. I forgot one thing. Replace your current $regex by the following:
$regex = '/^[A-Za-z0-9\-\\,.]+$/';
(In the original I forgot to add the ^ and $ at the start and end, to define that the whole string should match the given regex).
Hmm well in plain html you can add a maxlength using the maxlength attribute. For example:
<input type="text" maxlength="128" ...>
But with the code you provided.. I don't know. You seem to be using a class named ItemForm? You should maybe take a look how that class generates <input> elements.
I require the text field should contains Alphabets in Upper and lower case, numbers, hyphen, fullstops forward and back slash and commas and spaces in it
Try:
$regex = '/[A-Za-z0-9\-\\,.]+/';
$is_valid = preg_match($regex, $address); // Becomes true or false.
This does exactly what you ask. The following code is an example of validating a street name followed by a house number:
$regex = '/
^ # Start of string
[a-z\- ]+ # Alphabetical chars, hyphens and spaces
[ \t]* # Followed by one or multiple tabs or spaces
\d # House number should start with at least one number
[0-9a-z]* # House number may, for the rest, exist of numbers and/or letters
$ # End of string
/ix';
$is_valid = preg_match($regex, $address); // Returns true or false.
If you have an example address, I will be glad to help you write a regex that matches that address.
So are you getting an error or are you not getting an error? And if you are getting an error, what is the error you are getting? =)
In a nutshell, to speak proper English, you need to learn French!
Hm that doesn't make writing this report much easier but thanks anyway :p.
So that would mean that "public transport" is british english, and "public transportation" is american english?
Well what it says is that you have not defined $id. $id is empty, and therefore you get an error and your script is not working. If you do not define $id in a way such as this:
$id = 'yourvalue';
Then it will be undefined and you will not be able to work with it. PHP cannot check your <div>'s id. You should use Javascript for that :). Does this answer your question?
I think therefore I am not. Only when the mind is silent, I am. - Unknown
Haha no problem of course, you are not to blame :). Stuff like this happens all the time, that's what makes it so damn handy to have a community at your disposal to help you out when you can't seem to figure out the problem by yourself.
Is there anything else you need help with?
Then contact.php should be the file that contains the code to insert stuff into your database. Is that the case here?
Well if you are not getting any POST data, there must be something else going on. Could you verify that your <form>'s method property is set to "post"? E.g.: <form method="post" ...>
Then, the action property of your <form> element must be set to the location of the file in which you process your data and insert the record into your database. If the form is then submitted, it sends its data via POST to that file. If that process succeeds, you should not see "array(0) {}" on the next page, but an array filled with data.
So, example:
Page form.php:
<form action="newpage.php" method="post"> (Rest of your HTML)
Page newpage.php:
<?php
// A lot of stuff happens.
// Let's see if the form has successfully been submitted, did we get any data?
echo '<pre>'; var_dump($_POST); echo '</pre>';
// More of your own PHP.
And what happens if you put this somewhere at the top of your document? (After your session_start(); call, if you use that)
echo '<pre>'; var_dump($_POST); echo '</pre>';
Do you see any $_POST values on your screen when the file is loaded?
So I suppose this script is not working:
// usable constants
define('DB_NAME', 'yyy_ContactForm');
define('DB_USER', 'xxx');
define('DB_PASSWORD', 'zzz');
define('DB_HOST', 'localhost');
$link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Could not connect: ' .mysql_error());
}
$db_selected = mysql_select_db(DB_NAME,$link);
if(!$db_selected) {
die('Can\'t use' . DB_NAME . ':' .mysql_error());
}
//echo 'Connected successfully';
/* $fullname = $_POST['fullname'];
$email = $_POST['email'];
$comment = $_POST['comment']; */
$fullname = mysql_real_escape_string ($_POST['fullname']);
$email = mysql_real_escape_string ($_POST['email']);
$comment = mysql_real_escape_string ($_POST['comment']);
/*~~~~ $error = array();
if($_POST[$fullname, $email, $comment] == '') {
$error[] = '';
} ~~~~*/
$sql = "INSERT INTO admin_table (fullname, email, comment) VALUES ('$fullname',
'$email', '$comment')";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
mysql_close();
Have you checked if any $_POST values are actually submitted to the file in which the code above resides? In other words: are you 100% sure that your $_POST values have been set when you insert them into your database? You could check by, for example, adding the following line:
echo $sql;
underneath this line:
$sql = "INSERT INTO admin_table (fullname, email, comment) VALUES ('$fullname', '$email', '$comment')";
and then see if the values are actually in your query.
Could you post some code from where the insertion into the database happens?
Are you sure that mail() doesn't send anything at all if one recipient's email is invalid?
If so, you could maybe use a loop to send separate mails to every email address in an array? E.g.:
$email_addresses = array(
'email1@email.com',
'email2@email.com',
// etc.
);
// Fill these in with whatever you want.
$subject = '';
$message = '';
$headers = '';
// Send the emails.
foreach($email_addresses as $email)
{
mail($email, $subject, $message, $headers);
}
Well the only way to edit your header.php file would be to open your header.php file, I suppose. Same goes for any file, could you perhaps repose your question? ^^
If the code you posted is currently all on one the same page, it is logical why it isn't working at the moment: you cannot read your $_GET if it has not been set. That means that if your select is changed right now, it does not set your $_GET immediately; only after the form in which your <select> resides is submitted, you will be able to use it.
If this is all your code on one and the same page:
<select id="ID1" name="place" >
<option value="Colombo" selected="selected">Colombo</option>
<option value="Matara">Matara</option>
<option value="Galle">Galle</option>
</select>
//What i want is pass selected value through URL
<div style="float:right; padding-right:1px; padding-bottom:2px;">
<a href="MyCity.php?city1= <?php echo $_GET["place"] ; ?> > Click here </a>
</div>
Nothing will happen, because the line in which you are asking for $_GET['place'], it has not yet been set if no form has been submitted.
What you could do to make it work is, indeed, like diafol says, make your link change dynamically using Javascript or make it so that a form is submitted so that your $_GET data is accessible. As he also says, note that
<a href="MyCity.php?city1= <?php echo $_GET["place"] ; ?> >
will not work, as there are spaces before and after your <?php ?> part (and the closing double quotes (") are missing).
Diafols example is great, but I would still like to provide another example to you of how you could use a form to make this work (sorry diafol, not that your answer is not …
Maybe you can open header.php separately and then edit it in the design view? :)
Well yea, my suggestion should work for that, I think :). Note that if you use "JOIN", there MUST be a match in order for a row to be retrieved. If you don't mind if there is a match and want to retrieve it either way, you could use LEFT JOIN.