Forum Moderators: coopster
I'll explain a bit better.
I want a drop down menu with:
1 2 3 4
As the different options. Selecting option one will change the data in ID 1 in a MySQL, Selecting 2 will change the data in ID 2, etc.
I would then like a seperate PHP file to display only the data stored in each ID. As I want to be able to make my mIRC bots access this data directly.
Here's what I have so far, but I'm not sure if I'm on the right track.
This is my form.php
<form name="form1" method="post" action="connect.php">
<p>Select Script
<select name="bot" id="bot">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</p>
<p>
Data: <input name="data" type="text" id="data">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form> I also need a display.php and connect.php, however I'm unsure how to get them to work with the MySQL database.
I know the basis of the connection
$host = "localhost";
$user = "username";
$pass = "password";
$dbname = "database";
Could anyone please help me?
Thanks
~Karl
//This function returns a connection to our database on the CS Server
function connectDB(){
$user = ""; //put your username here
$psswd = "";//put your password here
$host = "";//put your host here i.e. localhost if it's on your machine
$dbn = "";//put the name of your database here
$conn = DB::connect("mysql://{$user}:{$psswd}@{$host}/{$dbn}");
if (DB::isError($conn)){
print "Connect Failed" . "\n";
die($conn->getMessage() . "\n");
}
return $conn;
}
?>
//This function queries the database that it is passed as a connection
//with the query that it is passed
function queryDB($conn, $query){
$result = $conn->query($query);
if(DB::isError($result))
return 0;
return $result;
}
now if you saved it as connection.php require that in any file you want to connect to your database with. Then when you want to query your database you put this in. The reason this is nice because since your using more than one file if anything should change on your MySQL DB you can just edit the connection.php file and it works for all of your other files
$query = "Select Some_Column from Some_Table where Something = 'someText' order by 'Some_Column' ASC;";
//that query can be anything you want it to be I just gave you
//an example one
//now set result = to this
$result = queryDB(connectDB(), $query);
//now if you wanted to show all of the results
//you type this you can format this however you want
//this will just echo them you could put in html tags
//or css tags or anything of that nature
while($row = $result->fetchRow(DB_FETCHMODE_ASSOC)){
echo($row['Some_Column_Here'];
}
let me know if you need anymore help
Ok.. Installing PEAR isn’t bad, here is what you do:
Open a command line window (i.e. Start->Run->cmd)
Go to the PHP directory, in my case C:\php. Type go-pear.bat. Follow the instructions.
The PEAR extension get installed in C:\php\PEAR directory.
Once PEAR is installed, go to the php.ini file in your Apache2 directory. Find the
Code:
;include_path = ".;c:\\php\\includes"
Remove the semi-colon (to un-comment it), and then add C:\php\PEAR to it
Code:
include_path = ".;c:\\php\\includes;C:\\php\\PEAR"