Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP and SQL syntax issue
    text
    copied!<p>I am having problems with a (should be simple) bit of code. I am getting info from a form and trying to echo out an entry/ies in a database that match the form specifications. I think that my HTML is correct, and my problem lies in the PHP. Here is my code that I need help with:</p> <pre><code>&lt;?php $submit = @$_POST['submit']; $gender = $_POST['gender']; $hair = $_POST['hair']; $height = $_POST['height']; $body = $_POST['body']; if ($submit){ //open database $connect = mysql_connect("xxxx", "xxxx", "xxxx") or die("Couldnt Connect to Server"); mysql_select_db("xxxx") or die("Couldnt find database"); $query = mysql_query("SELECT * FROM `table` WHERE `gender`='$gender' AND `hair`='$hair' AND `height`='$height' AND `body`='$body'"); $query_run = mysql_query($query); if ($query_run = mysql_query($query)) { while ($query_row = mysql_fetch_assoc($query_run)) { $pic = $query_row['picture']; }; }; }; ?&gt; </code></pre> <p>This is a self submitting page <code>&lt;form action='thispage.php' method='post'&gt;</code>. Later down the page in the empty space is where I am going to echo $pic.</p> <p>Is this method correct/the best way to do it? If need be, I will post the code for the entire page. It is only 75 lines right now.</p> <p>And before I am told that I should be using SQLi, this is more of a proof of concept right now, and more importantly I don't know how to make the changes from SQL to SQLi. </p> <p><strong>edit:</strong> Within the form, there are only options, not text input (if that matters)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload