Jump to content

Some Help


bob2588

Recommended Posts

i need some help on a script that i have never done i want to make a search code that seach a data base, there are a couple of virables that i have (type, state , zip , price range )and a few more but i have no idea how to write the script

 

thank you

Link to comment
Share on other sites

i just posted this on another post

 

you'll do

 


$res=mysql_query($query);

while($row=mysql_fetch_assoc($res)){

$touser=$row['touser'];
$fromuser=$row['fromuser'];
$comment=$row['comment'];
$commentdate=$row['commentdate'];
$commentid=$row['commentid'];

echo "TO: $touser FROM: $fromuser\n";
echo "COMMENT: $comment\n";
echo "SENT ON: $commentdate\n";
echo "ID OF: $commentid\n";

echo "<br />\n";


}

 

then for each iteration it'll update the variables from the db

 

basically you do a query, and store the result in $res, then while $row is being gotten from $res, you loop through the array, getting a new row for each iteration

Link to comment
Share on other sites

so it should look like this

<?php

mysql_connect('localhost', 'bob_2search', 'skater22') or die('Could not connect: ' . mysql_error());

$query = "("("SELECT * FROM real WHERE * LIKE '%$State%' && `zip` LIKE '%$zip%' && `Type` LIKE
'%$type%' ");

$res = mysql_query($qurey);

while($row=mysql_fetch_assoc($res)){

$State=$row['State']
$zip=$row['zip']
$type=$row['type']


echo '<table align="center" cellspacing="10" cellpadding="15">
<tr>
<td align="left"><b>Satet</b></td>
<td align="left"><b>Zip</b></td>
<td align="left"><b>Type</b></td>
'; 



echo '<tr><td align="left">' . $row['custID'] . '</td>
<td align="left">' . $row['State'] . '</td>
<td align="left">' . $row['zip'] . '</td>
<td align="left">' . $row['type'] . '</td>
<</tr>';





}

Link to comment
Share on other sites

i am getting two errors one is

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/bob2/public_html/Search/search.php on line 41

 

the other is

Parse error: syntax error, unexpected '{' in /home/bob2/public_html/Search/search.php on line 34

 

here is the code thank you for helping

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>

<form method="POST" action="?go">
<p style="margin-top: 0; margin-bottom: 0"> </p>
<p style="margin-top: 0; margin-bottom: 0">
<input type="text" name="State" size="20">State</p>
<p style="margin-top: 0; margin-bottom: 0">
<input type="text" name="Zip" size="20">Zip</p>
<p style="margin-top: 0; margin-bottom: 0">
<input type="text" name="Type" size="20">Type</p>
<p style="margin-top: 0; margin-bottom: 0">
<input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>







<?php
if(isset($_GET['go']){
mysql_connect('localhost', 'bob2_search', 'skater22') or die('Could not connect: ' . mysql_error());

$query = ("SELECT * FROM real WHERE * LIKE '%$State%' && `zip` LIKE '%$zip%' && `Type` LIKE
'%$type%' ");

$res = mysql_query($qurey);

while($row=mysql_fetch_assoc($res)){

$State=$row['State'];
$zip=$row['zip'];
$type=$row['type'];


echo '<table align="center" cellspacing="10" cellpadding="15">
<tr>
<td align="left"><b>Satet</b></td>
<td align="left"><b>Zip</b></td>
<td align="left"><b>Type</b></td>
'; 



echo '<tr><td align="left">' . $row['custID'] . '</td>
<td align="left">' . $row['State'] . '</td>
<td align="left">' . $row['zip'] . '</td>
<td align="left">' . $row['type'] . '</td>
<</tr>';




}
}

Link to comment
Share on other sites

 

$query = ("SELECT * FROM real WHERE * LIKE '%$State%' && `zip` LIKE '%$zip%' && `Type` LIKE

'%$type%' ");

 

should be

 

 

$query = ("SELECT * FROM real WHERE `state`  LIKE '%$State%' && `zip` LIKE '%$zip%' && `Type` LIKE

'%$type%' ");

 

or watever ur state field is

Link to comment
Share on other sites

k :D give this a go :D and remember to check against the table names of your DB

 


<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>

<form method="POST" action="?go">
   <p style="margin-top: 0; margin-bottom: 0"> </p>
   <p style="margin-top: 0; margin-bottom: 0">
   <input type="text" name="State" size="20">State</p>
   <p style="margin-top: 0; margin-bottom: 0">
   <input type="text" name="Zip" size="20">Zip</p>
   <p style="margin-top: 0; margin-bottom: 0">
   <input type="text" name="Type" size="20">Type</p>
   <p style="margin-top: 0; margin-bottom: 0">
   <input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>







<?php

if(isset($_GET['go']){
mysql_connect('localhost', 'bob2_search', 'skater22') or die('Could not connect: ' . mysql_error());

$state=$_POST['State']; // u have to get the values from the form
$zip=$_POST['Zip'];
$type=$_POST['Type'];

$query = ("SELECT * FROM real WHERE `State` LIKE '%$state%' && `zip` LIKE '%$zip%' && `Type` LIKE '%$type%'"); // * has to be a table name, so whatever state is

$res = mysql_query($query); //misspelled query 

while($row=mysql_fetch_assoc($res)){

$state=$row['State'];
$zip=$row['zip'];  /////check all the array names for capitalization against ur db fields
$type=$row['type'];
$id=$row['custID'];


echo '<table align="center" cellspacing="10" cellpadding="15"><tr><td align="left"><b>State</b></td><td align="left"><b>Zip</b></td><td align="left"><b>Type</b></td>'; 

echo "<tr><td align=\"left\">$id</td><td align=\"left\">$state</td><td align=\"left\">$zip</td><td align=\"left\">$type</td></tr>";

 }//end while


}//end go check

Link to comment
Share on other sites

there is still on error like i said before i dont know why i am getting the error

here is the error

Parse error: syntax error, unexpected '{' in /home/bob2/public_html/Search/search.php on line 35

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>

<form method="POST" action="?go">
   <p style="margin-top: 0; margin-bottom: 0"> </p>
   <p style="margin-top: 0; margin-bottom: 0">
   <input type="text" name="State" size="20">State</p>
   <p style="margin-top: 0; margin-bottom: 0">
   <input type="text" name="Zip" size="20">Zip</p>
   <p style="margin-top: 0; margin-bottom: 0">
   <input type="text" name="Type" size="20">Type</p>
   <p style="margin-top: 0; margin-bottom: 0">
   <input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>







<?php

if(isset($_GET['go']){  // This is line 35 
mysql_connect('localhost', 'bob2_search', 'skater22') or die('Could not connect: ' . mysql_error());

$state=$_POST['State']; // u have to get the values from the form
$zip=$_POST['Zip'];
$type=$_POST['Type'];

$query = ("SELECT bob2_search FROM real WHERE `State` LIKE '%$state%' && `zip` LIKE '%$zip%' && `Type` LIKE '%$type%'"); // * has to be a table name, so whatever state is

$res = mysql_query($query); //misspelled query 

while($row=mysql_fetch_assoc($res)){

$state=$row['State'];
$zip=$row['zip'];  /////check all the array names for capitalization against ur db fields
$type=$row['type'];
$id=$row['custID'];


echo '<table align="center" cellspacing="10" cellpadding="15"><tr><td align="left"><b>State</b></td><td align="left"><b>Zip</b></td><td align="left"><b>Type</b></td>'; 

echo "<tr><td align=\"left\">$id</td><td align=\"left\">$state</td><td align=\"left\">$zip</td><td align=\"left\">$type</td></tr>";



}//end while








}//end go check

 

Thank you for all the help :)

Link to comment
Share on other sites

Thnak you for all the help but this is the error i got when i tried wrint the script from a php tutorial

The Error is

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/bob2/public_html/Search/search.php on line 46

 

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>

<form method="POST" action="?go">
   <p style="margin-top: 0; margin-bottom: 0"> </p>
   <p style="margin-top: 0; margin-bottom: 0">
   <input type="text" name="State" size="20">State</p>
   <p style="margin-top: 0; margin-bottom: 0">
   <input type="text" name="Zip" size="20">Zip</p>
   <p style="margin-top: 0; margin-bottom: 0">
   <input type="text" name="Type" size="20">Type</p>
   <p style="margin-top: 0; margin-bottom: 0">
   <input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>







<?php

if(isset($_GET['go'])){
mysql_connect('localhost', 'bob2_search', 'skater22') or die('Could not connect: ' . mysql_error());

$state=$_POST['State']; // u have to get the values from the form
$zip=$_POST['Zip'];
$type=$_POST['Type'];

$query = ("SELECT bob2_search FROM real WHERE `State` LIKE '%$state%' && `zip` LIKE '%$zip%' && `Type` LIKE '%$type%'"); // * has to be a table name, so whatever state is

$res = mysql_query($query); //misspelled query 

while($row=mysql_fetch_assoc($res)){ // here is line 46

$state=$row['State'];
$zip=$row['zip'];  /////check all the array names for capitalization against ur db fields
$type=$row['type'];
$id=$row['custID'];


echo '<table align="center" cellspacing="10" cellpadding="15"><tr><td align="left"><b>State</b></td><td align="left"><b>Zip</b></td><td align="left"><b>Type</b></td>'; 

echo "<tr><td align=\"left\">$id</td><td align=\"left\">$state</td><td align=\"left\">$zip</td><td align=\"left\">$type</td></tr>";



}//end while








}//end go check

Link to comment
Share on other sites

basically if you have something like this:

 


$id=$_POST['id'];
$text=$_POST['text'];

$query="UPDATE `table` SET `text`='$text' WHERE `id`='$id'";

 

then you want to make sure that there is actually something in your variables. So you can either add one of these two lines to ensure that you're populating your query properly.

 


$id=$_POST['id'];
$text=$_POST['text'];

///either

print_r($_POST);
exit();

////which will show the whole post array, a little confusing if you're new to arrays, but easiest
////or do

echo "id - $id text - $text";
exit();

/////which will just show your variables.
$query="UPDATE `table` SET `text`='$text' WHERE `id`='$id'";

 

 

so if you do either of these and nothing shows, then your form is prolly messed up, no action, wrong input names etc.

 

if it works, then manually put the variables value into the sql string like so:

 

if $text=sometext and $id=1, you'll do:

 

UPDATE `table` SET `text`='sometext' WHERE `id`='1'

 

then take that completed line and go to your DB management software, like phpmyadmin, and there should be either a tab or some item that'll let you run sql right there.

 

When you put that line in and hit go, if it returns nothing, then your echoing of results isnt the problem, if however it returns some entries, then you have to figure out why you are getting no results in your code.

 

the SQL tab is right at the top when you click a table name. its like BROWSE || STRUCTURE || SQL || OPERATIONS || ETC ETC

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.