babygurl Posted January 16, 2012 Share Posted January 16, 2012 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/255162-votephp-noob-needs-help/ Share on other sites More sharing options...
gizmola Posted January 16, 2012 Share Posted January 16, 2012 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 } Quote Link to comment https://forums.phpfreaks.com/topic/255162-votephp-noob-needs-help/#findComment-1308312 Share on other sites More sharing options...
babygurl Posted January 16, 2012 Author Share Posted January 16, 2012 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/255162-votephp-noob-needs-help/#findComment-1308326 Share on other sites More sharing options...
gizmola Posted January 16, 2012 Share Posted January 16, 2012 You should be able to adapt my prior answer to your followup. Without a SELECT query it is obvious you are not going to have a result set to fetch. Quote Link to comment https://forums.phpfreaks.com/topic/255162-votephp-noob-needs-help/#findComment-1308335 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.