...

View Full Version : HTML to PHP Form Input and Submit



Psionicsin
08-29-2011, 07:03 PM
The various HTML character codes in here have totally disoriented me, so I need some help. I'm trying to fit the following code into a PHP echo statement.


<form action ="/tally.php?sen_id=$row[sen_id]" method="post">
<input type="submit" name="submit" value="Vote" >
</form>


I've turned it into this, but think I've done somehing wrong as it's passing out errors all over.


<?php echo
"&lt;form action =&quot;/tally.php?sen_id=$row[sen_id]&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Vote&quot; /&gt;
&lt;/form&gt;"
; ?>


Is there something that's missing, or that I forgot, or that I did wrong?

Fou-Lu
08-29-2011, 07:23 PM
Why are you echoing out special characters? These will not be parsed by an HTML browser. They will instead be treated as a textual display within the html, so you could use it in something like a <textarea>, but not as an actual form.

Without seeing your errors, we cannot troubleshoot that problem. I presume one will be undefined variable $row, and another as undefined offset since what you have here doesn't construct a $row array.

Psionicsin
08-29-2011, 07:33 PM
Why are you echoing out special characters? These will not be parsed by an HTML browser. They will instead be treated as a textual display within the html, so you could use it in something like a <textarea>, but not as an actual form.

Without seeing your errors, we cannot troubleshoot that problem. I presume one will be undefined variable $row, and another as undefined offset since what you have here doesn't construct a $row array.

I sorry, I wasn't aware of that. I'm trying to deconstruct, and reapply sections of coding that has been created for our original voting section in order to apply it to a mobile form of the page. The original coding is:

<?php

include("./templates/mysql_connect.php");

//FOR LETTER: A

$query = "SELECT * FROM seniors WHERE last_name LIKE 'A%' ORDER BY last_name ASC";
$result = @mysql_query ($query);

echo '<table><tr>
<td>
<p><span class="style19"><u>-A-</u></span><br />';

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

echo "<a href=\"$row[pic_url]\" rel=\"lightbox[seniors]\"
title=\" &lt;form action =&quot;/sencha-tallyvote.php?sen_id=$row[sen_id]&quot; method=&quot;post&quot;&gt;

$row[first_name] $row[last_name] - $row[school] <br />

&nbsp; &nbsp; &lt;input name=&quot;submit&quot; align=&quot;right&quot; type=&quot;submit&quot; value=&quot;Vote&quot; &gt;

&lt;/form&gt; \">$row[last_name], $row[first_name]</a><br/>";

}
echo '</p>';
?>

I was trying to replicate what the other programmer did by viewing the code above, which is where I got the special characters from. So far I have everything but the vote button, and it's throwing me for a loop.

Code I have currently (constantly changing it to see what works) is:

<?php
require_once('templates/mysql_connect.php');
?>

<?php
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result);
?>

<div class="contents">
<h1><?php echo $row['first_name'], " ", $row['last_name']; ?></h1>
<h4><?php echo $row['school']; ?></h4>
</div>

<?php echo
'<a href="sencha.php" class="bigmenu"><img src="images/backarrow.png" alt="Back to Senior Challenge Home" class="arrowleft indexicon" /><u>Back</u></a><br />'; ?>

<?php echo "<img src=\"http://www.rutholsonphoto.com" .$row['pic_url']. "\" width=\"100%\" />"; ?> <br />
<br />

<?php echo "<form action="tally.php?sen_id=$row[sen_id]" method="get">
<input type="submit" name="submit" value="Vote" />
</form>";
?>

Fou-Lu
08-29-2011, 07:38 PM
The only thing wrong with this is the missing escape sequences.


<?php echo "<form action="tally.php?sen_id=$row[sen_id]" method="get">
<input type="submit" name="submit" value="Vote" />
</form>";
?>

Should be


<?php
echo '<form action="tally.php?sen_id=' . $row['sen_id'] . '" method="get">
<input type="submit" name="submit" value="Vote" />
</form>';
?>

// or
<?php echo "<form action=\"tally.php?sen_id={$row['sen_id']}\" method=\"get\">
<input type=\"submit\" name=\"submit\" value=\"Vote\" />
</form>";
?>



Also, make sure you google up PHP sql injection prevention. You're code is wide open to attack.

Psionicsin
08-29-2011, 07:56 PM
Also, make sure you google up PHP sql injection prevention. You're code is wide open to attack.


Thanks for that. I'll get on that ASAP. However I tried to implement the example code and, although it created the button and link tot he page just fine, it seems to not be passing the data along to the next page as the fields remain blank and get the error:


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/web01/b829/moo.rophoto1/rop-mobile/tally.php on line 87

Fou-Lu
08-29-2011, 08:30 PM
That error indicates that your query has failed. It could be caused for many different reasons.
Assuming that this code is not tally.php, you will need to post tally.php in order to diagnose the SQL error.

Psionicsin
08-29-2011, 08:33 PM
That error indicates that your query has failed. It could be caused for many different reasons.
Assuming that this code is not tally.php, you will need to post tally.php in order to diagnose the SQL error.


<?php
require_once('templates/mysql_connect.php');

/////////////
function escape_data ($data)
{
global $dbc;

if(ini_get('magic_quotes_gpc'))
$data = stripslashes($data);

return mysql_real_escape_string($data, $dbc);
}
////////////

