View Full Version : Resolved need help asap
kryssy23
11-10-2008, 11:58 AM
I ran the db earlier today and i got this error... Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a9362154/public_html/register.php on line 92
still cant get rid of it... but it also was still adding stuff into the db... now i try and i get that error + 1064: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 3
and now nothing gets inserted into the db... any ideas on how to fix this?
i have to hand this up tomorrow.. so i need so help asap if you can
abduraooft
11-10-2008, 12:01 PM
Please post your code asap :)
kryssy23
11-10-2008, 12:11 PM
<?php
session_start();
//error_reporting(5);
include_once("includes/connect.inc.php");
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$team = $_POST['team'];
$country = $_POST['country'];
$stadium = $_POST['stadium'];
//echo "username = " . $username . "<br>";
//echo "password = " . $password . "<br>";
//echo "firstname = " . $fname . "<br>";
//echo "last name = " . $lname. "<br>";
//echo "address = " . $address . "<br>";
//echo "phone = " . $phone . "<br>";
//echo "email = " . $email . "<br>";
$errors = array();
if(empty($username)){
array_push($errors, "Username is empty");
}
if(empty($password)){
array_push($errors, "Password is empty");
}
if(empty($email)){
array_push($errors, "Email is empty");
}
if(empty($team)){
array_push($errors, "Team name is empty");
}
if(empty($country)){
array_push($errors, "Country is empty");
}
if(empty($stadium)){
array_push($errors, "Stadium Name is empty");
}
if(!empty($errors)){
$_SESSION['errors'] = $errors;
$_SESSION['registerForm']['username'] = $username;
$_SESSION['registerForm']['password'] = $password;
$_SESSION['registerForm']['email'] = $email;
$_SESSION['registerForm']['team'] = $team;
$_SESSION['registerForm']['country'] = $country;
$_SESSION['registerForm']['stadium'] = $stadium;
header("Location: registration.php");
flush();
}
//generating team
$sql = "INSERT INTO team (Name) VALUES ('$team')";
//Run the query
$results = mysql_query($sql, $dbh) or die (mysql_errno($dbh) . ":" . mysql_error($dbh) );
//Check how many rows were returned:
$num_rows = mysql_affected_rows();
//If 0 rows were returned no user exists/matches credentials
if($num_rows < 1){
// theres an error
}
$teamid = mysql_insert_id();
//generating player for positions
//generate players for team positions
for ($i=1; $i<=5;$i++){
$players = array();
$sql = "SELECT PlayerID FROM player WHERE position = " . $i . " AND signed != 1";
$results = mysql_query($sql) or die(mysql_error());
$numrows = mysql_num_rows($results);
//create 3 players
for ($h=1; $h<=3;$h++){
$rand = rand(0,$numrows-1);
//echo "RANDOM NUMBER = ". $rand;
while($row = mysql_fetch_assoc($results)){
array_push($players, $row['PlayerID']);
}
//print_r($players);
$playerid = $players[$rand];
//SQL Query string that will match against database
$sql = "INSERT INTO teamlookup (PlayerID, TeamID) VALUES ('$playerid', '$teamid')";
// echo "<br>". $sql . "<br> -------- <br>";
//Run the query
$results = mysql_query($sql, $dbh) or die (mysql_errno($dbh) . ":" . mysql_error($dbh) );
$sql = "UPDATE player
SET signed = 1
WHERE PlayerID = " . $playerid;
$results = mysql_query($sql, $dbh) or die (mysql_errno($dbh) . ":" . mysql_error($dbh) );
}
}
//SQL Query string that will match against database
$sql = "INSERT INTO member (username, password, email, country, stadium, TeamID) VALUES ('$username', '$password','$email', '$country', '$stadium','$teamid')";
//echo $sql;
//Run the query
$results = mysql_query($sql, $dbh) or die(mysql_error());
//Check how many rows were returned:
$num_rows = mysql_affected_rows();
//If 0 rows were returned no user exists/matches credentials
if($num_rows < 1){
$_SESSION['errors'] = "Error inserting member into database";
header("Location: registration.php");
} else{
$row = mysql_fetch_assoc($results);
$_SESSION['registerDetails']['username'] = $username;
$_SESSION['registerDetails']['password'] = $password;
$_SESSION['registerDetails']['email'] = $email;
$_SESSION['registerDetails']['team'] = $team;
$_SESSION['registerDetails']['country'] = $country;
$_SESSION['registerDetails']['stadium'] = $stadium;
$_SESSION['registerDetails']['teamid'] = $teamid;
}
}else{
header("Location: index.php");
}
?>
sorry... i dont know exactly where the error is.. so this is all the code
tagnu
11-10-2008, 12:54 PM
How about going for a trial and error method by echoing some text one by one after each mysql_query() line. This way you'll be able to track the line causing the error.
kryssy23
11-10-2008, 01:04 PM
i tried echoing it out and all i get each time is this error... 1064: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 3
abduraooft
11-10-2008, 01:09 PM
Have a try by changing all your $results = mysql_query($sql, $dbh) or die (mysql_errno($dbh) . ":" . mysql_error($dbh) ); to
$results = mysql_query($sql, $dbh) or die (mysql_errno($dbh) . ":" . mysql_error($dbh) .'<br/>'.$sql ); so that you'll get the exact query which is causing that error.
kryssy23
11-10-2008, 01:13 PM
nope nothing changed... man this is very fustrating
abduraooft
11-10-2008, 01:17 PM
nope nothing changed... man this is very fustrating I haven't told that it'll fix the issue.. The above change will print your query along with the error, so that you may fix it easily.
kryssy23
11-10-2008, 01:23 PM
i understand that... im fustrated because its giving me the same error... i have searched google... and i have found no way to fix it
here is the link... http://shootinghoops.site40.net/index.php
>click the register link
>submit the form and you will see the error
kryssy23
11-10-2008, 02:23 PM
i have fixed the problem... i think...when you register you get 15 players... i checked the db and there was only 10 left... so i added more... and the error has seemed to go.. thanks for everyone that helped :D
abduraooft
11-10-2008, 02:28 PM
i have fixed the problem... I'd strongly recommend you to rethink and find out at least which query was showing that error!
tagnu
11-11-2008, 06:42 AM
I agree with abduraooft. You need to isolate the query to avoid future issues.
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.