Jump to content

Run SQL Query via button click on user input


Go to solution Solved by benanamen,

Recommended Posts

I have a database written in

 and stored on a server. The table I will be accessing is called dataRep and houses Rep Data. This data is user input via form submission. Upon coming to the website there is an option to "View Rep Information" by submitting the Rep's ID that was given. That Rep ID will be the auto increment repID from the table. Upon clicking the button, it opens a new window that should display the rep's data. It does not, however.

 

Here is the [html] the user will see:

 
<div class="pop_box">
<a class="rms-button" href="#popup1">Enter Rep Number Here</a> </div>
<div id="popup1" class="overlay">
<div class="popup">
    <a class="close" href="#">×</a>
<div align="center"><br>
       <br>
       <p>Enter rep number in box below. Submission will open new window.</p>
    <form method="get" action="/data/repPrepare.php" target="_blank" >
      <input type="text" id="repSelect" name="repSelect" placeholder="Enter Rep Number Given Here" />  
        <button type="submit" class="newbutton">VIEW</button>
    </form>
</div>
</div>

...and here is the [php] I have tried, which I get the following error:

[indent]"Could not get data: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[repSelect]' at line 1"[/indent]

<?php 
 $dbhost = 'mhhost';
 $dbuser = 'myuser';
 $dbpass = 'mypass';

 $conn = mysql_connect($dbhost, $dbuser, $dbpass);

  if(! $conn ) {
    die('Could not connect: ' . mysql_error());
 }

 $sql = 'SELECT * FROM dataRep WHERE repID = [repSelect]';
 mysql_select_db('reviewmy_jos1');
 $retval = mysql_query( $sql, $conn );

 if(! $retval ) {
   die('Could not get data: ' . mysql_error());
 }

 while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
  echo "Rep ID :{$row['repID']}  <br> ".
     "Rep NAME : {$row['repName']} <br> ".
     "Rep Bio : {$row['repBio']} <br> ".
         "Rep Certs : {$row['repCerts']} <br> ".
     "--------------------------------<br>";
 }

 echo "Fetched data successfully\n";

 mysql_close($conn);
 ?>

I am truly stuck and have been dealing with this issue for two weeks. I would appreciate any assistance that can be provided. I just need the [php] to pull the data tied the repID that the user puts in the box. When I started this I assumed it would be rather easy. I guess that's what I get for assuming. Either way, I'm missing something here. Is there a possibility that this can not be done? Like, I should be using AJAX instead? 

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.