0

Hey guys,

I know that the query is not good, but i CANT see the problem.

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\XAMPP\xampp\htdocs\betania\modify.php on line 8

Could you please help me out?

<?php

	include "connection.php";
	
	if(!isset($_POST[submit])) {
		$q = mysql_query("SELECT * FROM inscrieri  WHERE id =".$_GET['id']."");
		$result = mysql_query($q);
		$person = mysql_fetch_array($result, MYSQL_ASSOC);
		
		
	}	else {
	
	}
		

?>

<html>
		<head>
			<title>Modificare participant - Lunca Bradului 2010</title>
		<style type="text/css">
		
		#loginform {
			border: 2px solid #500;
			background-color: #90A4CA;
			width: 300px;
			text-align: left;
		}
		
		#loginform form {
			margin: 5px;
		}
		
		#loginform label {
			width: 100px;
			float: left;
			display: block;
			clear: both;
		}
		
		#loginform label, input { 
			margin-bottom: 5px;
		}
		
		#loginform input {
			background-color: #FFCC00;
			border: 1px solid #CCC;
		}
		
		</style>
		
		</head>
		
	<body>
	
		<center>
		<div id="loginform">
			<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
				<label>Nume:</label>
					<input type="text" name="inputNume" id="nume" value="<?php echo  $person[nume]; ?>">
				<label>Prenume:</label>
					<input type="text" name="inputPrenume" id="prenume" value="<?php echo  $person[prenume]; ?>">
				<label>Telefon:</label>
					<input type="text" name="inputTelefon" id="telefon" value="<?php echo  $person[telefon]; ?>">
				<label>Email:</label>
					<input type="text" name="inputMail" id="mail" value="<?php echo  $person[mail]; ?>">
				<label>Varsta:</label>				
					<input type="text" name="inputVarsta" id="varsta" value="<?php echo  $person[varsta]; ?>">
				
				<input type="hidden" name="id" value="<?php $_GET[id]; ?>"
				<input type="submit" value="Modifica"/>
			</form>
		</div>
		</center>
	
	
	
	</body>
</html>

<?php 
	if(isset($_POST['submit'])) {
		$update = "UPDATE inscrieri SET nume='$_POST[inputNume]', prenume='$_POST[inputPrenume]', telefon='$_POST[inputTelefon]', mail='$_POST[inputMail]', varsta='$_POST[inputVarsta]' WHERE id = $_POST[id]";
		mysql_query($update) or die (mysql_error());
		
		echo "Participantul a fost modificat!";
		header("Location: index.php");
	} else {
	
	}
?>
2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Szabi Zsoldos
0

Change line 6 to:

$q = mysql_query("SELECT * FROM inscrieri WHERE id = '".$_GET['id']."'");

Also check that $_GET has a value assigned to it. Simple, but check it.

You could change line 8 to:

$person = mysql_fetch_assoc($result);

Less code for less confusion.

Use this too, to see why the query isn't working:

echo mysql_error();

Also, echo $q and run it inside phpMyAdmin to see if there is anything wrong with it...

Josh

0

I forgot to mention, don't use $_GET/POST in SQL statements, they can be injected into.

0

The problem is that I haven't used PHP from 2008 and i had this old file which worked and now it's giving me the same fetch problem.

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\XAMPP\xampp\htdocs\tabara\inscrisi\index.php on line 40

I tried your previous recommendations but the same issue.

What should i do to work ?

<html>
<title>BLA</title>
<head>

<style type="text/css" media="all">

@import url(/rev/css.css);

</style>
</head>
<body>
<table align="center" id="table1" width="900" height="300" align="center" style="border-bottom-style:solid; border:solid; border-color:#333">
<tr>
<td>
<div align="center">
<?php

	$con = mysql_connect("localhost","root","");
		if (!$con){
		  die('Could not connect: ' . mysql_error());
		}

	mysql_select_db("localhost", $con);

	$result = mysql_query("SELECT * FROM inscrisi");

	echo "<table style='border-bottom-style:solid; border:solid; border-color:#333333'>
<br>
<tr>
<th width='30px' style='background-color:#414141; color:#FFCC00'>ID</th>
<th width='100px' style='background-color:#414141; color:#FFCC00'>Numele</th>
<th width='100px' style='background-color:#414141; color:#FFCC00'>Prenumele</th>
</tr>";

	mysql_select_db("localhost", $con);


	$result = mysql_query("SELECT * FROM inscrisi ORDER BY nume ASC, varsta DESC");

	while($row = mysql_fetch_assoc($result))
	  {
	  echo "<tr style='border:solid; border:1px; border-color:#FFFFFF'>";
	  echo "<td align='center'>" . $row['id'] . "</td>";
	  echo "<th align='left' style=' color:#1186DD '>" . $row['nume'] . "</th>";
	  echo "<td align='center'>" . $row['prenume'] . "</td>";
	  echo "</tr>";
	  }
	echo "</table>";

	mysql_close($con);


?>
</div>

</td>
</tr>
</table>
</body>
</html>

Edited by Szabi Zsoldos: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.