Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Updating From mySQL To MySQLi

Status
Not open for further replies.
Mar 23, 2015
37
0
0
US
Hello,

I have a simple connect, query and display db rows that needs to be upgraded. Everything was working last week when I was last using my website now I'm getting errors because mySQL is finally dead.

I now have
Code:
<?php

	$db = new mysqli("$host","$username","$password","$database") or die("couldn't connect to the database!");
	
	if($db->connect_errno > 0){
    	die('Unable to connect to database [' . $db->connect_error . ']');
	}
	
    $sql = <<<SQL
		SELECT * 
		FROM 'workshops' 
		WHERE 'wDate' >= CURDATE() AND type = 'edu' ORDER BY 'wDate', 'wTime'
	SQL;
	
	if(!$result = $db->query($sql)){
    	die('There was an error running the query [' . $db->error . ']');
	}
?>

some html...

Code:
<?php 
	while($row = $result->fetch_assoc())
	{      
?>
<dl>
    <dt><?php echo date('m/d/Y', strtotime($row['wDate']))?> - <?php echo date('g:i A', strtotime($row['wTime']))?></dt>
    <dd><?php echo $row['Location']?></dd>
    <div itemscope itemtype='schema.org/PostalAddress'>
      <dd><span itemprop='streetAddress'><?php echo $row['Address']?></span></dd>
      <dd><span itemprop='addressLocality'><?php echo $row['City']?></span>, <span itemprop='addressRegion'><?php echo $row['State']?></span>  <span 
        itemprop='postalCode'><?php echo $row['Zip']?></span></dd>
    </div>
    <dd><?php echo $row['Presenter']?></dd>
</dl>
                
<?php 
  }
  mysql_close($db);
?>

Now on that first row line where I try to echo the date and time I'm getting a syntax error, unexpected quoted-string and whitespace (T-ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING). I'm not convinced my error is in that actual line of code. I think the code I actually changed in the query or while loop is the issue, but I'm not certain.

Also if anyone notices anything else I should change I'd appreciate the help.

Thanks.

 
PHP:
$sql = <<<SQL
		SELECT * 
		FROM 'workshops' 
		WHERE 'wDate' >= CURDATE() AND type = 'edu' ORDER BY 'wDate', 'wTime'
	SQL;

No quotes around your string variable assignment.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
ChrisHirst said:
No quotes around your string variable assignment.

Doesn't need them. That is Heredoc syntax and works without quotes.

With that said, can you try outputting the entire $row array just to verify its correct.

Code:
echo "<pre>" . print_r($row,1) . "</pre>";










----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top