Forum Moderators: coopster

Message Too Old, No Replies

php error: Undefined Index Search on line 15

         

nabilino

2:20 pm on Nov 1, 2007 (gmt 0)

10+ Year Member



Hi guys,
I need help with my script..i'm very new to PHP.
I have an error that I don't know how to get rid of in the following:

$Search = $_POST["Search"];
$connect = @mysql_connect($host, $user, $passwd)
or die("connect error: " . mysql_error());
$table_name = 'student';
@mysql_select_db($database)
or die('select_db error: ' . mysql_error());

$query = "SELECT * FROM $table_name WHERE
(stu_id = '$Search')";
print "$query<br>";
$result_id = mysql_query($query, $connect) or die("querry errror: " . mysql_error());

the error says: Undefined Index Search on line 15
then it prints the query.

thanks a million

jatar_k

2:32 pm on Nov 1, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld nabilino,

which is line 15?

is it this line?
$Search = $_POST["Search"];

if so then I would check that the caps match the actual element being posted

another way to debug is to dump the $_POST array to see what's in there, like so

echo '<p>POST:<pre>';
print_r($_POST);
echo '</pre>';

dreamcatcher

2:33 pm on Nov 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if (isset [uk2.php.net]($_POST['Search'])) {
$Search = $_POST["Search"];
$connect = @mysql_connect($host, $user, $passwd)
or die("connect error: " . mysql_error());
$table_name = 'student';
@mysql_select_db($database)
or die('select_db error: ' . mysql_error());

$query = "SELECT * FROM $table_name WHERE
(stu_id = '$Search')";
print "$query<br>";
$result_id = mysql_query($query, $connect) or die("querry errror: " . mysql_error());
}

dc

[edit]jatar_k beat me to it. Oh, well at least you have 2 alternatives. And welcome to WebmasterWorld nabilino

jatar_k

2:39 pm on Nov 1, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



as DC posted, if Search is an optional element then you would need something as posted.

nabilino

2:43 pm on Nov 1, 2007 (gmt 0)

10+ Year Member



thank you guys, I should of posted the whole code..now it's showing a syntax error, unexpected $end in C:/... on line 47.
my code goes only to line 43 then I have the body and html closing.

like this:

<?php

// Make a MySQL Connection
$host= "*******";
$user = "******";
$passwd = "******";
$database = "******";
$Search = $_POST["Search"];
$connect = @mysql_connect($host, $user, $passwd)
or die("connect error: " . mysql_error());
$table_name = 'student';
@mysql_select_db($database)
or die('select_db error: ' . mysql_error());

$query = "SELECT * FROM $table_name WHERE
(stu_id = '$Search')";
print "$query<br>";
$results_id = mysql_query($query, $connect) or die("querry errror: " . mysql_error());

if($row = mysql_fetch_array($results_id)){
extract($row);
print("<br /> the insert student ID form<br />");

/* echo "stu_id :{$row['stu_id']} <br>";
echo $row['stu_id'] . " <br>";
foreach ($row as $key => $value) {
print "$key = $value <br>";

}

}*/


?>

</body>
</html>

thanks

jatar_k

2:55 pm on Nov 1, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



bad comment maybe, the syntax should be correct on this

<?php

// Make a MySQL Connection
$host= "*******";
$user = "******";
$passwd = "******";
$database = "******";
$Search = $_POST["Search"];
$connect = @mysql_connect($host, $user, $passwd) or die("connect error: " . mysql_error());
$table_name = 'student';
@mysql_select_db($database) or die('select_db error: ' . mysql_error());

$query = "SELECT * FROM $table_name WHERE (stu_id = '$Search')";
print "$query<br>";
$results_id = mysql_query($query, $connect) or die("querry errror: " . mysql_error());

if($row = mysql_fetch_array($results_id)){
extract($row);
print("<br /> the insert student ID form<br />");

/*
echo "stu_id :{$row['stu_id']} <br>";
echo $row['stu_id'] . " <br>";
foreach ($row as $key => $value) {
print "$key = $value <br>";
}
*/

}
?>

</body>
</html>

nabilino

4:38 pm on Nov 1, 2007 (gmt 0)

10+ Year Member



your help is well appreciated.