...

View Full Version : Error with query string...



Deacon Frost
03-14-2008, 12:25 AM
Well, I know mah query strings normally, which is why I cannot for the life of me figure this out...



<form action="http://www.chrysys.net/portfolios.php" method=get>
<input type="hidden" name="id" value="<? echo $id ?>">
<a href="http://www.chrysys.net/portfolios.php?id=<? echo $id ?>">
<?php echo $name ?></a>
</input>
</form>
<td>
<?php echo $rank ?>


I don't know why it won't send the data that's included. Each one was properly pulled from the database, so that's not the issue.

What happens, is when I click the $name in any given field, it takes me to the next page like it should with the url being "Http://www.chrysys.net/porfolios.php?id=1" or whatever I click. But when it does that, for some reason it doesn't pull the data from the database where the id = the one selected.

Here's my retrieving end:



<?php
include("/home/deacon/public_html/critical/includes/profilesconn.php");

$id = $_GET['id'];

$sql = "SELECT ID,Name,Rank,1,2,3,4,5,About,Interests,Services,Portfolio FROM profile WHERE ID = '".$id."'";
$result = mysql_query( $sql ) or die('The error was: ' . mysql_error() . '<br />The query was: ' . $sql);
while($row = mysql_fetch_array($result));
{
$id = $row['ID'];
$name = $row['Name'];
$rank = $row['Rank'];
$_1 = $row['1'];
$_2 = $row['2'];
$_3 = $row['3'];
$_4 = $row['4'];
$_5 = $row['5'];
$about = $row['About'];
$interests = $row['Interests'];
$services = $row['Services'];
$portfolio = $row['Portfolio'];
}
?>


I've managed to isolate the problem to the link, trying to get the data inside that for the next page, but I just can't seem to work it. I know that since it takes me to id=1, that the information is on the page, but for some reason it won't send to the next page.

Fumigator
03-14-2008, 12:53 AM
Is your HTML validating? Cuz, I'm not going to swear by it, but I don't think it's valid to stick an anchor inside a hidden input tag like what you've done. You should be closing that hidden input tag immediately and then do the anchor.

flynch01
03-14-2008, 02:07 AM
Yeah should it not be:


<form action="http://www.chrysys.net/portfolios.php" method=get>
<input type="hidden" name="id" value="<? echo $id ?>">
<a href="http://www.chrysys.net/portfolios.php?id=<? echo $id ?>"><?php echo $name ?></a>
</form>
<td>
<?php echo $rank ?>

I never used </input> in HTML, at the moment in XHTML i use <input/> but even so.

Deacon Frost
03-14-2008, 02:11 AM
Lol, this was my last attempt ;). Nothing has worked up to this point, and everything I've done (from not using a form and just doing the url, to what you see now) hasn't worked. I've used 5 different techniques to send the data, but for some reason, none of them work. It won't pull data from the database in portfolios.php?id=, and the isolated reason is that the id from the previous page doesn't load properly to send to the next page. So when it tries to select from the database where id=$id since $id is an unassigned value, it can't select anything.

That's my problem.

flynch01
03-14-2008, 02:30 AM
Oh I see what your trying to do. Hold on reserved post.


<a href="http://www.chrysys.net/portfolios.php?id=<? echo $id ?>"><?php echo $name ?></a>


$sql = "SELECT `ID`,`Name`,`Rank`,`1`,`2`,`3`,`4`,`5`,`About`,`Interests`,`Services`,`Portfolio` FROM `profile` WHERE `ID` = '".$id."'";