$ip=$_SERVER['REMOTE_ADDR'];

$queryIP = "SELECT INET_NTOA('ip') FROM ips WHERE ip=INET_ATON('$ip')";
$resultIP = mysql_query ($queryIP);
$existIP = mysql_num_rows($resultIP);


if (isset($_COOKIE['vote']) || $existIP > 0)
{
$message = "<b>You have already voted in this year's Senior Challenge!</b> <p>To view the rankings of the current Senior Challenge contestants, <a href=\"/top10.php\">CLICK HERE</a></p>";
}
else
{
//Get Senior info
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result);

//Tally vote
$votes = $row['votes'] + 1;
$queryTally = "UPDATE seniors SET votes='$votes' WHERE sen_id=$_GET[sen_id] LIMIT 1";
$resultTally = mysql_query ($queryTally);

if(isset($resultTally))
{
$message = "<b>Your vote has been registered!</b> <p>Thank you for participating in the 2012 Senior Challenge. To view the rankings of the current Senior Challenge contestants, <a href=\"/top10.php\">click here</a></p>";

//Set cookie + ip
setcookie ("vote", "yes", time()+15552000);
$queryInsertIP = "INSERT INTO ips (ip, person) VALUES(INET_ATON('$ip'), '$row[last_name]')";
$resultInsertIP = mysql_query ($queryInsertIP);

}
else
{
$message = "<b>Error: Vote was not counted!</b> <p>You have encountered an error, and your vote was NOT tallied. Please, <a href=\"/contact.html\">contact us</a> to tally your vote.</p>";
}
}

?>

<?php
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result);
?>

<h3><?php echo $row['first_name'], " ", $row['last_name'], " has <font style=\"color:#FF0000\">
$row[votes]</font> votes";?></h3>

<?php echo "<p>", $message. "</p>"?>

Fou-Lu
08-29-2011, 08:36 PM
Change this line: $result = mysql_query ($query); to this: $result = mysql_query($query) or die(sprintf('MySQL error: %s, GET: <pre>%s</pre>', mysql_error(), print_r($_GET, true))); and post that result.

Psionicsin
08-29-2011, 08:40 PM
Change this line: $result = mysql_query ($query); to this: $result = mysql_query($query) or die(sprintf('MySQL error: %s, GET: <pre>%s</pre>', mysql_error(), print_r($_GET, true))); and post that result.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/web01/b829/moo.rophoto1/rop-mobile/tally.php on line 86
has votes

You have already voted in this year's Senior Challenge!

To view the rankings of the current Senior Challenge contestants, CLICK HERE

Fou-Lu
08-29-2011, 08:42 PM
The following messages indicate that its the first query that is failing. Change $resultIP = mysql_query ($queryIP); to $resultIP = mysql_query($queryIP) or die(sprintf('MySQL error: %s, GET: <pre>%s</pre>', mysql_error(), print_r($_GET, true)));


Something's not right here. There is no fetch_* call before that line of output. The line numbers don't line up either, you don't have 87 lines of code in this.
Are you sure this is the correct script?

Psionicsin
08-29-2011, 08:48 PM
The following messages indicate that its the first query that is failing. Change $resultIP = mysql_query ($queryIP); to $resultIP = mysql_query($queryIP) or die(sprintf('MySQL error: %s, GET: <pre>%s</pre>', mysql_error(), print_r($_GET, true)));


Something's not right here. There is no fetch_* call before that line of output. The line numbers don't line up either, you don't have 87 lines of code in this.
Are you sure this is the correct script?


The full code, including the stuff for HTML is:


<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
<meta name="author" content="Brandon Moner" />
<script type="text/javascript" type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" />

<title>Ruth Olson Photography</title>
</head>

<body>

<header>
<div class="top">
<div class="contents">
<a href="index.php"><img src="/images/logo.png" width="100%" alt="Ruth Olson Photography" /></a>
<!-- <h1><a href="index.php">Ruth Olson Photography</a></h1> -->
</div>
</div>
</header>

<div class="container">

<?php
require_once('templates/mysql_connect.php');

/////////////
function escape_data ($data)
{
global $dbc;

if(ini_get('magic_quotes_gpc'))
$data = stripslashes($data);

return mysql_real_escape_string($data, $dbc);
}
////////////

$ip=$_SERVER['REMOTE_ADDR'];

$queryIP = "SELECT INET_NTOA('ip') FROM ips WHERE ip=INET_ATON('$ip')";
$resultIP = mysql_query ($queryIP);
$existIP = mysql_num_rows($resultIP);


if (isset($_COOKIE['vote']) || $existIP > 0)
{
$message = "<b>You have already voted in this year's Senior Challenge!</b> <p>To view the rankings of the current Senior Challenge contestants, <a href=\"/top10.php\">CLICK HERE</a></p>";
}
else
{
//Get Senior info
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result);

//Tally vote
$votes = $row['votes'] + 1;
$queryTally = "UPDATE seniors SET votes='$votes' WHERE sen_id=$_GET[sen_id] LIMIT 1";
$resultTally = mysql_query ($queryTally);

