Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
learning php decided id make a little database editing program to help me
getting a error and i cant find whats wrong here is my codeCode: Select all
<?php
?>
<html>
<head>
<link href="../../style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div align="center" class="style7">
<p class="style5"><h1>Database Editing Program</h1></p>
</div>
<?php echo "<h3>Insert Data</h3><form method='POST' action='proccess.php'>
<input type='hidden' name='type' value='insert'>
Columns To insert into (<I>separate with commas)</i>
<input name='selection' type='text'><br>
Table Name
<input type='text' name='insert_table_name'><br>
Data to insert
<input name='insert_inserts' type='text'>
<input type='submit' name='Submit' value='Submit'>
</form>";
?>
<?php
echo "<h3>Truncate Table</h3>
<form action='proccess.php' method='POST'>
Truncate <input type='text' name='truncate_table_name'/>
<input type='submit' name='Submit' value='Sumbit' />
<input type='hidden' name='type' value='truncate'>
</form>
"
?>
</body>
</html>Code: Select all
<link href="../../style.css" rel="stylesheet" type="text/css">
<?php
include ("../../includes/connect.inc.php");
@$type = $_POST['type'];
@$insert_selection = $_POST['selection'];
@$insert_table_name = $_POST['insert_table_name'];
@$insert_inserts = $_POST['insert_inserts'];
@$truncate_table = $_POST['truncate_table_name'];
@$truncate_succesfull;
?>
<?php
// Function to insert data
function insert($insert_selection,$insert_table_name,$insert_inserts, $conn, $db) {
$sql = "INSERT INTO $insert_table_name ($insert_selection) VALUES ('$insert_table_name')";
$result = mysqli_query($conn, $sql);
}
// function to truncate
function truncate($truncate_table, $conn, $db) {
$sql = "TRUNCATE $truncate_table";
$result = mysqli_query($conn, $sql);
$truncate_succesfull = "1";
}
?>
<?php
if ($type == "insert")
{
insert($type, $insert_selection, $insert_table_name, $insert_inserts, $conn, $db) or die("Error - Cannot Insert Data!");
}
elseif ($type == "truncate") {
truncate($truncate_table, $conn, $db);
if ($truncate_succesfull == "1") {
echo "Truncate Succesfull!";
}
}
elseif (!isset($type)) {
echo "<h1>Do Not Run this Page On Its Own You Wont Get Any Result</h1>";
}
?>Code: Select all
Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\Documents and Settings\Peter\Desktop\www\apache\htdocs\cms\admin\db\proccess.php on line 17Thank you all
Jcart | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]