Help displaying msql search result

Hi all,

I have a search button button using Post method. I have a search.php to display the data based on the search criteria. But I am stuck. no error message but could only display “Please enter a search query”

Here is the php code:

<?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){ $name=$_POST['name']; //connect to the database $con = mysql_connect("localhost","db_username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("bgcomp_jo152", $con); $name = $_POST['name']; $result = mysql_query ("select * from Customer_Registration where Firstname like '%$name%' or lastname like '%$name%' "); $row = mysql_fetch_row($result); $Firstname = $row[7]; $lastname = $row[8]; $Address = $row[9]; $Postcode = $row[10]; ?>
    <form>
	
	<table width="100%" border="2" cellspacing="0" cellpadding="8">
First name: Last name: Address: Postcode:
    </form>
    <?php

}
}
else{
echo “

Please enter a search query

”;
}
}

?>

[quote author=php-newbies link=topic=13829.msg45235#msg45235 date=1316369604]
Hi all,

I have a search button button using Post method. I have a search.php to display the data based on the search criteria. But I am stuck with the message “Please enter a search query”

Here is the php code:

<?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("^/[A-Za-z]+/", $_POST['name'])){ $name=$_POST['name']; } } else{ echo "

Please enter a search query

"; } } //connect to the database $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("bgcomp_jo152", $con); $name = $_POST['name']; $result = mysql_query ("select * from Customer_Registration where Firstname like '%$name%' or lastname like '%$name%' "); $row = mysql_fetch_row($result); $Firstname = $row[7]; $lastname = $row[8]; $Address = $row[9]; $Postcode = $row[10]; ?>
    <form>
	
	<table width="100%" border="2" cellspacing="0" cellpadding="8">
First name: Last name: Address: Postcode:
    </form>
    <?php

?>

Hi, please do one change first the connection with mysql will be done first before checking anything this may clear your problem else contact me I will help.

Sponsor our Newsletter | Privacy Policy | Terms of Service