Jump to content

insert form into sql


truck7758

Recommended Posts

Hi all,

 

Can anyone see why this form wont insert the data into my sql database? When i click submit i get a blank page and the data doesn't submit.

 

<?php

if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form

?>

 

<BODY TEXT="red" LINK="yellow" BGCOLOR="black">

<p>

<a href="http://www.ticketline.co.uk">

<img src="new_logo2.jpg" alt="Ticketline_logo" align="center" width="210" height="95" />

</a>

Date: <? print strftime("%d/%m/%Y"); ?>

</p>

<h1 align="center">Create New Supplier</h1>

<p align="center">

<form method="post" action="<?php echo $PHP_SELF;?>">

<table>

<tr>

<td align="center">Name:</td>

<td align="center">Tel No:</td>

<td align="center">Fax:</td>

<td align="center">Website:</td>

<td align="center">E-Mail:</td>

 

</tr>

<tr>

<td align="center"><input type='text' name='name' value='' size='25'></td>

<td align="center"><input type='text' name='telno' value='' size='15'></td>

<td align="center"><input type='text' name='fax' value='' size='15'></td>

<td align="center"><input type='text' name='website' value='' size='15'></td>

<td align="center"><input type='text' name='email' value='' size='15'></td>

</tr>

<tr>

 

<td align="center">Account No:</td>

<td align="center">Account Manager:</td>

<td align="center">Account Login:</td>

<td align="center">Account Password:</td>

 

</tr>

<tr>

 

<td align="center"><input type='text' name='accnumber' value='' size='15'></td>

<td align="center"><input type='text' name='accmanager' value='' size='15'></td>

<td align="center"><input type='text' name='acclogin' value='' size='15'></td>

<td align="center"><input type='text' name='accpassword' value='' size='15'></td>

</tr>

<tr>

<td align="center">Address:</td>

<td align="center">Other Info:</td>

</tr>

<tr align="center">

<td><textarea rows="5" cols="20" name="address" wrap="physical"></textarea><br /></td>

<td><textarea rows="5" cols="20" name="other" wrap="physical"></textarea><br /></td>

</tr>

</table>

<input type="submit" value="Submit" name="submit" STYLE="font-family:sans-serif; font-size:large;

font-style:italic; background:red; color:black; width:6em; height:1.5em">

</form>

 

<?

} else {

 

 

$host = "localhost";

$username = "username";

$password = "password";

$database = "orders";

 

$mysqli = mysqli_connect('localhost','uname','password');

$mysqli->select_db('supplier');

 

$name = $_POST["name"];

$telno = $_POST["telno"];

$fax = $_POST["fax"];

$website = $_POST["website"];

$email = $_POST["email"];

$accnumber = $_POST["accnumber"];

$accmanager = $_POST["accmanager"];

$acclogin = $_POST["acclogin"];

$accpassword = $_POST["accpassword"];

$address = $_POST["address"];

$other = $_POST["other"];

 

 

$name = addslashes($name);

$telno= addslashes($telno);

$fax = addslashes($fax);

$website= addslashes($website);

$email= addslashes($email);

$accnumber= addslashes($accnumber);

$accmanager = addslashes($accmanager);

$acclogin = addslashes($acclogin);

$accpassword = addslashes($accpassword);

$address = addslashes($address);

$other = addslashes($other);

 

 

if(!$mysqli)

 

{

echo " Error: could not connect to database.";

 

exit;

}

 

 

 

$sql="INSERT INTO `supplier`

(`name`,

`address`,

`telno`,

`fax`,

`website`,

`accountno`,

`accountmanager`,

`email`,

`accountlogin`,

`accountpwd`,

`otherinfo`)

VALUES ('".$name."',

'".$address."',

'".$telno."',

'".$fax."',

'".$website."',

'".$accnumber."',

'".$accmanager."',

'".$email."',

'".$acclogin."',

'".$accpassword."',

'".$other."')";

 

$result = mysqli_query($mysqli, $sql, MYSQLI_USE_RESULT);

 

 

if($result)

 

{

echo mysqli_affected_rows($mysqli)." .Supplier Table Updated.";

}

 

 

 

 

}

?>

 

 

Cheers,

Mike

Link to comment
Share on other sites

Hi,

 

I have just done this in mysql and it inserted into the table:

INSERT INTO `supplier`
(`name`,
`address`,
`telno`,
`fax`,
`website`,
`accountno`,
`accountmanager`,
`email`,
`accountlogin`,
`accountpwd`,
`otherinfo`)
values
("test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test");

 

i also echo'd $sql and i get the following:

INSERT INTO `supplier` (`name`, `address`, `telno`, `fax`, `website`, `accountno`, `accountmanager`, `email`, `accountlogin`, `accountpwd`, `otherinfo`) VALUES ('mike', '25 dkfhj,kf wffjkk fefe fedfgggdf m1 1jg', '12345678', '87654321', 'www.test.co.uk', '7758', 'me', 'michael@test.co.uk', 'test', '1234', 'asefjsd sdfgvsdfgdfg sdfgsdf')

 

This seems correct to me.

 

Thanks,

Mike

Link to comment
Share on other sites

Your script is setting the $user/$pass variables etc, but never actually uses them.

See your following snippet of code:

$username = "username";
$password = "password";
$database = "orders";

$mysqli = mysqli_connect('localhost','uname','password');

 

Therefore I expect that you're not actually connecting to the database in the first place. I would verify this as it seems inconsistent.

 

Also, you might consider using mysqli_error() to see what your error is (i.e. why it's not working...)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.