Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
I'm new - a little help? :D
Old 01-28-2010, 02:21 PM I'm new - a little help? :D
Junior Talker

Posts: 3
Trades: 0
Hi, i'm new to these forums and the reason that i found you , and joined is because i'm having a little problem with a poll that i am trying to create using php and mysql (i'm quite new to any sort of web design although i understand the basics).

Basically, I am trying to create a custom poll, not on that links to a stupid site but one that is completely in my own page and shows you the results after you click vote. I tried using this guide and got as far as having the poll and everything but i don't think it responded to mysql database that i used.

I was wondering if anybody could help me out or suggest and easier way to create a poll. (i'm using a mac).


Thanks in advance for any help!

Last edited by allApple; 01-28-2010 at 02:27 PM..
allApple is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-28-2010, 02:23 PM Re: I'm new - a little help? :D
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
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)
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 01-28-2010 at 02:25 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 01-28-2010, 02:54 PM Re: I'm new - a little help? :D
Junior Talker

Posts: 3
Trades: 0
Quote:
Originally Posted by NullPointer View Post
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
allApple is offline
Reply With Quote
View Public Profile
 
Old 01-28-2010, 03:00 PM Re: I'm new - a little help? :D
Douglife's Avatar
Extreme Talker

Posts: 218
Name: Douglas Montgomery
Location: Florida
Trades: 0
Welcome to the site, give me a moment here to go through this code, and hopefully I can help, no promises though!
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Douglife is offline
Reply With Quote
View Public Profile Visit Douglife's homepage!
 
Old 01-28-2010, 03:06 PM Re: I'm new - a little help? :D
Junior Talker

Posts: 3
Trades: 0
Quote:
Originally Posted by Douglife View Post
Welcome to the site, give me a moment here to go through this code, and hopefully I can help, no promises though!
Thanks!! no worries if you can't find anything
allApple is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to I'm new - a little help? :D
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.79420 seconds with 12 queries