jkanclerz Posted April 14, 2008 Share Posted April 14, 2008 Complete noobie with PHP. Overview: My company is running a travel incentive program. Each month our customers receive a point statement showing how much credit their account has earned toward the trip. I've set up a Wordpress site to keep them informed about the trip. What I want to do: In sidebar.php of WP I would like to have a simple one line form, where the customer enters their account number and it retrieves the points/credit they've earned. I can create a new table in MySQL, calling it "Points" with 2 columns, the primary key being their account number, and the second column, "Points." My problem is I'm not sure how to call this data from the table with PHP. I'm thinking it should be fairly straightforward, especially since I'm not concerned with securing this information. Your help with this is appreciated. Cheers, Jesse Link to comment https://forums.phpfreaks.com/topic/101094-calling-information-from-table-with-a-form/ Share on other sites More sharing options...
craygo Posted April 14, 2008 Share Posted April 14, 2008 what you need to do is have a text box so they can enter it and submit it to a page. I would use a post method. then on the page you select them to go to you would assign the post value. <?php // set your database variables $dbhost = 'localhost'; // database server $dbuser = 'username'; // Username $dbpass = 'password'; // Password $dbname = 'test'; // db name // connect to the database $mysql_conn = @mysql_connect($dbhost, $dbuser, $dbpass) or die("Could not connect to MySql, check host, username, password <br />".mysql_error()); @mysql_select_db($dbname, $mysql_conn) or die("Could not connect to database <br />".mysql_error()); $account = $_POST['account_num']; $sql = "SELECT * FROM `Points` WHERE `account_num` = '$account'"; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res); echo "account number = {$row['account_num']} Points = {$row['Points']}"; ?> Obviously it would be much more fancy. I would suggest though having a primary key as an auto number then having the 2 fields. Cause if you want to get fancy with it later, it would be much easier to link tables together through auto numbers rather than account numbers. Ray Link to comment https://forums.phpfreaks.com/topic/101094-calling-information-from-table-with-a-form/#findComment-517051 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.