You don't need the url to be in the form, get variables are retrieved from the URL so the form isn't needed just replace the form with that url above. Secondly, as trivial as it is sometimes just adding ` to your sql elements makes a difference. It fixed my strange error before, wouldn't work then but worked after. I'm still not sure EXACTLY what the problem is but try it.

Deacon Frost
03-14-2008, 03:20 AM
Nope...

here:

http://www.chrysys.net/portfolio.php

click "Browse all portfolios" at the top.

Click "Deacon"

and you'll see. The image is set in the html, not the database.

But yeah, it didn't work, i dunno why...

Here are all three pages:



<?php include("/home/deacon/public_html/critical/includes/header.php"); ?>

<body>

<div class="left">

<ul>
<li><a href="index.php">Home</a></li>
<li class="active"><a href="portfolio.php">Portfolio</a></li>
<li><a href="services.php">Services</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>

</div>

<div class="right">


<div class="content">
<?php
$id = $_GET['id'];

if(!isset($id)){
include("/home/deacon/public_html/portfolios1.php");
}
else
{
include("/home/deacon/public_html/portfolios2.php");
}
//repeat for all styles/pages.
?>

<? include("/home/deacon/public_html/critical/includes/footer.php"); ?>




<?php
include("/home/deacon/public_html/critical/includes/profilesconn.php");
$sql = "SELECT ID,Name,Rank FROM profile ORDER BY ID LIMIT 30";
$result = mysql_query( $sql ) or die('The error was: ' . mysql_error() . '<br>The query was: ' . $sql);
$num = mysql_num_rows($result);
if($num > 0)
{
while($row = mysql_fetch_assoc($result))
{
$id = $row['ID'];
$name = $row['Name'];
$rank = $row['Rank'];
?>

<center>
<table width="75%">
<tr>
<td>
<h1>ID</h1>
<td>
<h1>Name</h1>
<td>
<h1>Rank</h1>
<tr>
<td>
<?php echo $id ?>
<td>
<a href="http://www.chrysys.net/portfolios.php?id=<? echo $id ?>"><?php echo $name ?></a>
</input>
</form>
<td>
<?php echo $rank ?>
</td>
</tr>
</table>
<?php
}
}
?>
</center>




<?php
include("/home/deacon/public_html/critical/includes/profilesconn.php");

$id = $_GET['id'];

$sql = "SELECT `ID`,`Name`,`Rank`,`1`,`2`,`3`,`4`,`5`,`About`,`Interests`,`Services`,`Portfolio` FROM `profile` WHERE `ID` = '".$id."'";
$result = mysql_query( $sql ) or die('The error was: ' . mysql_error() . '<br />The query was: ' . $sql);
while($row = mysql_fetch_array($result));
{
$id = $row['ID'];
$name = $row['Name'];
$rank = $row['Rank'];
$_1 = $row['1'];
$_2 = $row['2'];
$_3 = $row['3'];
$_4 = $row['4'];
$_5 = $row['5'];
$about = $row['About'];
$interests = $row['Interests'];
$services = $row['Services'];
$portfolio = $row['Portfolio'];
}
?>




<table width="75%">
<tr>
<td>
<a href="http://www.chrysys.net"><img src="/critical/images/me.jpg" alt="Find All of Deacon's Work" width="150" height="200" align="left" /></a>
<h1><? echo $name; ?></h1>
<h2><? echo $rank; ?></h2>
<hr>
<center><h2>Best Top 5</h2>
<ol>
<li><span><? echo $_1; ?></span></li>
<li><span><? echo $_2; ?></span></li>
<li><span><? echo $_3; ?></span></li>
<li><span><? echo $_4; ?></span></li>
<li><span><? echo $_5; ?></span></li>
</ol>
</center>
</td>
</tr>
</table>

<table width="75%">
<tr>
<td align>
<h2>About Me</h2>
<?php echo $about; ?>
</td>
</tr>
</table>

<br /><br />

<table width="75%">
<tr>
<td>
<h2>My Interests</h2>
<?php echo $interests; ?>
</td>
</tr>
</table>


<br /><br />

<table width="75%">
<tr>
<td>
<h2>My Services</h2>
<?php echo $services; ?>
</td>
</tr>
</table>


<br /><br />

<table width="75%">
<tr>
<td>
<h2>My Portfolio</h2>
<?php echo $portfolio; ?>
</td>
</tr>
</table>



They go in that order.

tomws
03-14-2008, 10:47 PM
<form action="http://www.chrysys.net/portfolios.php" method=get>
...


Perhaps you need method="get". Double quotes.

Deacon Frost
03-15-2008, 07:25 AM
Nah, I was really stupid when I did this. I couldn't use a form (which was my last attempt)..

So I solved it using the methods taught by learning C++ :P.

Basically I used the fetch_num_rows to see if the data was getting to the page, then I echoed it to display, and when I saw the '1' I realized that it did in fact pull the information for the prior page.

my error was here:



while($row = mysql_fetch_array($result));


which I changed to



$row = mysql_fetch_assoc($result);



Which solved it :P.


Thanks to all who attempted :D. (Sorry for not trying a lil harder =/)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum