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
https://forums.phpfreaks.com/topic/92254-insert-form-into-sql/
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', '[email protected]', 'test', '1234', 'asefjsd sdfgvsdfgdfg sdfgsdf')

 

This seems correct to me.

 

Thanks,

Mike

Link to comment
https://forums.phpfreaks.com/topic/92254-insert-form-into-sql/#findComment-472634
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
https://forums.phpfreaks.com/topic/92254-insert-form-into-sql/#findComment-472638
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.