drop down menu to choose table (mysql)

A

Anonymous

Guest
I am about to pull what little hair I have let trying to figure if this is possible. On my website I have a drop down menu with different tables in the drop down part.

What I am trying to do is have a user choose the table to get info from then in the search box type in keywords of what to search for.

After successfully login in, I am going to call function to choose different operation in mysql ,
but what is wrong?
Parse error: syntax error, unexpected '>' in C:\Apache\Apache2\htdocs\verifypassword.php on line 25
Code:
<?php 
$username = $_POST[user];
$password = $_POST[pass];
$ref = $_SERVER['HTTP_REFERER'];
   
        if( ($username=='zhao') && ($password=='zhao') &&($ref == "http://localhost/login.php")) 
           [color=red] process_form( );[/color]//call function to choose the table to get info from then in the search
//box type in keywords of what to search for.
            else 
        echo " <font size='20' />ACCESS DENIED!</font>  "; 
 
[color=red]function process_form( )[/color] {
 $conn = mysql_connect('localhost', 'root', '000405');
if(!$conn) {
	echo '<p>Unable to connect to the database server at this time.</p>';
                exit();
}
mysql_select_db('firstdb',$conn);

//Initialize the table, set amount = 10000
$sql1 = 'CREATE TABLE checking (amount FLOAT(8))';
$sql2 = 'CREATE TABLE saving (amount FLOAT(8))'; 

echo "Please select a transaction, enter a $ amount and submit:"

<form>//[b][color=red]line[/color] 25[/b]
<select name = "choice">
<option value="dc">Deposit into checking account</option>
<option value="ds">Deposit into saving account</option>
<option value="tc">Transfer into checking account</option>
<option value="ts">Transfer into saving account</option>
<option value="wc">Withdraw into checking account</option>
<option value="ws">Withdraw into saving account</option>
</select>
</form>


 }
?>
 
If you want to put HTML in your PHP script, you should close the PHP block first:


Code:
<?php
// snip
echo "Please select a transaction, enter a $ amount and submit:"
// close the PHP block:
?>
<form>
<select name = "choice">
<option value="dc">Deposit into checking account</option>
<option value="ds">Deposit into saving account</option>
<option value="tc">Transfer into checking account</option>
<option value="ts">Transfer into saving account</option>
<option value="wc">Withdraw into checking account</option>
<option value="ws">Withdraw into saving account</option>
</select>
</form>
<?php
// and open it again to close the if block
 }
?>

Coditor
 
Thanks
Well, I changed, but terrible thing happened.
Fatal error: Call to undefined function mysql_connect() in C:\Apache\Apache2\htdocs\verifypassword.php on line 15

Code:
<html>
<?php 
$username = $_POST[user];
$password = $_POST[pass];
$ref = $_SERVER['HTTP_REFERER'];
   
        if( ($username=='zhao') && ($password=='zhao') &&($ref == "http://localhost/login.php")) 
            process_form( );
//call function to choose the table to get info from then in the search
//box type in keywords of what to search for.
            else 
        echo " <font size='20' />ACCESS DENIED!</font>  "; 
 
function process_form( ) {
 $conn = mysql_connect('localhost', 'root', '000405');
if(!$conn) {
	echo '<p>Unable to connect to the database server at this time.</p>';
                exit();
}
mysql_select_db('firstdb',$conn);

//Initialize the table, set amount = 10000
$sql1 = 'CREATE TABLE checking (amount FLOAT(8))';
$sql2 = 'CREATE TABLE saving (amount FLOAT(8))'; 

echo "Please select a transaction, enter a $ amount and submit:"
?>
<form>
<select name = "choice">
<option value="dc">Deposit into checking account</option>
<option value="ds">Deposit into saving account</option>
<option value="tc">Transfer into checking account</option>
<option value="ts">Transfer into saving account</option>
<option value="wc">Withdraw into checking account</option>
<option value="ws">Withdraw into saving account</option>
</select>
</form>
<?php
echo "Transaction Success";
}
?>
</html>
 
It looks like the mysql functions haven't been enabled. Check your php.ini file for extension=php_mysql.dll. Make sure it's not commented by a semicolon ( ; ).

Coditor
 
Can you send us a URL with your phpinfo?

FYI - just in case - this can be done by a small script:

<?php
phpinfo();
?>

Coditor
 
Thanks, Coditor.

I have resloved this issue. I added PHPIniDir "C:/php"
into the bottom of httpd.conf. I don't know why.

However another problem is coming:please look at my code.
The result always display "Table 'firstdb.checking' doesn't exist".
Even I remove the statement
Code:
$check_checking = mysql_query('DROP TABLE IF EXISTS checking');


Code:
  function process_form( ) {
          $conn = mysql_connect('localhost', 'root', '000405');
          if(!$conn) {
	echo '<p>Unable to connect to the database server at this time.</p>';
                exit();
                    }
          mysql_select_db('firstdb',$conn);

         //Initialize the table, set amount = 10000
       $check_checking = mysql_query('DROP TABLE IF EXISTS checking');
          $sql1 = 'CREATE TABLE checking (amount FLOAT(8))';
          mysql_query("INSERT INTO checking(amount) VALUES('10000' ) ") or die(mysql_error()); 
           $result1 = mysql_query("SELECT * FROM checking") or die(mysql_error()); 
             // store the record of the "checking" table into $row1
   $row1 = mysql_fetch_array( $result1);
        // Print out the contents of the entry 
     echo "Checking Account Initial Amount: \n".$row1['amount'];
 
You execute the query to drop the table, but you don't execute the query to create the table. You only store that in $sql, but it's never sent to MySql. The table therefor won't exist.

Coditor
 
You need to put mysql_query() in your CREATE TABLE code.
That will run your query... like you're doing in the other ones.
 
THANKS EVERYBODY!

Now after correct codes, it runs, but
it gives me a sweet hug:
"Can't connect to MySQL server on 'localhost' (10061)"
help me again!
 
Back
Top