if(isset($resultTally))
{
$message = "<b>Your vote has been registered!</b> <p>Thank you for participating in the 2012 Senior Challenge. To view the rankings of the current Senior Challenge contestants, <a href=\"/top10.php\">click here</a></p>";

//Set cookie + ip
setcookie ("vote", "yes", time()+15552000);
$queryInsertIP = "INSERT INTO ips (ip, person) VALUES(INET_ATON('$ip'), '$row[last_name]')";
$resultInsertIP = mysql_query ($queryInsertIP);

}
else
{
$message = "<b>Error: Vote was not counted!</b> <p>You have encountered an error, and your vote was NOT tallied. Please, <a href=\"/contact.html\">contact us</a> to tally your vote.</p>";
}
}

?>

<?php
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result);
?>

<h3><?php echo $row['first_name'], " ", $row['last_name'], " has <font style=\"color:#FF0000\">
$row[votes]</font> votes";?></h3>

<?php echo "<p>", $message. "</p>"?>

<br />

</div>

<footer class="contents">
<p>&copy; Copyright 2003 - <?php echo date("Y") ?> Ruth Olson Photography</p>
</footer>

</body>

</html>

Fou-Lu
08-29-2011, 09:04 PM
Ok, that's a little closer. Are you pulling that text off of the browser window or from the source? That error should come AFTER the text below it, so I'm thinking that this may be an HTML output and not source output.
What is the results of the modification to the ip check?

Psionicsin
08-29-2011, 09:28 PM
Ok, that's a little closer. Are you pulling that text off of the browser window or from the source? That error should come AFTER the text below it, so I'm thinking that this may be an HTML output and not source output.
What is the results of the modification to the ip check?

I'm getting this directly from the actual backup file. Not viewing from any type of browser.

And the output from the IP change was the same as the other, unless you want me to post the source of the output.

Fou-Lu
08-29-2011, 09:31 PM
I'm getting this directly from the actual backup file. Not viewing from any type of browser.

And the output from the IP change was the same as the other, unless you want me to post the source of the output.

So are you executing this via PHP and storing it into an html file? That kinda defeats the purpose of using PHP to dynamically create the data though.
What is the results of the ip query check?

Psionicsin
08-29-2011, 09:40 PM
So are you executing this via PHP and storing it into an html file? That kinda defeats the purpose of using PHP to dynamically create the data though.
What is the results of the ip query check?

No. Everything is inside of a PHP file that has HTML inside of it. Since this is for mobile devices, I didn't want to be making too many server calls due to some people having capped data plans.

And the output that was displayed on the page for the IP query was Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/web01/b829/moo.rophoto1/rop-mobile/tally.php on line 86
has votes

You have already voted in this year's Senior Challenge!

To view the rankings of the current Senior Challenge contestants, CLICK HERE

Fou-Lu
08-29-2011, 10:12 PM
What is the current code you have now?
Also, you don't need to use a mobile device to test this. You can use a browser to check the source code. I still don't know what you are referring to as a 'backup file'.

Wait, you have a similar query further into the script. The first modification is the one you could use:


<?php
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query($query) or die(sprintf('MySQL error: %s, GET: <pre>%s</pre>', mysql_error(), print_r($_GET, true)));
$row = mysql_fetch_array ($result);
?>

<h3><?php echo $row['first_name'], " ", $row['last_name'], " has <font style=\"color:#FF0000\">
$row[votes]</font> votes";?></h3>

<?php echo "<p>", $message. "</p>"?>

<br />

</div>

<footer class="contents">
<p>&copy; Copyright 2003 - <?php echo date("Y") ?> Ruth Olson Photography</p>
</footer>

</body>

</html>


I'm betting the first change you made was against that query in the if branch.

Psionicsin
08-29-2011, 10:51 PM
What is the current code you have now?
Also, you don't need to use a mobile device to test this.

I started from scratch again, so from the original code. I'm testing it in an actual browser, I was just informing you what it's use was for.

Current Source Code from File:

<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
<meta name="author" content="Brandon Moner" />
<script type="text/javascript" type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" />

<title>Ruth Olson Photography</title>
</head>

<body>

<header>
<div class="top">
<div class="contents">
<a href="index.php"><img src="/images/logo.png" width="100%" alt="Ruth Olson Photography" /></a>
<!-- <h1><a href="index.php">Ruth Olson Photography</a></h1> -->
</div>
</div>
</header>

<div class="container">

<?php
require_once('templates/mysql_connect.php');

/////////////
function escape_data ($data)
{
global $dbc;

if(ini_get('magic_quotes_gpc'))
$data = stripslashes($data);

return mysql_real_escape_string($data, $dbc);
}
////////////

$ip=$_SERVER['REMOTE_ADDR'];

$queryIP = "SELECT INET_NTOA('ip') FROM ips WHERE ip=INET_ATON('$ip')";
$resultIP = mysql_query ($queryIP);
$existIP = mysql_num_rows($resultIP);


if (isset($_COOKIE['vote']) || $existIP > 0)
{
$message = "<b>You have already voted in this year's Senior Challenge!</b> <p>To view the rankings of the current Senior Challenge contestants, <a href=\"/top10.php\">CLICK HERE</a></p>";
}
else
{
//Get Senior info
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result);

//Tally vote
$votes = $row['votes'] + 1;
$queryTally = "UPDATE seniors SET votes='$votes' WHERE sen_id=$_GET[sen_id] LIMIT 1";
$resultTally = mysql_query ($queryTally);

