View Single Post
 
Old January 4th, 2005, 02:54 PM
leno leno is offline
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm, sorted it out myself. You can actually store a SQL query in a Javascript variable and just display the variable. So the inputs are first checked, put into variables, and then inputted in the DB using PHP, something like this:

Code:
<?php
// When submit button is pressed
if(isset($sbm)==1) {
?>
<script type="text/javascript">
// Read names and e-mail address from POSTED form
var name = "<?php echo $_POST['name']; ?>"
var email = "<?php echo $_POST['email']; ?>"

// Set the mysql query in var query
var query = '<?php echo "INSERT INTO names (name, email) VALUES ("$' + name + ', $' + email + ')";'

// Connect to MySQL
document.write('<?php echo "\$db = mysql_connect(\"\", \"\", \"\")/r"; ?>')
document.write('<?php echo "\$query = ' + query + '/r";')
document.write('<?php echo "mysql_query($query)";')
document.write('<?php echo "mysql_close()";')
</script>
<?php
}
?>
Would this work theoretically? Maybe there are some mistakes in the /-es and ' or ", but could this work?