Jawanaut Posted March 10, 2017 Share Posted March 10, 2017 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? Quote Link to comment Share on other sites More sharing options...
Solution benanamen Posted March 10, 2017 Solution Share Posted March 10, 2017 Your query is not valid. More importantly you are using obsolete mysql code that has been completely removed from Php. You need to use PDO. https://phpdelusions.net/pdo Quote Link to comment Share on other sites More sharing options...
Jawanaut Posted March 10, 2017 Author Share Posted March 10, 2017 Thank you for the response and sending me in the right direction. Quote Link to comment Share on other sites More sharing options...
Jawanaut Posted March 10, 2017 Author Share Posted March 10, 2017 Is it possible to query my database based on user input from a form? Quote Link to comment Share on other sites More sharing options...
benanamen Posted March 10, 2017 Share Posted March 10, 2017 (edited) Yes. The form values will be available in the POST array. e.g $_POST['first_name'] Edited March 10, 2017 by benanamen Quote Link to comment Share on other sites More sharing options...
Jawanaut Posted March 10, 2017 Author Share Posted March 10, 2017 Any suggestions as to how? Am I not going about it right? Should I not use PHP? Would AJAX be easier or better any way? Quote Link to comment Share on other sites More sharing options...
benanamen Posted March 10, 2017 Share Posted March 10, 2017 Forget about ajax. Lookup Mysql CRUD tutorials. You need to learn basic form html first. Quote Link to comment Share on other sites More sharing options...
Jawanaut Posted March 10, 2017 Author Share Posted March 10, 2017 See you have a site.... how much would you charge for the php to do what I need? Quote Link to comment Share on other sites More sharing options...
benanamen Posted March 10, 2017 Share Posted March 10, 2017 (edited) Email me. See my Profile. Site wont allow you to get PM's yet. Edited March 10, 2017 by benanamen Quote Link to comment Share on other sites More sharing options...
Jawanaut Posted March 10, 2017 Author Share Posted March 10, 2017 ok Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.