if(isset($resultTally))
{
$message = "<b>Your vote has been registered!</b> <p>Thank you for participating in the 2012 Senior Challenge. To view the rankings of the current Senior Challenge contestants, <a href=\"/top10.php\">click here</a></p>";

//Set cookie + ip
setcookie ("vote", "yes", time()+15552000);
$queryInsertIP = "INSERT INTO ips (ip, person) VALUES(INET_ATON('$ip'), '$row[last_name]')";
$resultInsertIP = mysql_query ($queryInsertIP);

}
else
{
$message = "<b>Error: Vote was not counted!</b> <p>You have encountered an error, and your vote was NOT tallied. Please, <a href=\"/contact.html\">contact us</a> to tally your vote.</p>";
}
}

?>

<?php
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result);
?>

<h3><?php echo $row['first_name'], " ", $row['last_name'], " has <font style=\"color:#FF0000\">
$row[votes]</font> votes";?></h3>

<?php echo "<p>", $message. "</p>"?>

<br />

</div>

<footer class="contents">
<p>&copy; Copyright 2003 - <?php echo date("Y") ?> Ruth Olson Photography</p>
</footer>

</body>

</html>
Current Rendered Source Code from Browser:

<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
<meta name="author" content="Brandon Moner" />
<script type="text/javascript" type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" />

<title>Ruth Olson Photography</title>
</head>

<body>

<header>
<div class="top">
<div class="contents">
<a href="index.php"><img src="/images/logo.png" width="100%" alt="Ruth Olson Photography" /></a>
<!-- <h1><a href="index.php">Ruth Olson Photography</a></h1> -->
</div>
</div>
</header>

<div class="container">

<br />
<b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/hermes/web01/b829/moo.rophoto1/rop-mobile/tally.php</b> on line <b>86</b><br />

<h3> has <font style="color:#FF0000">
</font> votes</h3>

<p><b>You have already voted in this year's Senior Challenge!</b> <p>To view the rankings of the current Senior Challenge contestants, <a href="/top10.php">CLICK HERE</a></p></p>
<br />

</div>

<footer class="contents">
<p>&copy; Copyright 2003 - 2011 Ruth Olson Photography</p>
</footer>

</body>

</html>


I still don't know what you are referring to as a 'backup file'.

I had made a backup file with the original code just in case something went wrong. I gave you the entire original coding from there.


Wait, you have a similar query further into the script.

I was going to mention this. So should I make both that value or what?

Psionicsin
08-29-2011, 10:54 PM
Wait, you have a similar query further into the script. The first modification is the one you could use:


<?php
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query($query) or die(sprintf('MySQL error: %s, GET: <pre>%s</pre>', mysql_error(), print_r($_GET, true)));
$row = mysql_fetch_array ($result);
?>

<h3><?php echo $row['first_name'], " ", $row['last_name'], " has <font style=\"color:#FF0000\">
$row[votes]</font> votes";?></h3>

<?php echo "<p>", $message. "</p>"?>

<br />

</div>

<footer class="contents">
<p>&copy; Copyright 2003 - <?php echo date("Y") ?> Ruth Olson Photography</p>
</footer>

</body>

</html>


I'm betting the first change you made was against that query in the if branch.

If I replace the bottom query with the one you supplied right above, I get:
MySQL error: 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 '' at line 1, GET:

Array
(
[submit] => Vote
)

Psionicsin
08-29-2011, 11:37 PM
Currently have this as code:

<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
<meta name="author" content="Brandon Moner" />
<script type="text/javascript" type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" />

<title>Ruth Olson Photography</title>
</head>

<body>

<header>
<div class="top">
<div class="contents">
<a href="index.php"><img src="/images/logo.png" width="100%" alt="Ruth Olson Photography" /></a>
<!-- <h1><a href="index.php">Ruth Olson Photography</a></h1> -->
</div>
</div>
</header>

<div class="container">

<?php
require_once('templates/mysql_connect.php');

/////////////
function escape_data ($data)
{
global $dbc;

if(ini_get('magic_quotes_gpc'))
$data = stripslashes($data);

return mysql_real_escape_string($data, $dbc);
}
////////////

$ip=$_SERVER['REMOTE_ADDR'];

$queryIP = "SELECT INET_NTOA('ip') FROM ips WHERE ip=INET_ATON('$ip')";
$resultIP = mysql_query($queryIP) or die(sprintf('MySQL error: %s, GET: <pre>%s</pre>', mysql_error(), print_r($_GET, true)));
$existIP = mysql_num_rows($resultIP);


