RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting

need help with insert.php

Join Date: Jun 2005
Posts: 20
Reputation: nike123 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nike123 nike123 is offline Offline
Newbie Poster

Re: need help with insert.php

  #6  
Oct 18th, 2005
oh no, thanks for the advice, I got it working ages ago, just got my tutor to look at it for me. Am not too sure how it worked (Not so much of a programming person you see)(


Originally Posted by Sp!ke
Oh, shoot, we're both wrong, heh!

This will most DEFINATELY work.

[php]<?php
if (isset($_POST['add'])) {
include ('config.php');
include ('opendb.php');

mysql_select_db('DB_NAME', $mysql);
// You must tell it what the connection resource is, as well
// as which databse you will be using. Make sure that in opendb.php,
// the function mysql_connect(); is being set to $mysql.

$username = $_POST['username'];
$password = $_POST['password'];

$query = "INSERT INTO user (host, user, password, select_priv, insert_priv, update_ priv) VALUES ('localhost', '" . $username . "', 'PASSWORD(" . $password . "'), 'Y', 'Y', 'Y')";
// You need to concatenate with the '.' command.
// I know this will work, I've used it hunderds of times.

mysql_query($query) or die('Error, insert query failed ');

$query2 = "FLUSH PRIVILEGES";
mysql_query($query2) or die('Error, insert query failed');

include ('closedb.php');
echo "New MySQL user added";
} else {
?>
<html><body>
<form method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Username</td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td width="100">Password</td>
<td><input name="password" type="text" id="password"></td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td><input name="add" type="submit" id="add" value="Add New User"></td>
</tr>
</table>
</form></body></html>[/php]
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 4:41 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC