Jump to content

vote.php noob needs help


babygurl

Recommended Posts

I get to errors below and cannot figure out what im doign wrong i've tryed diffrent ways and have even rewritten this couple times

(#1error) not sure how to re query and echo out the array??

(#2error) gives me error on line 14 if i echo anything past (echo $row['name']."|user1:". $row['user1']. "|user2:". $row['user2']. ->this

 

 

 

<?php

$conn = mysql_connect("localhost", "root", "");

if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
}
  
if (!mysql_select_db("register_db")) {
    echo "Unable to select mydbname: " . mysql_error();
    exit;
}

$result = mysql_query("SELECT * FROM register_vote WHERE name = '{$_POST['user']}'");


if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}
    =========================(#1error)==========================================
//THIS IS THE CODE I'M HAVING ISSUES WITH
if (mysql_num_rows($result) == 0) {
mysql_query("INSERT INTO register_vote (name) VALUES ('$_POST[user]')");
//need it to the query new results after insert
//then
       //  echo $row['name']."|user1:". $row['user1']. "|user2:". $row['user2']. "|user3:". $row['user3'];



}================================================= (#2error)===================================
   while ($row = mysql_fetch_array($result)) {
       echo $row['name']."|user1:". $row['user1']. "|user2:". $row['user2']. "|user3:". $row['user3'];
}                                  //when I put anything past $row['user2']. it gives me error on line 14
mysql_free_result($result);
?>

Link to comment
Share on other sites

We don't know what your database schema looks like so this is just as guess, based on your insert.

 

It appears you have a table named register_vote that gets a row inserted to indicate a user voted.  If you want to then query this table and display all users:

 

$result = mysql_query("SELECT * from register_vote");
if ($result) {
  while ($row = mysql_fetch_assoc($result)) {
    echo "{$row['name']} Voted 
";
  }
} else {
  // query error
}

 

Link to comment
Share on other sites

I get to errors below and cannot figure out what im doign wrong i've tryed diffrent ways and have even rewritten this couple times

(#1error) not sure how to re query and echo out the array??

(#2error) gives me error on line 14 if i echo anything past                                                  HERE

echo $row['name']."|gtop100:". $row['gtop100']. "|mcservers:". $row['mcservers']. !!!!ANTHING PAST THIS!!!"|xtremetop100:". $row['xtremetop100'];

 

ok let me explain the project better, this is a voting interface used for a game server. the interface.php contains values such as $_POST['user']

when the user logs in it goes to the vote.php and does this process( check if $_POST['user'] exist if not insert into register_vote, the sql auto genrates 3 values gtop100,mcserver,xtremetop and sets defualts @ false.

then it querys the register_vote for if $_POST['user']=username and echos out

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

echo $row['name']."|gtop100:". $row['gtop100']. "|mcservers:". $row['mcservers']. "|xtremetop100:". $row['xtremetop100'];

and and respnds to the interface.php with these values (test=username for the example)

test|gtop100:false|mcservers:false|xtremetop100:false

 

 

<?php

$conn = mysql_connect("localhost", "root", "");

if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
}
  
if (!mysql_select_db("register_db")) {
    echo "Unable to select mydbname: " . mysql_error();
    exit;
}

$result = mysql_query("SELECT * FROM register_vote WHERE name = '{$_POST['user']}'");


if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}
    =========================(#1error)==========================================
//THIS IS THE CODE I'M HAVING ISSUES WITH
if (mysql_num_rows($result) == 0) {
mysql_query("INSERT INTO register_vote (name) VALUES ('$_POST[user]')");
//need it to the query new results after insert
//then
       //echo $row['name']."|gtop100:". $row['gtop100']. "|mcservers:". $row['mcservers']. "|xtremetop100:". $row['xtremetop100'];



}================================================= (#2error)===================================
   while ($row = mysql_fetch_array($result)) {
       echo $row['name']."|gtop100:". $row['gtop100']. "|mcservers:". $row['mcservers'];
}                                  //when I put anything past $row['mcservers'] it gives me error on line 14 and then on page load it automatically send 
                                         this error Notice: Undefined index: user in C:\wamp blah blah line 14
mysql_free_result($result);
?>

error14.png

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.