Quote:
Originally Posted by NullPointer
Posting the code you're using along with any error messages will make helping you much easier. (Make sure you use [ php] tags when posting php code)
|
I think that it is to do with the fact that actually i have no idea how to connect to the mysql database that i am using (at least i think i don't).
As i said i'm new to php and so i'm just copying and pasting form the tutorial in the link but apparently i can't even manage that.
Basically i have the main page saved as poll.php
PHP Code:
<?php require_once('Connections/conn_vote.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO poll (id, question) VALUES (%s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['Poll'], "text"));
mysql_select_db($database_conn_vote, $conn_vote);
$Result1 = mysql_query($insertSQL, $conn_vote) or die(mysql_error());
$insertGoTo = "results.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_rs_vote = "-1";
if (isset($_GET['recordID'])) {
$colname_rs_vote = $_GET['recordID'];
}
mysql_select_db($database_conn_vote, $conn_vote);
$query_rs_vote = sprintf("SELECT * FROM poll WHERE id = %s", GetSQLValueString($colname_rs_vote, "int"));
$rs_vote = mysql_query($query_rs_vote, $conn_vote) or die(mysql_error());
$row_rs_vote = mysql_fetch_assoc($rs_vote);
$totalRows_rs_vote = mysql_num_rows($rs_vote);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Poll</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<fieldset>
<legend>What is your JavaScript library of choice?</legend>
<form action="results.php" id="form1" name="form1" method="POST">
<label>
<input type="radio" name="Poll" value="mootools" id="Poll_0" />
Mootools
</label>
<label>
<input type="radio" name="Poll" value="prototype" id="Poll_1" />
Prototype
</label>
<label>
<input type="radio" name="Poll" value="jquery" id="Poll_2" />
jQuery
</label>
<label>
<input type="radio" name="Poll" value="spry" id="Poll_3" />
Spry
</label>
<label>
<input type="radio" name="Poll" value="other" id="Poll_4" />
Other
</label>
<input type="submit" name="submit" id="submit" value="Vote" />
<input type="hidden" name="id" value="form1" />
<input type="hidden" name="MM_insert" value="form1" />
</form>
</fieldset>
</body>
</html>
<?php
mysql_free_result($rs_vote);
?>
The results page saved as results.php
PHP Code:
<?php require_once('Connections/conn_vote.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_conn_vote, $conn_vote);
$query_rs_vote = "SELECT * FROM poll";
$rs_vote = mysql_query($query_rs_vote, $conn_vote) or die(mysql_error());
$row_rs_vote = mysql_fetch_assoc($rs_vote);
$totalRows_rs_vote = mysql_num_rows($rs_vote);
$resultQuestion1 = mysql_query("SELECT * FROM poll WHERE question='mootools'");
$num_rowsQuestion1 = mysql_num_rows($resultQuestion1);
$resultQuestion2 = mysql_query("SELECT * FROM poll WHERE question='prototype'");
$num_rowsQuestion2 = mysql_num_rows($resultQuestion2);
$resultQuestion3 = mysql_query("SELECT * FROM poll WHERE question='jquery'");
$num_rowsQuestion3 = mysql_num_rows($resultQuestion3);
$resultQuestion4 = mysql_query("SELECT * FROM poll WHERE question='spry'");
$num_rowsQuestion4 = mysql_num_rows($resultQuestion4);
$resultQuestion5 = mysql_query("SELECT * FROM poll WHERE question='other'");
$num_rowsQuestion5 = mysql_num_rows($resultQuestion5);
$percentQuestion1 = ($num_rowsQuestion1 / $totalRows_rs_vote)*100;
$percentQuestion2 = ($num_rowsQuestion2 / $totalRows_rs_vote)*100;
$percentQuestion3 = ($num_rowsQuestion3 / $totalRows_rs_vote)*100;
$percentQuestion4 = ($num_rowsQuestion4 / $totalRows_rs_vote)*100;
$percentQuestion5 = ($num_rowsQuestion5 / $totalRows_rs_vote)*100;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Results</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<fieldset>
<legend>Results</legend>
<ul>
<li>
<span class="total-votes"><?php echo $num_rowsQuestion1 ?></span> Mootools
<br />
<div class="results-bar" style="width: <?php echo round($percentQuestion1,2); ?>%;">
<?php echo round($percentQuestion1,2); ?>%
</div>
</li>
<li>
<span class="total-votes"><?php echo $num_rowsQuestion2 ?></span> Prototype
<div class="results-bar" style="width: <?php echo round($percentQuestion2,2); ?>%;">
<?php echo round($percentQuestion2,2); ?>%
</div>
</li>
<li>
<span class="total-votes"><?php echo $num_rowsQuestion3 ?></span> jQuery
<div class="results-bar" style="width: <?php echo round($percentQuestion3,2); ?>%;">
<?php echo round($percentQuestion3,2); ?>%
</div>
</li>
<li>
<span class="total-votes"><?php echo $num_rowsQuestion4 ?></span> Spry
<div class="results-bar" style="width: <?php echo round($percentQuestion4,2); ?>%;">
<?php echo round($percentQuestion4,2); ?>%
</div>
</li>
<li>
<span class="total-votes"><?php echo $num_rowsQuestion5 ?></span> Other
<div class="results-bar" style="width: <?php echo round($percentQuestion5,2); ?>%;">
<?php echo round($percentQuestion5,2); ?>%
</div>
</li>
</ul>
<h6>Total votes: <?php echo $totalRows_rs_vote ?></h6>
<a href="poll.php">Back to Voting</a>
</fieldset>
</body>
</html>
<?php
mysql_free_result($rs_vote);
?>
and finally a file saved as conn_vote.php (which is the one i assume that it is using to connect to the mysql database)
PHP Code:
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_conn_vote = "mygql14.000webhost.com";
$database_conn_vote = "a6524818_poll";
$username_conn_vote = "a6524818_example";
$password_conn_vote = "password1";
//$conn_vote = mysql_pconnect($hostname_conn_vote, $username_conn_vote, $password_conn_vote) or trigger_error(mysql_error(),E_USER_ERROR);
$conn_vote = mysql_connect($hostname_conn_vote, $username_conn_vote, $password_conn_vote) or die('Can\'t create connection: '.mysql_error());
mysql_select_db($database_conn_vote, $conn_vote) or die('Can\'t access specified db: '.mysql_error());
?>
here is what 000webhost.com tells me to do to use my scripts
Can't work out what i have done wrong and this is all that happens when i vote and it loads the results screen
I know that this is a huge post so feel free to completely ignore it and don't worry about answering if it's too much to look at

thanks