Jump to content

Recommended Posts

Thanks for taking the time to help me out.

I'm trying to do what seems to be a simple select statement.  All I want is for someone to enter in their email address and check the database.  If it's there, retrieve that row.

The problem is that I'm getting all confused as to the proper format of the select statement using the form variables.  I've seen .$variable.  '$variable'  and even '%".$variable."%'.

Can someone take a look and help me out?

Here's my code:


$queryterm=$_POST['updateterm'];

$hostname="server";
$username="DBuser";
$password="DBPassword";
$dbname="DBName";
$usertable="TableName";

mysql_connect($hostname, $username, $password) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

[color=purple]$query = mysql_query("SELECT * FROM '$usertable' WHERE " '$queryterm' "= email");[/color]

if (!$query) {
  die("query Failed. " . mysql_error());
}

While ($row = mysql_fetch_array($result)) {
echo $row['email'];
}

Link to comment
https://forums.phpfreaks.com/topic/13953-select-statement-with-html-variables/
Share on other sites

You need to surround strings with single quotes in MySQL. In your example you have the quotes surrounding the wrong items. Try something like this:
[code]<?php
$query = "SELECT * FROM $usertable WHERE email = '$queryterm'";
$result = mysql_query($query) or die("There was a problem with the query: $query<br>" . mysql_error());
while ($row = mysql_fetch_assoc($result))
    echo $row['email'] . "<br>\n";
?>[/code]

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