Jump to content

ucwords(strtolower(?)) and supplied argument is not a valid ?


Recommended Posts

Problem 1 )

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/wasetorg/public_html/search.php on line 177

$data = mysql_query("select * from person where $type like '%$search%' ORDER BY lname ASC LIMIT 0,30"); 
                     
while($info=mysql_fetch_array($data))
{
	if($info['no']=="1")
	{
	echo"			{ucwords(strtolower($info['lname']))} {ucwords(strtolower($info['fname']))} ";  //line 177
	}
}

 

Problem 2)

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:.........

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:.........

 

while($info=mysql_fetch_array($data))
{
	if($info['no']=="1")
	{
	echo"			{$info['lname']} {$info['fname']}";
	}

 

Some of the mysql datas are uppercase/lowercase like ERIK, Erik, erik....maybe because of that it gives "supplied argument is not a valid" worning...

 

where $type like '%$search%'

Im using like operators, if I convert all data with ucwords(), I can match the true datas....

 

How can I solve these problems? I didnt do it....

	echo"			{ucwords(strtolower($info['lname']))} {ucwords(strtolower($info['fname']))} ";  //line 177

 

Two things with that:

- you can't call functions within "" quotes.

- if you use array variable within "" quotes you must surround it with {} braces. <- this one is actually causing a warning

 

You should do:

	echo "{".ucwords(strtolower($info['lname']))."} {".ucwords(strtolower($info['fname']))."}";  //line 177

 

That's assuming you want {} around last name and first name (I think you might put them by mistake)

		
echo ucwords(strtolower($info['lname']))." ".ucwords(strtolower($info['fname']))."}, {".$info['country']." (Nat) <br>;
echo ucwords(strtolower($info['university'])) <br>;

 

I didnt apply the code

 

Parse error: syntax error, unexpected '(', expecting ',' or ';

 

		
echo ucwords(strtolower($info['lname']))." ".ucwords(strtolower($info['fname']))."}, {".$info['country']." (Nat) <br>";
echo ucwords(strtolower($info['university']))." <br>";

 

 

Try to find an editor that would highlight your code. It will make spotting mistakes like this much easier

$Rows = mysql_num_rows(mysql_query("select * from person where $type like '%$search%'")) or die (mysql_error ()); 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/public_html/search.php on line 187

-----------------------and------------------

$data = mysql_query("select * from person where $type like '%$search%' ORDER BY lname ASC LIMIT $start,$limit") or die (mysql_error ());

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 'like '%%'' at line 1

 

What are these problems?

 

 

Make this:

$Rows = mysql_num_rows(mysql_query("select * from person where $type like '%$search%'")) or die (mysql_error ()); 

 

This:

$query = mysql_query("select * from person where $type like '%$search%'") or die(mysql_error());
$Rows = mysql_num_rows($query);

Basically that meant that the query is most likely failing and returning a MySQL Resource ID.

 

The second error is saying that $search is null, so make sure your variables are being set properly.

					<?php
include("dbconfig.php");

function title_case($title) {
  // Our array of 'small words' which shouldn't be capitalised if
  // they aren't the first word.  Add your own words to taste.
  $smallwordsarray = array(
    'of','a','the','and','an','or','nor','but','is','if','then','else','when',
    'at','from','by','on','off','for','in','out','over','to','into','with'
    );
  // Split the string into separate words
  $words = explode(' ', $title);
  foreach ($words as $key => $word)
  {
    // If this word is the first, or it's not one of our small words, capitalise it
    // with ucwords().
    if ($key == 0 or !in_array($word, $smallwordsarray))
      $words[$key] = ucwords(strtolower($word));
  }
  // Join the words back into a string
  $newtitle = implode(' ', $words);
  return $newtitle;
}


$search = mysql_real_escape_string($_POST['search']);
$type = mysql_real_escape_string($_POST['type']);

$page = $_GET["page"]; 
if(empty($page) or !is_numeric($page)){ 
$page = 1;
}

$limit = 25; 

$query1 = mysql_query("select * from person where $type like '%$search%'") or die (mysql_error () );
$rowNumber = mysql_num_rows($query1); 

$pageNumber = ceil($rowNumber / $limit); 
$start = ($page-1)*$limit; 

$data = mysql_query("select * from person where $type like '%$search%' ORDER BY lname ASC LIMIT $start,$limit") or die (mysql_error ()); 
                     
while($info=mysql_fetch_array($data))
{
	if($info['committee_no']=="1")
	{
                     echo title_case($info['lname'])." ".title_case($info['fname']).", ".$info['country']." <br>";
	}
	if($info['no']=="2")
	{
                     echo title_case($info['lname'])." ".title_case($info['fname']).", ".$info['country']."  <br>";
	}
}


if($page > 1){ 
$back = $page-1;
echo "<p align=\"center\"><b><a href=\"search.php?page=$back\"><< Back </a>";

}else{ 

echo "<p align=\"center\"><b> << Back ";
}

echo " | ";

if($page>=$pageNumber){ 

echo "Next >> </b></p>";

}else{ 

$next = $page+1;

echo "<a href=\"search.php?page=$next\">Next >></a></b></p>";

}
?>

 

Im trying to using paging 0-25, 25-50 .......

 

first page is listing all datas 0-25, but when I click to next page....program is giving there errors?...

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 'like '%%'' at line 1

 

I used this paging code before, i didnt face any prbblem....but now this scipts first page is showing the datas 0-25, why the second page is giving this error ????

 

Some of the mysql datas are uppercase/lowercase like ERIK, Erik, erik...and im trying the search with lowercase...it can be an error?

$_POST['search'] and $_POST['type'] is not blank....

for example im searching 'Mobile', program finds 43 rows....

 

First page is listing 25 records, but when I click the next page, just an error....next page must show 18 records...

 

 

Because your $search and $type variables are not set when you go from page to page.

 

You're using links to switch between pages. Not only links are $_GET not $_POST, but your links don't even conatin these variables.

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.