if (isset($_COOKIE['vote']) || $existIP > 0)
{
$message = "<b>You have already voted in this year's Senior Challenge!</b> <p>To view the rankings of the current Senior Challenge contestants, <a href=\"/top10.php\">CLICK HERE</a></p>";
}
else
{
//Get Senior info
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query($query) or die(sprintf('MySQL error: %s, GET: <pre>%s</pre>', mysql_error(), print_r($_GET, true)));
$row = mysql_fetch_array ($result);

//Tally vote
$votes = $row['votes'] + 1;
$queryTally = "UPDATE seniors SET votes='$votes' WHERE sen_id=$_GET[sen_id] LIMIT 1";
$resultTally = mysql_query ($queryTally);

if(isset($resultTally))
{
$message = "<b>Your vote has been registered!</b> <p>Thank you for participating in the 2012 Senior Challenge. To view the rankings of the current Senior Challenge contestants, <a href=\"/top10.php\">click here</a></p>";

//Set cookie + ip
setcookie ("vote", "yes", time()+15552000);
$queryInsertIP = "INSERT INTO ips (ip, person) VALUES(INET_ATON('$ip'), '$row[last_name]')";
$resultInsertIP = mysql_query ($queryInsertIP);

}
else
{
$message = "<b>Error: Vote was not counted!</b> <p>You have encountered an error, and your vote was NOT tallied. Please, <a href=\"/contact.html\">contact us</a> to tally your vote.</p>";
}
}

?>

<?php
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query($query) or die(sprintf('MySQL error: %s, GET: <pre>%s</pre>', mysql_error(), print_r($_GET, true)));
$row = mysql_fetch_array ($result);
?>

<h3><?php echo $row['first_name'], " ", $row['last_name'], " has <font style=\"color:#FF0000\">
$row[votes]</font> votes";?></h3>

<?php echo "<p>", $message. "</p>"?>

<br />

</div>

<footer class="contents">
<p>&copy; Copyright 2003 - <?php echo date("Y") ?> Ruth Olson Photography</p>
</footer>

</body>

</html>

Here's the error it output
MySQL error: 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 '' at line 1, GET:

Array
(
[submit] => Vote
)

Fou-Lu
08-30-2011, 12:12 AM
No we got what we need.
sen_id is not passed to this script. Modify the calling script:


<?php
require_once('templates/mysql_connect.php');
?>

<?php
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result);
printf('<pre>%s</pre><pre>%s</pre>', print_r($row, true), print_f($_GET, true));
?>

<div class="contents">
<h1><?php echo $row['first_name'], " ", $row['last_name']; ?></h1>
<h4><?php echo $row['school']; ?></h4>
</div>

<?php echo
'<a href="sencha.php" class="bigmenu"><img src="images/backarrow.png" alt="Back to Senior Challenge Home" class="arrowleft indexicon" /><u>Back</u></a><br />'; ?>

<?php echo "<img src=\"http://www.rutholsonphoto.com" .$row['pic_url']. "\" width=\"100%\" />"; ?> <br />
<br />

<?php echo "<form action="tally.php?sen_id=$row[sen_id]" method="get">
<input type="submit" name="submit" value="Vote" />
</form>";
?>


Run the calling script again, and you'll have a pre dump for the record and the get. What is in these?

Psionicsin
08-30-2011, 12:20 AM
Run the calling script again, and you'll have a pre dump for the record and the get. What is in these?

Altered the file, and this is the error from that:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /hermes/web01/b829/moo.rophoto1/rop-mobile/vote.php on line 49

And what is in what exactly? I didn't understand the question.

Fou-Lu
08-30-2011, 12:21 AM
The second is print_r not print_f. That was my bad.

Psionicsin
08-30-2011, 12:24 AM
The second is print_r not print_f. That was my bad.

Changed, but still outputs the same error. Seems to be having an issue with something in here:

<?php echo "<form action="tally.php?sen_id=$row[sen_id]" method="get">
<input type="submit" name="submit" value="Vote" />
</form>";
?> <br />

Fou-Lu
08-30-2011, 12:26 AM
No don't submit the form. Just load this page.


Wait, check the source. If you see the <pre></pre><pre></pre> with noting between them, then yes that's your problem there. You have provided no sen_id for the environment to work with, so neither this script nor the one being processed will function properly.

Psionicsin
08-30-2011, 12:30 AM
No don't submit the form. Just load this page.


Wait, check the source. If you see the <pre></pre><pre></pre> with noting between them, then yes that's your problem there. You have provided no sen_id for the environment to work with, so neither this script nor the one being processed will function properly.


LOL I'm not submitting the form. This is what happens when I click someone's name, and it goes to load the "vote.php" page with their info. Try yourself HERE (http://m.rutholsonphoto.com/sencha.php). Chose an alphabet group, and then click on a name. Won't even load the page.

Fou-Lu
08-30-2011, 12:36 AM
I still have the syntax error. Did you correct the issue with the print_f to print_r?

Psionicsin
08-30-2011, 12:38 AM
I still have the syntax error. Did you correct the issue with the print_f to print_r?

Sure did. The coding for the entire page thus far is:

<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
<meta name="author" content="Brandon Moner" />
<script type="text/javascript" type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" />

<title>Ruth Olson Photography</title>
</head>

<body>

<header>
<div class="top">
<div class="contents">
<a href="index.php"><img src="/images/logo.png" width="100%" alt="Ruth Olson Photography" /></a>
<!-- <h1><a href="index.php">Ruth Olson Photography</a></h1> -->
</div>
</div>
</header>

<div class="container">

<?php
require_once('templates/mysql_connect.php');
?>

<?php
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result);
printf('<pre>%s</pre><pre>%s</pre>', print_r($row, true), print_r($_GET, true));
?>

<div class="contents">
<h1><?php echo $row['first_name'], " ", $row['last_name']; ?></h1>
<h4><?php echo $row['school']; ?></h4>
</div>

