...

View Full Version : Issue with code



CoolAsCarlito
08-05-2008, 03:24 PM
<?php
}
else
{
?>
<center><table><tr><td>Title:</td><td>
<?php
echo '<select onchange="showTitle(this.value)">';
$data = mysql_query("SELECT titlename FROM titles");
while($row = mysql_fetch_assoc($data)) {
echo '<option value="'.$row['titlename'].'">'.$row['titlename'].'</option>';
}
echo '</select>';
?></td></tr></table></center>
<?php
$q=$_GET["q"];

$con = mysql_connect('?", "?", "?"');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("?", $con);

$sql="SELECT * FROM titles WHERE id = '".$q."'";

$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>Title Name:</th>
<th>Type:</th>
<th>Status:</th>
<th>Champion:</th>
<th>Contender 1:</th>
<th>Contender 2:</th>
<th>Contender 3:</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<input type="text" name="titlename" maxlength="60" value=" . $row['type'] . ">";
echo "<select name="type" value=" . $row['type'] . ">"
<option>Singles</option><option>Tag Team</option><option>Stable</option></select>;
echo "<select name="status" value=" . $row['status'] . ">"
<option>Active</option><option>Inactive</option></select>;

echo '<select value=" . $row['champion'] . ">';
$data = mysql_query("SELECT wrestlingname FROM singles");
while($row = mysql_fetch_assoc($data)) {
echo '<option value="'.$row['wrestlingname'].'">'.$row['wrestlingname'].'</option>';
echo '</select>';

echo '<select value=" . $row['champion'] . ">';
$data = mysql_query("SELECT wrestlingname FROM singles");
while($row = mysql_fetch_assoc($data)) {
echo '<option value="'.$row['wrestlingname'].'">'.$row['wrestlingname'].'</option>';
echo '</select>';

echo '<select value=" . $row['champion'] . ">';
$data = mysql_query("SELECT wrestlingname FROM singles");
while($row = mysql_fetch_assoc($data)) {
echo '<option value="'.$row['wrestlingname'].'">'.$row['wrestlingname'].'</option>';
echo '</select>';
echo '<select value=" . $row['champion'] . ">';
$data = mysql_query("SELECT wrestlingname FROM singles");
while($row = mysql_fetch_assoc($data)) {
echo '<option value="'.$row['wrestlingname'].'">'.$row['wrestlingname'].'</option>';
echo '</select>';

}
echo "</table>";

mysql_close($con);
?>


<?php
}
?>

djm0219
08-05-2008, 03:26 PM
I'm sorry but my mind reader is broken. What is your "issue with code"?

derzok
08-05-2008, 03:27 PM
...and the issues are? We don't read minds. What should it be doing? What is the script doing? Is it printing the wrong data? Is it showing you an error? Is it displaying nothing at all?

Edit: Looks like Dave beat me to the punch

CoolAsCarlito
08-05-2008, 03:28 PM
It says Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/content/y/a/n/yankeefaninkc/html/edittitle2.php on line 71

But I can't find it.

derzok
08-05-2008, 03:32 PM
It looks fine to me (unless I'm sleepier than I thought this morning)... Are you sure you've uploaded the most recent version of the code and that you aren't running an old one? One thing you might want to do: put your


echo '</select>';


OUTSIDE your while loop - otherwise you'll display a '</select>' for every value of the drop down.

That wouldn't cause PHP errors though, that'd just make the html look funny...

malfist
08-05-2008, 03:34 PM
look at this:


echo "<input type="text" name="titlename" maxlength="60" value=" . $row['type'] . ">";
echo "<select name="type" value=" . $row['type'] . ">"


That's part of the problem, the interpreter reads it as
echo "<input type=" <--expected simicolon
text <--where does this come from
" name=" <--String, what do I do with this?

CoolAsCarlito
08-05-2008, 03:39 PM
What should I do with it though?

derzok
08-05-2008, 03:39 PM
Just noticed some more errors - you never close any of your while loops. They're all like this:



while(something = mysql_something) {
// some stuff

while(something = mysql_something) {
// some more stuff

Instead of:



while(something = mysql_something) {
// some stuff
}
while(something = mysql_something) {
// some more stuff
}


You need a closing bracket if you have an opening bracket!


What should I do with it though?

Put it in single quotes instead - like you did for the other HTML you outputted. It's traditional to put HTML in single quotes (because you so often have to use double quotes inside of it) and to put text inside of regular quotes (because we often put apostrophes in our text). This prevents needing to escape every quote. If you have your heart set on using double quotes you'll have to add a '\' character in front of every double quote inside of the outermost double quotes - ie: "the man said "Hello"" => "the man said \"Hello\"" - the same rule follows for single quotes: 'The man said 'Boo!'' => 'The man said \'Boo!\'' - this is why we blend quotes the way we do: 'The man said "Hello"' or "the man said 'Boo!'"

malfist
08-05-2008, 03:43 PM
What should I do with it though?

You should lookup what to do with quotes. Use ' and ", and you can also escape it like \"

http://ca.php.net/types.string

CoolAsCarlito
08-05-2008, 04:47 PM
Okay well I erased a whole bunch of things off the php and tried doing a little bit at a time and try making it work one piece at a time.

http://www.kansasoutlawwrestling.com/edittitle2.php

See my problem now?

derzok
08-05-2008, 04:56 PM
I see the problem but I need to see the code in order to correct it... It looks like you just missed some quotes but I'd have to look to know where.

CoolAsCarlito
08-05-2008, 05:28 PM
http://kansasoutlawwrestling.com/edittitle2.php

Code is here:



<html>
<head>
<script src="selecttitle.js"></script>
</head>


<?php
// Connects to your Database
$link = mysql_connect("?", "?", "?") or die(mysql_error());
mysql_select_db("?",$link) or die(mysql_error());

if (!mysql_select_db("?", $link)) {
echo 'Could not select database';
exit;
}
?>
<center><table><tr><td>Title:</td><td>
<?php
echo '<select onchange="showTitle(this.value)">';
$data = mysql_query("SELECT titlename FROM titles");
while($row = mysql_fetch_assoc($data)) {
echo '<option value="'.$row['titlename'].'">'.$row['titlename'].'</option>';
}
echo '</select>';
?></td></tr></table></center>

<center><table border=1 cellpadding=5 cellspacing=0 width=350>
<font color="#CC0000"><h2><center>Edit a Title</h2></center></font>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<tr><td>Title Name:</td><td>
<input type="text" name="titlename" maxlength="60" value=" . $row['titlename'] . ">
</td></tr>

</html>

malfist
08-05-2008, 05:32 PM
this:


<input type="text" name="titlename" maxlength="60" value=" . $row['FirstName'] . ">

Is html, you need part of that to be php.

CoolAsCarlito
08-05-2008, 06:49 PM
Huh? WHat do you mean?

malfist
08-05-2008, 06:51 PM
What I mean is, there's no PHP there, it's just HTML. HTML sees you want the value to be " . $row['FirstName'] . ", so it makes it " . $row['FirstName'] . ". However something like this might be more appropriate for what you want.


<input type="text" name="titlename" maxlength="60" value="<?php echo $row['FirstName']; ?>">

CoolAsCarlito
08-05-2008, 07:12 PM
Okay so I edited it all but it won't insert the info.



<html>
<head>
<script src="selectitle.js"></script>
</head>


<?php
// Connects to your Database
$link = mysql_connect("?", "?", "?") or die(mysql_error());
mysql_select_db("?",$link) or die(mysql_error());

if (!mysql_select_db("?", $link)) {
echo 'Could not select database';
exit;
}
?>
<center><table><tr><td>Title:</td><td>
<?php
echo '<select onchange="showTitle(this.value)">';
$data = mysql_query("SELECT titlename FROM titles");
while($row = mysql_fetch_assoc($data)) {
echo '<option value="'.$row['titlename'].'">'.$row['titlename'].'</option>';
}
echo '</select>';
?></td></tr></table></center>
<?php
$q=$_GET["q"];

// Connects to your Database
$link = mysql_connect("?", "?", "?") or die(mysql_error());
mysql_select_db("?",$link) or die(mysql_error());

if (!mysql_select_db("?", $link)) {
echo 'Could not select database';
exit;
}

$sql="SELECT * FROM titles WHERE id = '".$q."'";

$result = mysql_query($sql);
?>
<center><table border=1 cellpadding=5 cellspacing=0 width=350>
<font color="#CC0000"><h2><center>Edit a Title</h2></center></font>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<tr><td>Title Name:</td><td>
<input type="text" name="titlename" maxlength="60" value=" <?php echo $row['titlename']; ?>">
</td></tr>

</html>

malfist
08-05-2008, 08:20 PM
print out the array and see what you get.

CoolAsCarlito
08-05-2008, 08:21 PM
And that's done how? lol

malfist
08-05-2008, 08:22 PM
Maybe someone should google it :P

http://oreilly.com/catalog/progphp/chapter/ch05.html

CoolAsCarlito
08-05-2008, 08:33 PM
Which array?

print "$array?";

malfist
08-05-2008, 08:35 PM
Please read that, it says about half way down. It's very informational, and you may find it beneficial.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum