×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Error Updating From mySQL To MySQLi

Error Updating From mySQL To MySQLi

Error Updating From mySQL To MySQLi

(OP)
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.

RE: Error Updating From mySQL To MySQLi

CODE --> 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.

RE: Error Updating From mySQL To MySQLi

Quote (ChrisHirst)

No quotes around your string variable assignment.

Doesn't need them. That is Heredoc syntax and works without quotes. http://php.net/manual/en/language.types.string.php...


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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close