<?php echo
'<a href="sencha.php" class="bigmenu"><img src="images/backarrow.png" alt="Back to Senior Challenge Home" class="arrowleft indexicon" /><u>Back</u></a><br />'; ?>

<?php echo "<img src=\"http://www.rutholsonphoto.com" .$row['pic_url']. "\" width=\"100%\" />"; ?> <br />
<br />

<?php echo "<form action="tally.php?sen_id=$row[sen_id]" method="post">
<input type="submit" name="submit" value="Vote" />
</form>";
?> <br />

</div>

<footer class="contents">
<p>&copy; Copyright 2003 - <?php echo date("Y") ?> Ruth Olson Photography</p>
</footer>

</body>

</html>

However this is line 49:

<?php echo "<form action="tally.php?sen_id=$row[sen_id]" method="post">

The one it has a problem with.

Fou-Lu
08-30-2011, 12:41 AM
Oh yeah that was the first problem you had.


<?php echo '<form action="tally.php?sen_id=' . $row['sen_id'] . '" method="get">
<input type="submit" name="submit" value="Vote" />
</form>';
?>

Psionicsin
08-30-2011, 12:45 AM
Oh yeah that was the first problem you had.


<?php echo '<form action="tally.php?sen_id=' . $row['sen_id'] . '" method="get">
<input type="submit" name="submit" value="Vote" />
</form>';
?>


Fixed. Now spitting out something that is not an error, but shouldn't be there.

Array
(
[0] => 671
[sen_id] => 671
[1] => Kayla
[first_name] => Kayla
[2] => Gillies
[last_name] => Gillies
[3] => John Glenn
[school] => John Glenn
[4] => N
[package] => N
[5] => /images/sencha/kgillies-jg.jpg
[pic_url] => /images/sencha/kgillies-jg.jpg
[6] => 0
[votes] => 0
[7] =>
[placeholder] =>
)

Array
(
[sen_id] => 671
)


Rendered browser source is:

<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
<meta name="author" content="Brandon Moner" />
<script type="text/javascript" type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" />

<title>Ruth Olson Photography</title>
</head>

<body>

<header>
<div class="top">
<div class="contents">
<a href="index.php"><img src="/images/logo.png" width="100%" alt="Ruth Olson Photography" /></a>
<!-- <h1><a href="index.php">Ruth Olson Photography</a></h1> -->
</div>
</div>
</header>

<div class="container">

<pre>Array
(
[0] => 671
[sen_id] => 671
[1] => Kayla
[first_name] => Kayla
[2] => Gillies
[last_name] => Gillies
[3] => John Glenn
[school] => John Glenn
[4] => N
[package] => N
[5] => /images/sencha/kgillies-jg.jpg
[pic_url] => /images/sencha/kgillies-jg.jpg
[6] => 0
[votes] => 0
[7] =>
[placeholder] =>
)
</pre><pre>Array
(
[sen_id] => 671
)
</pre>
<div class="contents">
<h1>Kayla Gillies</h1>
<h4>John Glenn</h4>
</div>

<a href="sencha.php" class="bigmenu"><img src="images/backarrow.png" alt="Back to Senior Challenge Home" class="arrowleft indexicon" /><u>Back</u></a><br />
<img src="http://www.rutholsonphoto.com/images/sencha/kgillies-jg.jpg" width="100%" /> <br />

<br />

<form action="tally.php?sen_id=671" method="get">
<input type="submit" name="submit" value="Vote" />
</form> <br />

</div>

<footer class="contents">
<p>&copy; Copyright 2003 - 2011 Ruth Olson Photography</p>
</footer>

</body>

</html>

Psionicsin
08-30-2011, 12:56 AM
I wonder if consolidating the various PHP functions into one would make a difference. I've noticed in the original that the part in question was housed inside of a function that held a mysql_fetch_array. Not 100% though as we're about to packup here for today so I can't check for about 15min until I get home.

Fou-Lu
08-30-2011, 12:58 AM
Okay, that's right. Change this:


<?php echo '<form action="tally.php?sen_id=' . $row['sen_id'] . '" method="get">
<input type="submit" name="submit" value="Vote" />
</form>';
?>

To this:


<?php
echo '<form action="tally.php" method="get">
<input type="hidden" name="sen_id" value="' . $row['sen_id'] . '" />
<input type="submit" name="submit" value="Vote" />
</form>';
?>

I can't see that making a differenct, but you never know. Also, can you confirm that you are actually pressing the button with your mouse, and not just hitting enter?

Psionicsin
08-30-2011, 01:25 AM
<?php
echo '<form action="tally.php" method="get">
<input type="hidden" name="sen_id" value="' . $row['sen_id'] . '" />
<input type="submit" name="submit" value="Vote" />
</form>';
?>

I can't see that making a difference, but you never know. Also, can you confirm that you are actually pressing the button with your mouse, and not just hitting enter?

That made the difference. Not sure what happened, but it worked. Now...why did it work? And is that "print_r" statement what's pushing out all of the info for the selected person? Is that something that can be removed now or what?

Fou-Lu
08-30-2011, 01:52 AM
It can be removed.
I didn't think that it would choke on a form type of get while passing a get into the processing string, but there you go. Pass your get's as hidden in a get form.

