I am having a problem trying to get a row to create everytime I enter a new database entry.
My code so far is:
<table align="center">
<th>MH/s</th><th>Contact Length</th><th>Date Bought</th><th>Payment</th>
<?php while ($row_cnt > 0) {
echo "<tr><td>" . $row['mhbought'] . "</td><td>" . $row['length'] . "</td><td>" . date(d-m-Y, $row['datebought'] . "</ td><td>" . $row['payment'] . "</td></tr>";
}
?>
</table>
The error I receive however states PHP Parse error: syntax error, unexpected ';' (which is the echo line) Am I doing something completely dumb here, can this even be done?
Thank you for any help you may provide.
Looking at the code, the problematic line is this:
date(d-m-Y, $row['datebought']
^^ missing quotes ^ missing closing parenthesis
Change it to:
date('d-m-Y', $row['datebought'])
You haven't close date() right bracket and there is quotation missing for date format. Your echo should look like:
echo "<tr><td>" . $row['mhbought'] . "</td><td>" . $row['length'] . "</td><td>" . date('d-m-Y', $row['datebought']) . "</td><td>" . $row['payment'] . "</td></tr>";
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I can's seem to figure out why I'm getting this error.
I need to turn user_link part into hyperlink(right now it outputs a text on the frontend). Error happens on this line in my shortcode.php file. I guess there is an error with a href part:
$output .= '<td>' . $order->billing_first_name . ' ' . $order->billing_last_name . ' <a href='" . $order->user_link . "'>" . $order['user_link'] . "</a> </td>';
Your issue is right here:
. ' <a href='" .
Notice how you're starting with a single quote and ending with a double.
Definitely consider using an IDE. It will make these easy bugs blatantly obvious. I highly recommend PHPStorm, or if you don't want to spend anything, sublime text (Not an IDE but will provide linting and highlighting).
On top of that I'd recommend using some type of templating engine eventually. You should always try to avoid writing HTML as strings.
$output .= '<td>' . $order->billing_first_name . ' ' . $order->billing_last_name . ' ' . $order['user_link'] . ' </td>';
You switched the ' and " in the a href. I also changed the two " to ' in the a description.
Hi straight forward question really. I have a search function in php that prints out the required information from a data base. But it prints it out as one word. I don't want a line break...just a space between words. I've googled and checked this forum for answers but can't seem to find any.
The code works and does as it is required but it doesn't look neat.
Instead of: ID Job Title Job Description Job location Job Category
it looks like this:
IDJobTitleJobDescriptionJoblocationJobCategory
This is part of my php code.
// $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
echo
'<p>'
. $results['id']
. $results['job_title']
. $results['job_description']
. $results['job_location']
. $results['job_category']
. '</p>';
Please note I want it in one line, not line breaks. Thanks.
You have to echo the space like this .' '.
Or in your Case just replace your code with this.
echo
'<p>'
. $results['id']
.' '. $results['job_title']
.' '. $results['job_description']
.' '. $results['job_location']
.' '. $results['job_category']
.' '. '</p>
echo '<p>'
.$results['id'] . ' '
. $results['job_title'] . ' '
. $results['job_description'] . ' '
. $results['job_location'] . ' '
. $results['job_category'] . ' '
. '</p>';
So I'm working on an editor for a friend of mine, and I'm getting a strange Syntax error. It's strange because I'm currently creating an NPC editor using the shell of the Item editor I made a while back. That's saying I literally just changed the variables and changed everything that said 'item' to 'npc'. However, I'm getting a syntax error at a random column and I can't find out what the error is. It's in the editing section of the editor(lol). The delete and create parts of the editor work fine.
}else if($state == "edit")
{
$editsql = "UPDATE npcs SET name='" . $name . "', description='" . $description . "', gender=" . $gender . ", size=" . $size . ", dialog='" . $dialog . "', hair_style=" . $hair_style . ", hat=" . $hat . ", top=" . $top . ", bottom=" . $bottom . ", movement_pattern=" . $movement_pattern . ", behavior=" . $behavior . ", range=" . $range . ", uses_special_pokemon=" . $uses_special_pokemon . ", pokemon_1=" . $pokemon_1 . ", pokemon_2=" . $pokemon_2 . ", pokemon_3=" . $pokemon_3 . ", pokemon_4=" . $pokemon_4 . ", pokemon_5=" . $pokemon_5 . ", pokemon_6=" . $pokemon_6 . " WHERE id=" . $id;
this is the error:
Could not edit npc ID 3 : 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 'range=0, uses_special_pokemon=0, pokemon_1=1, pokemon_2=1, pokemon_3=1, pokemon_' at line 1
I can't quite figure out what it's calling out near 'range' and range itself looks fine to me, so I don't see an error at all. It's most likely something completely obvious that I'm just overlooking as usual, but I'm stumped.
You'll want to rename range to range_, because Range is a SQL reserved word. You could enclose it in backticks, which are different than single quotes. ` VS ' ...
If you seperate the query into multiple lines your error message will tell you where it failed closer to where the actual error was. It's a one-liner, so it tells you error exists on line 1. Typically, seperate clauses, i.e.
select xxxx
from yyyy
where xxxx = zzzz
then you'll know it's an error in syntax and in what clause.
I want to create an HTML Message to send an email in PHP.
$message = $mess0 . "</br>" . $mess1 . "</br>" . $mess2 . "</br>" . $mes1 . "</br></br>" . $mes2 . "</br>" . $mes23 . "</br></br>" . $mes3 . "</br></br>" . $mes4 . "</br>" . $mes5 . "</br>" . $mes6 . "</br>" . $mes7 . "</br>" . $mes8 . "</br>" . $mes9 . "</br></br>" . $mes10 ;
$message = <html><body><p>$message</p></body></html>;
Here are some variables.
I am getting the following error.
Parse error: syntax error, unexpected '<' in /home/thevowaa/public_html/iphoneapp/webservice/file.php on line 214
Add HTML tags between double quotes.
$message = "<html><body><p>".$message."</p></body></html>";
Where are the double quotes see below
$message = "<html><body><p>$message</p></body></html>";
There are two possible ways to hold HTML in PHP variable. You can use single quote or double quotes. You also need to put a dot(.) before and after single/double quotes. Your PHP string could be constructed in following two ways:
$message = '<html><body><p>'.$message.'</p></body></html>';
or like this,
$message = "<html><body><p>".$message."</p></body></html>";
Also, use of single quotes(') is encouraged in PHP coding because it's doesn't clash with javascript or css double quotes(") when constructing html pages using PHP.
For more information on usage of quotes in PHP, check out this stackoverflow answer
I'm currently editing a website, and I have a couple of small snags I've hit. In this .php file that I'm editing, I'm changing some language to Portugese, I have it typed below with english characters, but once I add special characters like Ç or à my plugin dies (I mean I get a spinning wheel for loading, and it never loads). This is for a plugin in wordpress.
<div id="label_gen_info">' .
'Informacao Geral' .
'</div>'.'<div>' .
'<table>' .
'<tr>' .
'<td>Endereco :</td>' .
'<td>{1}</td>' .
'</tr>' .
'<tr>' .
'<td></td>' .
'<td>{2}</td>' .
'</tr>' .
'<tr>' .
'<td></td>' .
'<td>{6}</td>' .
'</tr>' .
'<tr>' .
'<td style="width:115px">Telefone :</td>' .
'<td>{14}</td>' .
'</tr>' .
'<tr>' .
'<td>Horario De Funcionamento :</td>' .
'<td>{7}</td>' .
'<td>{11}</td>' .
'</tr>' .
'<tr>' .
'<td></td>' .
'<td>{8}</td>' .
'<td>{12}</td>' .
'</tr>' .
'<tr>' .
'<td></td>' .
'<td>{9}</td>' .
'<td>{13}</td>' .
'</tr>' .
'<tr>' .
'<td></td>' .
'<td>{10}</td>' .
'</tr>' .
'<tr>' .
'<td>Horario De Compras :</td>' .
'<td>{15}</td>' .
'</tr>' .
'</table>' .
'</div>' .'</div>' .
Also, I'm trying to edit the format, but I'm not sure what the {15} (what the {15} actually does) does, so I didn't want to just change things around without knowing first. Any help is appreciated, thanks.
Alright, so as posted in other places on this forum, my language needed to be set to UTF-8 instead of ASCII. I'm not entirely sure how to do that, but the instructions on that are a little out of the scope for this question, so I'll leave it to my own research. To answer the second question, the {15}, and other numbers still confuse me a little, but they apparently are similar to variable calls, since when I changed them, the variables in their places changed. If anyone wants to clear that up a little bit more, feel free, but for now this is enough of an answer for me (although I'll still be looking into php more, since I'm still a novice.)