I have a file /admin/php.php which has the following:
<?php
$ID=$_GET['ID'];
require("../admin/config.php");
$sql = "SELECT * FROM contacts WHERE contacttype IN ('New','Buyer','Seller','Buyer / Seller','Investor') AND leadstatus = 'New' ORDER BY date DESC";
$space = (!empty($row['firstname']) && !empty($row['lastname'])) ? ' ' : '';
$name = $row['firstname'].$space.$row['lastname'];
$partner = $row['spousefirst'];
$cell = (!empty($row['phonecell'])) ? " {$row['phonecell']} (cell)" : '';
$email = (!empty($row['email'])) ? " {$row['email']} (email)" : '';
mysql_query($sql) or die ("Error: ".mysql_error());
?>
On another page /admin/index.php I have:
<?php require("php.php"); ?>
<tbody>
<tr>
<td><input type="checkbox" name="" id="" value="<?php echo $row['ID']; ?>"></td>
<td><strong><?php echo $name; ?></strong></td>
<td><?php echo $partner; ?></td>
<td><?php echo $row['phonecell']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo date("M jS, g:i A", strtotime($row['date'])); ?></td>
<td><?php echo $row['contacttype']; ?></td>
<td><?php echo $row['agentassigned']; ?></td>
<td><?php echo $row['leadstatus']; ?></td>
<td>View + </td>
<td>View + </td>
<td>D</td>
</tr>
</tbody>
<?php
}
mysql_close();
?>
</table>
When I run this, I get a Parse error: syntax error, unexpected '}' in /admin/index.php. I've tried removing the '}' after <?php in /admin/index.php and I get an error for unexpected $end in /admin/php.php. Really confused why this isn't working. Thanks for your help!
First of all, } should not be there. There is no opening { in this file, so there should not be a closing one.
Next up, unexpected $end - that error is in another file, so that's another problem.
The syntax of php.php looks valid, but:
your mysql_query call should return a result, and i don't see you assigning it to anything.
check that closing ?> isn't followed/preceeded by non-printable characters we do not see here, but that can make parser choke - basically, remove that line, recreate it and save the file.
<?php
}
mysql_close($sql);
?>
You have closing bracket but I can't see opening.
the "}" will cause an error from the code that is posted in your question. I'm not sure if this is all the code though.
also another question would be are you connection to a database at all? cause there is nothing in your code here that shows that either.
and you are not doing anything after the mysql_query($sql) is ran.
Related
I've been turning in circles for a while now trying to understand what I have done wrong with lines 68 and 110. It comes up with:
"expects parameter 1 to be resource, boolean given"
but I don't understand where my mistake is. Would someone be able to point me in the right direction or explain my error so I can better understand?
I'm really new to PHP (only started learning it last week) so I've been mostly doing my best with tutorials and what I can find online.
Line 68 onwards:
while($row = mysql_fetch_array($query)){
$card_number = $row['card_number'];
$card_id = $row['card_id'];
$card_name = $row['card_name'];
$card_mana_img = $row['card_mana_img'];
$card_type = $row['card_type'];
$card_rarity = $row['card_rarity'];
$card_set = $row['card_set'];
}
?>
Lines 99 onwards:
<table>
<tr>
<td>Number</td>
<td>Name</td>
<td>Type</td>
<td>Mana</td>
<td>Rarity</td>
<td>Set</td>
</tr>
<?php while ($row = mysql_fetch_array($query)) { ?>
<tr>
<td><?php echo $card_number; ?></td>
<td><?php echo $card_name; ?></td>
<td><?php echo $card_type; ?></td>
<td><?php echo $card_mana_img; ?></td>
<td><?php echo $card_rarity; ?></td>
<td><?php echo $card_set; ?></td>
</tr>
<?php } ?>
</table>
<br>
<?php echo $paginationCtrls; ?><br>
<?php echo $textline2;?><br>
<?php echo $textline1;?>
Don't use this: $sql = "SELECT number FROM magicorigins_cardset";
Use this:
$sql = "SELECT count(*) FROM magicorigins_cardset";
underneath is a small script which shows if someone has a birthday today.
The only thing what i miss is a line under the name with the text "Happy birthday" It should only appear, ofcourse is someone has a birthday. how can i achieve this?
<html>
<head>
<title>Vandaag Jarig:</title>
</head>
<body>
<table>
<thead>
</thead>
<tbody>
<?php
$connect = mysql_connect("localhost","root", "****");
if (!$connect) {
die(mysql_error());
}
mysql_select_db("my_site_db");
$results = mysql_query
("SELECT * FROM aevinew2_verjaardagen WHERE DAY(geboortedatum) = DAY (CURDATE ()) AND MONTH(geboortedatum) = MONTH(CURDATE())");
if(mysql_num_rows($results) > 0){
while($row = mysql_fetch_array($results)) {
?>
<tr>
<td><?php echo $row['Naam']?></td>
<td><?php echo $row['Afdeling']?></td>
</tr>
<?php
}
}else{
echo "Helaas geen taart vandaag, er is niemand jarig";
}
?>
</tbody>
</table>
</body>
</html>
Something like this? You had syntax error in your code aswell. Missing ; delimiter at end of echo command.
<td><?php echo $row['Naam'].'<br/>Happy Birthday!'; ?></td>
<td><?php echo $row['Afdeling']; ?></td>
Replace line 22 ,23 with these lines. You are missing ';' after echo statement.
<td><?php echo $row['Naam'].'<br/>Happy Birthday!'; ?></td>
<td><?php echo $row['Afdeling']; ?></td>
well, the script is working (it was already), but the only thing i need is an echo under the current echo which is just showing some text.
If i do that it letterly puts that kind of text on top include the text Echo
I am receiving a "Fatal error" once the function fetch_array(mysqli_both) is invoked. The file below on the while instance is exactly where the error is coming from.
<?php
include 'connect.php';
$id = $_SESSION['user_id'];
$res = mysqli_query($mysqli, "SELECT a.name,j.link,j.points, a.submit_time from journal j, article a where a.journal_id = j.id and a.professor_id = $id");
?>
<table>
<tr>
<th>Article</th>
<th>Journal</th>
<th>Points</th>
<th>Time</th>
</tr>
<?php
while ($row = $res->fetch_array(MYSQLI_BOTH)) {
?>
<tr>
<td><?php echo $row[0] ?></td>
<td><?php echo $row[1] ?></td>
<td><?php echo $row[2] ?></td>
<td><?php $date = date_create($row[3]);
echo date_format($date, 'Y-m-d H:i:s'); ?></td>
<tr>
<?php
}
?>
</table>
When i try it on my wampserver i don't have this problem as i activated couple of PHP extensions. Online, i don't think it's easy to activate such extensions. Do you think this error is related to the fact that i didn't invoked the $query as a variable with $mysqli in line 4?
First of all you should use require_once('connect.php'); because it is a needed file for this code.
Also you have to check your $mysqli variable if it's a correct connection to your database.
For more help you might have to post the full Error-Message
you should check result before fetch:
if ($res) {
while ($row = $res->fetch_array(MYSQLI_BOTH)) {
...
...
}
} else {
echo printf("Errormessage: %s\n", mysqli_error($mysqli));
}
I've been troubleshooting for a while now, and I really can't find any answer. Basically this is what it looks like:
When I type the name of a real user: Nothing posted on the page with an exception of the header
When I type a fake user: User has not been found (direct translation from Norwegian in the code)
<?php
include_once("moduler/head.php");
$user = $_GET['user'];
$query1 = $con->query("SELECT * FROM players WHERE name='$user'");
echo $con->error;
if ($query1->num_rows == 0) {
echo "<h1>Ingen spiller funnet med: $user.</h1>";
return;
}
while ($row == mysqli_fetch_array($query1)) {
$styrkeLvl = $row['styrke'];
$beskyttelseLvl = $row['beskyttelse'];
$bueskytingLvl = $row['bueskyting'];
$trehuggingLvl = $row['trehugging'];
$gruvedriftLvl = $row['gruvedrift'];
$fiskingLvl = $row['fisking'];
$kills = $row['kills'];
$deaths = $row['deaths'];
$rank = $row['rank'];
$money = $row['money'];
$donstatus = $row['donationstatus'];
$lastlogin = $row['lastlogin'];
$regtime = $row['registrationtime'];
$rankName = getRankString($rank);
?>
<h1><?php echo $user; ?></h1>
<table class=\"userView\">
<tbody>
<tr><td>Brukerstatus</td>
<td><?php echo $rankName; ?></td>
</tr>
<tr><td>Donasjon status</td>
<td>D<?php echo $donstatus; ?></td>
</tr>
<tr><td>Styrke level</td>
<td><?php echo $styrkeLvl; ?></td>
</tr>
<tr><td>Beskyttelse level</td>
<td><?php echo $beskyttelseLvl; ?></td>
</tr>
<tr><td>Bueskyting level</td>
<td><?php echo $bueskytingLvl; ?></td>
</tr>
<tr><td>Trehugging level</td>
<td><?php echo $trehuggingLvl; ?></td>
</tr>
<tr><td>Fisking level</td>
<td><?php echo $fiskingLvl; ?></td>
</tr>
<tr><td>Drap</td>
<td><?php echo $kills; ?></td>
</tr>
<tr><td>Dødsfall</td>
<td><?php echo $deaths; ?></td>
</tr>
<tr><td>Sist pålogget</td>
<td><?php echo $lastlogin; ?></td>
</tr>
<tr><td>Registreringsdato</td>
<td><?php echo $regtime; ?></td>
</tr>
</tbody>
</table>
<?php
}
?>
Any ideas? I've also tried running the entire thing in an echo with no result
Thanks
All your variables inside the while loop are only available inside the while loop. so you cannot echo them in the tables. so <td><?php echo $rankName; ?></td> will give you an undefined variable error. The same applies for the other variables you are trying to display.
To avoid this you should try to declare your variables globally, or put your table inside the loop.
Also the other issue is that as it is the code inside the loop will never execute because of the double equal (==). You should use double equal (==) for comparison and single equal (=) for assignment.
So you have to change while ($row == mysqli_fetch_array($query1)) to while ($row = mysqli_fetch_array($query1))
I'm trying to figure out what's wrong with my mysqli code below. The data is definitely in the table. I have 2 questions:
Why isn't this giving me any results?
Could I have the echo <table></table> section in a separate php file, if yes, how would I call $name,$partner,$cell etc.?
<?php
$mysqli = new mysqli($host, $uname, $pword, $db);
if ($mysqli->connect_errno)
{
echo "Connection failed: %s\n", $mysqli->connect_error;
exit();
}
$query = ("SELECT * FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND leadstatus = 'New' ORDER BY date DESC");
$result = $mysqli->query($query);
while ($row = $result->fetch_array()) {
$space = (!empty($row['firstname']) && !empty($row['lastname'])) ? ' ' : '';
$name = $row['firstname'].$space.$row['lastname'];
$partner = $row['spousefirst'];
$cell = (!empty($row['phonecell'])) ? " {$row['phonecell']} (cell)" : '';
$email = (!empty($row['email'])) ? " {$row['email']} (email)" : '';
$ID = $row['ID'];
echo'<table>
<tbody>
<tr>
<td><input type="checkbox" name="" id="" value="<? echo $ID; ?>"></td>
<td><strong><? echo $name; ?></strong></td>
<td><? echo $partner; ?></td>
<td><? echo $phonecell; ?></td>
<td><? echo $email; ?></td>
<td><? echo date("M jS, g:i A", strtotime($date)); ?></td>
<td><? echo $contacttype; ?></td>
<td><? echo $agentassigned; ?></td>
<td><? echo $leadstatus; ?></td>
<td>View + </td>
<td>View + </td>
<td>D</td>
</tr>
</tbody>
</table>';
}
?>
EDIT:
It's showing the <table> but just not giving me values for $name, $email...ect.
The final echo does not look well constructed. I would prefer to use a concatenated string to output the variables, just like this( I put only a few lines as example):
echo'<table>
<tbody>
<tr>
<td><input type="checkbox" name="" id="" value="'. $ID .'"></td>
<td><strong>'. $name.' </strong></td>
The query looks solid as does the rest of your code. Here are a few troubleshooting steps to try out:
echo out $query and run it directly against your database. Do you get results? If you don't get any results from a direct query then that means the query is returning 0 rows and your tables will end up empty as well.
Do a var_dump($result) to verify there is information being stored in there. You could also add change $result = $mysqli->query($query); to $result = $mysqli->query($query) or die $mysqli->error;
The results from these 2 steps should give you a good idea on where things are going wrong. In general you want to stop through each part of the query process and look at every variable involved to ensure that it has the data you expect stored inside of it.
To answer your 2nd question: yes you can. If you put the code for the table in a separate file and then include()it, the variables will still be available to the included code.
See the PHP manual on include()