Psionicsin
08-30-2011, 02:16 AM
It can be removed.
I didn't think that it would choke on a form type of get while passing a get into the processing string, but there you go. Pass your get's as hidden in a get form.

Ok one more thing. Tried voting and it worked. However I am having an error saying:
Warning: Cannot modify header information - headers already sent by...etc

Fou-Lu
08-30-2011, 02:43 AM
Its caused by the setcookie.
You cannot have output prior to the call of anything that sends a cookie, and this includes setting a session_start or setcookie.
You'll need to either modify the document structure to move all output after the processing up to the setcookie, or use output buffering with an ob_start() at the start of the page. I do not like the output buffering method as its a 'hacky' solution to what can be fixed with simple if/else calls and variable printing.

Psionicsin
08-30-2011, 02:46 AM
Its caused by the setcookie.
You cannot have output prior to the call of anything that sends a cookie, and this includes setting a session_start or setcookie.
You'll need to either modify the document structure to move all output after the processing up to the setcookie, or use output buffering with an ob_start() at the start of the page. I do not like the output buffering method as its a 'hacky' solution to what can be fixed with simple if/else calls and variable printing.

Ahh yes I remember that solution. So, with me not having any extensive PHP knowledge, how would I reconstruction this as I do agree it's a hacky solution?


<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
<meta name="author" content="Brandon Moner" />
<script type="text/javascript" type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" />

<title>Ruth Olson Photography</title>
</head>

<body>

<header>
<div class="top">
<div class="contents">
<a href="index.php"><img src="/images/logo.png" width="100%" alt="Ruth Olson Photography" /></a>
<!-- <h1><a href="index.php">Ruth Olson Photography</a></h1> -->
</div>
</div>
</header>

<div class="container">

<?php
require_once('templates/mysql_connect.php');

/////////////
function escape_data ($data)
{
global $dbc;

if(ini_get('magic_quotes_gpc'))
$data = stripslashes($data);

return mysql_real_escape_string($data, $dbc);
}
////////////

$ip=$_SERVER['REMOTE_ADDR'];

$queryIP = "SELECT INET_NTOA('ip') FROM ips WHERE ip=INET_ATON('$ip')";
$resultIP = mysql_query($queryIP) or die(sprintf('MySQL error: %s, GET: <pre>%s</pre>', mysql_error(), print_r($_GET, true)));
$existIP = mysql_num_rows($resultIP);


if (isset($_COOKIE['vote']) || $existIP > 0)
{
$message = "<b>You have already voted in this year's Senior Challenge!</b> <p>To view the rankings of the current Senior Challenge contestants, <a href=\"/top10.php\">CLICK HERE</a></p>";
}
else
{
//Get Senior info
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query($query) or die(sprintf('MySQL error: %s, GET: <pre>%s</pre>', mysql_error(), print_r($_GET, true)));
$row = mysql_fetch_array ($result);

//Tally vote
$votes = $row['votes'] + 1;
$queryTally = "UPDATE seniors SET votes='$votes' WHERE sen_id=$_GET[sen_id] LIMIT 1";
$resultTally = mysql_query ($queryTally);

if(isset($resultTally))
{
$message = "<b>Your vote has been registered!</b> <p>Thank you for participating in the 2012 Senior Challenge. To view the rankings of the current Senior Challenge contestants, <a href=\"/top10.php\">click here</a></p>";

//Set cookie + ip
setcookie ("vote", "yes", time()+15552000);
$queryInsertIP = "INSERT INTO ips (ip, person) VALUES(INET_ATON('$ip'), '$row[last_name]')";
$resultInsertIP = mysql_query ($queryInsertIP);

}
else
{
$message = "<b>Error: Vote was not counted!</b> <p>You have encountered an error, and your vote was NOT tallied. Please, <a href=\"/contact.html\">contact us</a> to tally your vote.</p>";
}
}

?>

<?php
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query($query) or die(sprintf('MySQL error: %s, GET: <pre>%s</pre>', mysql_error(), print_r($_GET, true)));
$row = mysql_fetch_array ($result);
?>

<h3><?php echo $row['first_name'], " ", $row['last_name'], " has <font style=\"color:#FF0000\">
$row[votes]</font> votes";?></h3>

<?php echo "<p>", $message. "</p>"?>

<br />

</div>

<footer class="contents">
<p>&copy; Copyright 2003 - <?php echo date("Y") ?> Ruth Olson Photography</p>
</footer>

</body>

</html>

Fou-Lu
08-30-2011, 02:50 AM
Just move all of this:


<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width; initial-scale=1.0;" />
<meta name="author" content="Brandon Moner" />
<script type="text/javascript" type="text/javascript" src="js/jquery-1.6.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" />

<title>Ruth Olson Photography</title>
</head>

<body>

<header>
<div class="top">
<div class="contents">
<a href="index.php"><img src="/images/logo.png" width="100%" alt="Ruth Olson Photography" /></a>
<!-- <h1><a href="index.php">Ruth Olson Photography</a></h1> -->
</div>
</div>
</header>

<div class="container">


Including the space before <?php, after this:


<?php
$query = "SELECT * FROM seniors WHERE sen_id=$_GET[sen_id]";
$result = mysql_query($query) or die(sprintf('MySQL error: %s, GET: <pre>%s</pre>', mysql_error(), print_r($_GET, true)));
$row = mysql_fetch_array ($result);
?>

And before this:


<h3><?php echo $row['first_name'], " ", $row['last_name'], " has <font style=\"color:#FF0000\">
$row[votes]</font> votes";?></h3>

That should do it.

Psionicsin
08-30-2011, 08:42 PM
Thanks very much for your help, Fou-Lu.

Psionicsin
08-31-2011, 08:27 PM
Fou-Lu, I made another mistake. not with the same page, but with this one "top10.php":


<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ruth Olson Photography</title>
<meta http-equiv="content-type" content="application/xhtml+xml" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<link rel="apple-touch-icon" href="images/icon.png" />

<!--CSS-->
<link href="css/style.css" rel="stylesheet" type="text/css" />

<!--jQuery-->
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/dropdown.js"></script>
<script type="text/javascript" src="js/superfish.js"></script>
<script type="text/javascript">
$(function() {
$('#back_to_top').click(function() {
$('body,html').animate({scrollTop:0},800);
});
});

var $ = jQuery.noConflict();
$(function() {
$('#activator').click(function(){
$('#box').animate({'top':'75px'},500);
});
$('#boxclose').click(function(){
$('#box').animate({'top':'-400px'},500);
});
$('#activator_share').click(function(){
$('#box_share').animate({'top':'65px'},500);
});
$('#boxclose_share').click(function(){
$('#box_share').animate({'top':'-400px'},500);
});

});
$(document).ready(function(){
$(".toggle_container").hide();
$(".trigger").click(function(){
$(this).toggleClass("active").next().slideToggle("slow");
return false;
});

});
</script>
</head>
<body>
<!--Top page (logo and search button)-->
<div id="top" class="page_x">
<div id="header">
<div id="content_header">
<a href="index.php"><img src="images/logo.png" alt="Impact Mobile" /></a>
</div>
</div>
</div>
<!--Top page Ends-->
<!--Navigation-->
<div id="navigation">
<div id="content_navigation">
<a href="javascript:history.back()"><img src="images/back.png" alt="Go back" class="butt_black left" /></a>
<a href="#" id="categories-button"><img src="images/navigation.png" alt="Open menu" class="butt_black right" /></a>
<div id="categories-dropdown">
<div class="categories-inside">
<ul>
<li><a href="senspecs.php">Specials</a></li>
<li><a href="sencha.php">Vote</a></li>
<li><a href="galleries.php">Galleries</a></li>
<li><a href="contact.php">Contact</a></li>
<li><a href="http://www.facebook.com/pages/Ruth-Olson-Photography/328300073878">Facebook</a></li>
</ul>
</div>
</div>
</div>
</div>
<!--Navigation Ends-->
<!--Main contents-->
<div class="box_center" id="page_x">
<h1 class="shadow">2012's Top 10 Contestants</h1>

<div id="results" align="center">

<?php

include("templates/mysql_connect.php");

$totalQuery = "SELECT * FROM seniors";
$totalResult = mysql_query ($totalQuery);
$totalSeniors = mysql_num_rows ($totalResult);

echo "<strong>There are $totalSeniors Senior Challenge Contestants</strong>";

?>

<br />
<br />

<big><b><u>Top 10</u></b></big><br />
<br />

<?php

include("templates/mysql_connect.php");

//Leaderboards
$voteQuery = "SELECT * FROM seniors ORDER BY votes DESC LIMIT 10";
$voteResult = mysql_query ($voteQuery);

echo '<table cellpadding="3"> <thead>';
echo '<th align="left"><b><u>Rank</u></b></th>
<th align="center"><b><u>Name</u><b></th>
<th align="center"><b><u>School</u><b></th></tr></thead>';

$i = 1;

while ($row = mysql_fetch_array ($voteResult)){

echo "<tr "; if($i%2 !=0) echo 'bgcolor="#E0E0E0" >'; else echo '>';
echo"<td align=\"center\">$i</td>
<td align=\"center\"><a href=\"vote.php?sen_id=$row[sen_id]\" <form action =\"vote.php?sen_id=$row[sen_id]\" method=\"post"\>
</form> \">$row[last_name], $row[first_name]</a></td>
<td align=\"center\">$row[school]</td>
</tr>\n";
$i++;
}
echo '</td></tr>';
?>

</table>

</div>
</div>
<!--Main contents Ends-->
<!--Footer-->
<div id="footer">
<div id="content_footer">
<!--Your copyright-->
<div id="copyright">
&copy; Copyright 2003 - <?php echo date("Y") ?> Ruth Olson Photography
</div>
<!--Your copyright Ends-->
</div>
</div>
<!--Footer Ends-->
</body>
</html>

It's supposed to be a 3 column table of the top 10 contestants. Column 1 is the ranking, 2 is their name, and 3 is their school. However I seemed to have messed it up while deleting old code from there and can't seem to get it to work lol.

I need the links for each of the names to function like they do on THIS PAGE (http://m.rutholsonphoto.com/sencon-1.php). It takes you to their custom vote page with their info and such.

I'm getting this error:
Parse error: syntax error, unexpected '=' in /hermes/web01/b829/moo.rophoto1/mobile/top10.php on line 123

Psionicsin
08-31-2011, 08:34 PM
Nevermind I figured it out. Thanks if you took a look anyway lol.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum