Jump to content
Sign in to follow this  
Dubird

PHP and mySQL help

Recommended Posts

Ok, here's the thing. I'm trying to use a simple PHP script to take data from an HTML form and send it to the database. I've tried about 5 different variations of it, all doing the same thing, and I'm getting the same error:

Database ERROR: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

I can't find what's causing the problem. It is connecting and finding the database, it just can't run what I have. Which is:

<?php

  // Connect to the database server
  $cid = @mysql_connect("*****","*****","*****"); 

 if (!$cid) {
    echo( "<P>Unable to connect to the " .
          "database server at this time.</P>" );
    exit();
  }

  // Select the graphics database

  if (! @mysql_select_db("graphics") ) {
    echo( "<P>Unable to locate the graphics " .
          "database at this time.</P>" ); 
   exit(); 
 }

?>

<html>
<head>
<title>Insert New Record</title>
</head>
<body bgcolor="#ffffff">

<h2>Insert New Record</h2>

<?
    if ($_SERVER['REQUEST_METHOD'] == "POST")
    {
        # escape data and set variables
	$name=$_POST['name']; 
	$type=$_POST['type']; 
	$style=$_POST['style']; 
	$about=$_POST['about']; 
	$notes=$_POST['notes']; 
	$series=$_POST['series']; 
	$link=$_POST['link']; 
	$view=$_POST['view']; 
	$image=$_POST['image']; 
	$front=$_POST['front']; 


$sql  = "INSERT INTO testing (name, type, style, about, notes, series, link, view, image, front) VALUES ";
$sql .= "('$name','$type','$style','$about','$notes','$series','$link','$view','$image','$front',)";

        #execute SQL statement
        $result = mysql_query($sql, $cid);

        # check for error
        if (mysql_error()) { print "Database ERROR: " . mysql_error(); }

print "<h3><font color=red>New layout added</font></h3>";
}

?>

<form name="fa" action="enter_data2.php" method="POST">
<TABLE border=0 align=center width=400>
 <TR>
  <TD class=text>Name:</TD>
  <TD> <input type=text name="name"></TD>
 </TR>
 <TR>
  <TD class=text>Type of layout:</TD>
  <TD><input type=text name="type"></TD>
 </TR>
 <TR>
  <TD class=text>Catagory (blog, anime, generic)</TD>
  <TD><input type=text name="style"></TD>
 </TR>
 <TR>
  <TD class=text valign=top>About:</TD>
  <td valign=top><textarea name="NOTES" rows=4 cols=30></textarea></TD>
 </TR>
 <TR>
  <TD class=text>Notes:</TD>
  <TD><input type=text name="notes"></TD>
 </TR>
 <TR>
  <TD class=text>Series:</TD>
  <TD><input type=text name="series"></TD>
 </TR>
 <TR>
  <TD class=text>Download file:</TD>
  <TD><input type=text name="Link"></TD>
 </TR>
 <TR>
  <TD class=text>Preview:</TD>
  <TD><input type=text name="view"></TD>
 </TR>
 <TR>
  <TD class=text>Thumbnail:</TD>
  <TD><input type=text name="image"></TD>
 </TR>
 <TR>
  <TD class=text>Front image:</TD>
  <TD><input type=text name="front"></TD>
 </TR>

 <TR>
  <TD colspan=2 align=center><input type="submit" value="Submit" name="Submit"> <input type="reset" value="Reset" name="Reset"> 
 </TR>
</TABLE>
</FORM>     


</body>
</html>

help? *greatbigpuppydogeyes*


Yesterday was the deadline for all complaints!

acsig2016.jpg

Share this post


Link to post
Share on other sites


hehe you got a bit of a mess there. I can show you a much simpler way if you like.

Make a new file and call it mysql_connect.php

Type this in the file and save it.

<?php

DEFINE ('DB_USER', 'name'); // Insert your database username into the quotes.

DEFINE ('DB_PASSWORD', 'password'); // Insert your database password into the quotes.

DEFINE ('DB_HOST', 'localhost'); // This will most likely stay the same.

DEFINE ('DB_NAME', 'download'); //Insert your actual database name in the quotes.

$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error());

@mysql_select_db (DB_NAME) OR die('Could not select the database: ' . mysql_error() );

?>

Then use this as a add data script. I added as many comments as I could to help you understand what each thing does. If you need help I can help as much as possible in my free time.
<?php

//checks if someone clicked the submit button.

if (isset($_POST['submitted'])) {

//includes the database connection

include ('mysql_connect.php');

//checks if the name field is empty

if (empty($_POST['name'])) {

echo '<p><font color="red">You need to enter a name.</font></p>';

} else {

$name = $_POST['name'];

}

//checks if the layout field is empty

if (empty($_POST['layout'])) {

echo '<p><font color="red">You need to enter a type of layout.</font></p>';

} else {

$layout = $_POST['layout'];

}

//checks if the catagory field is empty

if (empty($_POST['catagory'])) {

echo '<p><font color="red">You need to enter a Catagory (blog, anime, generic).</font></p>';

} else {

$catagory2 = $_POST['catagory'];

}

//checking for vb/javascript script and preventing them from using it in the catagory filed.

$urlreg = $catagory2;

if( preg_match('/<script language=(.*?)/', $urlreg) ) {

echo '<p><font color="red">Scripting languages are not allowed</font></p>';

} else {

$catagory = $_POST['catagory'];

}

//grabs the data for name, layout, catagory and inserts it.

if ($name && $layout && $catagory) {

//inserts data into the downloads table

$query = "INSERT INTO downloads (name, layout, catagory, date) VALUES ('$name', '$layout', '$catagory', NOW())";

$result = @mysql_query($query);

//outputs message if problem or successfull

if ($result) {

echo '<p><font color="red">Data was added! <a href="index.php">Home</a></font></p>';

} else {

echo '<font color="red"><p>Data could not be added! Please try again.</p></font>';

}

} else {

echo '<p><font color="red">Please fill in the appropriate information</font></p>';

}

}

?>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">

<p><b>News Title :</b><br />

<input type="input" name="name" size="25" maxlength="60" value="<?php if(isset($_POST['name'])) echo $_POST['name']; ?>" /></p>

<p><b>Name :</b><br />

<input type="input" name="layout" size="15" maxlength="35" value="<?php if(isset($_POST['layout'])) echo $_POST['layout']; ?>" /></p>

<p><b>Message :</b><br />

<textarea rows="7" cols="55" name="catagory"><?php if(isset($_POST['catagory'])) echo $_POST['catagory']; ?></textarea></p>

<p><input type="submit" name="submit" value="Add data" /></p>

<input type="hidden" name="submitted" value="TRUE" /></p>

</form>

PS. the above code allows html and javascript to work in the input fields. I did add a small regex check for the category field to be checked and prevent any java script from being added. However if you dont plan to have any html or javascript at all in any of the input fields then you should use striptags to filter out any possible tags.


sig.php

All hail piggy, king of bacon ^)^

Share this post


Link to post
Share on other sites

I think gokuDX7 has done a wonderful job in helping you. I've only skimmed the code, but it looks very similar to my own forms.

I'm not up to speed with all of the regular expressions, but I've found this site very informative.

http://www.regular-expressions.info/

I would recommend creating a function for your PHP code and stick it in its own include file. It may add a little overhead, but unless you are expecting a high traffic volume (I sure don't), the organized structures of classes and functions in include files are very useful, making maintenance of the code later easier.

I recommend creating a file called debug.inc.php in your lib folder.

&lt;?php

//-----------------------------------------------------------------------
// Function:    Debug
// Description: Print the values entered straight to the pages for debug.
// Assumptions: session_start(); has already been called.
//-----------------------------------------------------------------------
function Debug($sName, $saValues)
{
    if (is_array($saValues))
    {
        print "&lt;p&gt;&lt;b&gt;$sName&lt;/b&gt;  ";
        print_r($saValues);
        print "&lt;/p&gt;\n";
    }
    else
    {
        print "&lt;p&gt;&lt;b&gt;$sName&lt;/b&gt;  $saValues &lt;/p&gt;\n";
    }
    return (1);
}

?&gt;

Add this include to the beginning of any PHP script in question.

include_once "lib/debug.inc.php";

I use this debug function regularly to print of variables, array, and pesky SQL statements that don't work.

I apologize for not knowing your knowledge base and experience ahead of time. I hope you find these tips useful.


Understand this lad, fate is a fickle lady. Work with the hand you're dealt and you may just be able to run your flag up the pole. Don't, and well, you may just find your mast cut down.

Share this post


Link to post
Share on other sites
I think gokuDX7 has done a wonderful job in helping you. I've only skimmed the code, but it looks very similar to my own forms.

I'm not up to speed with all of the regular expressions, but I've found this site very informative.

http://www.regular-expressions.info/

I would recommend creating a function for your PHP code and stick it in its own include file. It may add a little overhead, but unless you are expecting a high traffic volume (I sure don't), the organized structures of classes and functions in include files are very useful, making maintenance of the code later easier.

I recommend creating a file called debug.inc.php in your lib folder.

&lt;?php

//-----------------------------------------------------------------------
// Function:    Debug
// Description: Print the values entered straight to the pages for debug.
// Assumptions: session_start(); has already been called.
//-----------------------------------------------------------------------
function Debug($sName, $saValues)
{
    if (is_array($saValues))
    {
        print "&lt;p&gt;&lt;b&gt;$sName&lt;/b&gt;  ";
        print_r($saValues);
        print "&lt;/p&gt;\n";
    }
    else
    {
        print "&lt;p&gt;&lt;b&gt;$sName&lt;/b&gt;  $saValues &lt;/p&gt;\n";
    }
    return (1);
}

?&gt;

Add this include to the beginning of any PHP script in question.

include_once "lib/debug.inc.php";

I use this debug function regularly to print of variables, array, and pesky SQL statements that don't work.

I apologize for not knowing your knowledge base and experience ahead of time. I hope you find these tips useful.

if( preg_match('/<script language=(.*?)/', $urlreg) ) {

means check for <script language="anything after it".

So any time someone attempts to use

<script language="javascript" type="text/javascript">

alert("HAHAHAHAHA HAXOR");

</script>

it will prevent that and output an error message. Keep in mind the regex was only for the category input box as an example on how you can do it. If you want to prevent people from doing it in all the others then you have to do the same for them or just use the striptags function to prevent any code at all from being inputted (ie. <b>JAjJAJ</b> <marquee direction="left">jajJAjJAJ</marquee>...etc

Hope you guys understand. Regex can be a bit harder to understand but I rely on it heavily for things for some reason :/


sig.php

All hail piggy, king of bacon ^)^

Share this post


Link to post
Share on other sites

Ok, tried the form from goku, and still no dice. It says Data cannot be added. -_- I honestly don't care about leaving fields blank or allowing javascript because I'm the only one that will use it. I just want an easy way to update without having to log into my hosting control panel and navigating to my SQL admin panel. I'm a bit lost right now, because it retrieves information just fine. I just can't find a way to insert new data.


Yesterday was the deadline for all complaints!

acsig2016.jpg

Share this post


Link to post
Share on other sites

This could be becuse of 1 or 2 things. First check your mysql_connect.php file, make sure its pointing to the right database name. In case your not sure what it is, open up phpmyadmin and look at the drop down list on the left for the name of the place your data is being stored. That name is your database name. Make sure its spelled right in the mysql_connect.php file.

it could also be saying that because you may be missing a field name in your database. See this part in my code

INSERT INTO downloads (name, layout, catagory, date) VALUES ('$name', '$layout', '$catagory', NOW())
Look at your database and see if you have a name, layout, catagory, date field. If one is missing then thats why your getting the error.

If you can give me every field that you insert data into then I can update my source code to work for you. I'm sure now that you know you can just change the names around.


sig.php

All hail piggy, king of bacon ^)^

Share this post


Link to post
Share on other sites

ok, first of all, i'm using the same connect script i'm using for everything else....and it'll tell me if it's not connecting, so that's good....

also, i don't have those fields in my table, so i changed the script to reflect that....they're all correct, and it's the same ones that allow me to grab the data.....

here's what i've got (and yes, i'm not using the seperate connect file, i prefer it this way because i'm using several different databases, so it's easier for me to keep track this way)

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Insert New Record&lt;/title&gt;
&lt;/head&gt;
&lt;body bgcolor="#ffffff"&gt;

&lt;h2&gt;Insert New Record&lt;/h2&gt;

&lt;?php

  // Connect to the database server
  $dbc = @mysql_connect("localhost","******","******"); 

 if (!$dbc) {
    echo( "&lt;P&gt;Unable to connect to the " .
          "database server at this time.&lt;/P&gt;" );
    exit();
  }

  // Select the graphics database

  if (! @mysql_select_db("graphics") ) {
    echo( "&lt;P&gt;Unable to locate the graphics " .
          "database at this time.&lt;/P&gt;" ); 
   exit(); 
 }


//checks if someone clicked the submit button.
if (isset($_POST['submitted'])) {

//checks if the name field is empty
if (empty($_POST['name'])) {
echo '&lt;p&gt;&lt;font color="red"&gt;You need to enter a name.&lt;/font&gt;&lt;/p&gt;';
} else {
$name = $_POST['name'];
}
//checks if the type field is empty
if (empty($_POST['type'])) {
echo '&lt;p&gt;&lt;font color="red"&gt;You need to enter a type of layout.&lt;/font&gt;&lt;/p&gt;';
} else {
$type = $_POST['type'];
}
//checks if the style field is empty
if (empty($_POST['style'])) {
echo '&lt;p&gt;&lt;font color="red"&gt;You need to enter a catagory (blog, anime, generic).&lt;/font&gt;&lt;/p&gt;';
} else {
$style2 = $_POST['style'];
}

//checks if the about field is empty
if (empty($_POST['about'])) {
echo '&lt;p&gt;&lt;font color="red"&gt;You need to about.&lt;/font&gt;&lt;/p&gt;';
} else {
$about2 = $_POST['about'];
}

//checks if the notes field is empty
if (empty($_POST['notes'])) {
echo '&lt;p&gt;&lt;font color="red"&gt;You need to enter notes.&lt;/font&gt;&lt;/p&gt;';
} else {
$notes2 = $_POST['notes'];
}

//checks if the series field is empty
if (empty($_POST['series'])) {
echo '&lt;p&gt;&lt;font color="red"&gt;You need to enter series.&lt;/font&gt;&lt;/p&gt;';
} else {
$series2 = $_POST['series'];
}

//checks if the link field is empty
if (empty($_POST['link'])) {
echo '&lt;p&gt;&lt;font color="red"&gt;You need to enter link.&lt;/font&gt;&lt;/p&gt;';
} else {
$link2 = $_POST['link'];
}

//checks if the view field is empty
if (empty($_POST['view'])) {
echo '&lt;p&gt;&lt;font color="red"&gt;You need to enter preview.&lt;/font&gt;&lt;/p&gt;';
} else {
$view2 = $_POST['view'];
}

//checks if the image field is empty
if (empty($_POST['image'])) {
echo '&lt;p&gt;&lt;font color="red"&gt;You need to enter thumbnail.&lt;/font&gt;&lt;/p&gt;';
} else {
$image2 = $_POST['image'];
}

//checks if the front field is empty
if (empty($_POST['front'])) {
echo '&lt;p&gt;&lt;font color="red"&gt;You need to enter front.&lt;/font&gt;&lt;/p&gt;';
} else {
$front2 = $_POST['front'];
}


//grabs the data for name, type, style and inserts it.
if ($name &amp;&amp; $type &amp;&amp; $style &amp;&amp; $about &amp;&amp; $notes &amp;&amp; $series &amp;&amp; $link &amp;&amp; $view &amp;&amp; $image &amp;&amp; $front) {

//inserts data into the testing table
$query = "INSERT INTO testing (id, name, type, style, about, notes, series, link, view, image, front) VALUES ('', '$name', '$type', '$style', '$about', '$notes', '$series', '$link', '$view', '$image', '$front', NOW())";
$result = @mysql_query($query);

//outputs message if problem or successfull
if ($result) {
echo '&lt;p&gt;&lt;font color="red"&gt;Data was added! &lt;a href="index.php"&gt;Home&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;';
} else {
echo '&lt;font color="red"&gt;&lt;p&gt;Data could not be added! Please try again.&lt;/p&gt;&lt;/font&gt;';
}
} else {
echo '&lt;p&gt;&lt;font color="red"&gt;Please fill in the appropriate information&lt;/font&gt;&lt;/p&gt;';
}
}
?&gt;

&lt;form action="&lt;?php $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
&lt;p&gt;&lt;b&gt;Name:&lt;/b&gt;&lt;br /&gt;
&lt;input type="input" name="name" size="25" maxlength="60" value="&lt;?php if(isset($_POST['name'])) echo $_POST['name']; ?&gt;" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Type:&lt;/b&gt;&lt;br /&gt;
&lt;input type="input" name="type" size="15" maxlength="35" value="&lt;?php if(isset($_POST['type'])) echo $_POST['type']; ?&gt;" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Style:&lt;/b&gt;&lt;br /&gt;
&lt;input type="input" name="style" size="15" maxlength="35" value="&lt;?php if(isset($_POST['style'])) echo $_POST['style']; ?&gt;" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;About:&lt;/b&gt;&lt;br /&gt;
&lt;textarea rows="7" cols="55" name="about"&gt;&lt;?php if(isset($_POST['about'])) echo $_POST['about']; ?&gt;&lt;/textarea&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Notes:&lt;/b&gt;&lt;br /&gt;
&lt;input type="input" name="notes" size="15" maxlength="35" value="&lt;?php if(isset($_POST['notes'])) echo $_POST['notes']; ?&gt;" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Series:&lt;/b&gt;&lt;br /&gt;
&lt;input type="input" name="series" size="15" maxlength="35" value="&lt;?php if(isset($_POST['series'])) echo $_POST['series']; ?&gt;" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Download:&lt;/b&gt;&lt;br /&gt;
&lt;input type="input" name="link" size="15" maxlength="35" value="&lt;?php if(isset($_POST['link'])) echo $_POST['link']; ?&gt;" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Preview:&lt;/b&gt;&lt;br /&gt;
&lt;input type="input" name="view" size="15" maxlength="35" value="&lt;?php if(isset($_POST['view'])) echo $_POST['view']; ?&gt;" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Thumbnail:&lt;/b&gt;&lt;br /&gt;
&lt;input type="input" name="image" size="15" maxlength="35" value="&lt;?php if(isset($_POST['image'])) echo $_POST['image']; ?&gt;" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Front Thumbnail:&lt;/b&gt;&lt;br /&gt;
&lt;input type="input" name="front" size="15" maxlength="35" value="&lt;?php if(isset($_POST['front'])) echo $_POST['front']; ?&gt;" /&gt;&lt;/p&gt;


&lt;p&gt;&lt;input type="submit" name="submit" value="Add data" /&gt;&lt;/p&gt;
&lt;input type="hidden" name="submitted" value="TRUE" /&gt;&lt;/p&gt;
&lt;/form&gt;


&lt;/body&gt;
&lt;/html&gt;

the id field generates automaticly, so i don't actually enter data for it....


Yesterday was the deadline for all complaints!

acsig2016.jpg

Share this post


Link to post
Share on other sites

hehe your variable names don't match the ones in your mysql INSERT. Looks like you copy pasted my last "//checks if the * field is empty" code and removed the javascript but forgot to rename the variables. See how there's a 2 next to each variable name starting with $style2? You can remove all the 2's since the only reason I had the 2 on the last field was for the javascript prevention part. To try and make it clear I'll past the update so you can look and compare.

<html>

<head>

<title>Insert New Record</title>

</head>

<body bgcolor="#ffffff">

<h2>Insert New Record</h2>

<?php

// Connect to the database server

$dbc = @mysql_connect("localhost","****","*****");

if (!$dbc) {

echo( "<P>Unable to connect to the " .

"database server at this time.</P>" );

exit();

}

// Select the graphics database

if (! @mysql_select_db("graphics") ) {

echo( "<P>Unable to locate the graphics " .

"database at this time.</P>" );

exit();

}

//checks if someone clicked the submit button.

if (isset($_POST['submitted'])) {

//checks if the name field is empty

if (empty($_POST['name'])) {

echo '<p><font color="red">You need to enter a name.</font></p>';

} else {

$name = $_POST['name'];

}

//checks if the type field is empty

if (empty($_POST['type'])) {

echo '<p><font color="red">You need to enter a type of layout.</font></p>';

} else {

$type = $_POST['type'];

}

//checks if the style field is empty

if (empty($_POST['style'])) {

echo '<p><font color="red">You need to enter a catagory (blog, anime, generic).</font></p>';

} else {

$style = $_POST['style'];

}

//checks if the about field is empty

if (empty($_POST['about'])) {

echo '<p><font color="red">You need to about.</font></p>';

} else {

$about = $_POST['about'];

}

//checks if the notes field is empty

if (empty($_POST['notes'])) {

echo '<p><font color="red">You need to enter notes.</font></p>';

} else {

$notes = $_POST['notes'];

}

//checks if the series field is empty

if (empty($_POST['series'])) {

echo '<p><font color="red">You need to enter series.</font></p>';

} else {

$series = $_POST['series'];

}

//checks if the link field is empty

if (empty($_POST['link'])) {

echo '<p><font color="red">You need to enter link.</font></p>';

} else {

$link = $_POST['link'];

}

//checks if the view field is empty

if (empty($_POST['view'])) {

echo '<p><font color="red">You need to enter preview.</font></p>';

} else {

$view = $_POST['view'];

}

//checks if the image field is empty

if (empty($_POST['image'])) {

echo '<p><font color="red">You need to enter thumbnail.</font></p>';

} else {

$image = $_POST['image'];

}

//checks if the front field is empty

if (empty($_POST['front'])) {

echo '<p><font color="red">You need to enter front.</font></p>';

} else {

$front = $_POST['front'];

}

//grabs the data for name, type, style and inserts it.

if ($name && $type && $style && $about && $notes && $series && $link && $view && $image && $front) {

//inserts data into the testing table

$query = "INSERT INTO testing (id, name, type, style, about, notes, series, link, view, image, front) VALUES ('', '$name', '$type', '$style', '$about', '$notes', '$series', '$link', '$view', '$image', '$front', NOW())";

$result = @mysql_query($query);

//outputs message if problem or successfull

if ($result) {

echo '<p><font color="red">Data was added! <a href="index.php">Home</a></font></p>';

} else {

echo '<font color="red"><p>Data could not be added! Please try again.</p></font>';

}

} else {

echo '<p><font color="red">Please fill in the appropriate information</font></p>';

}

}

?>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">

<p><b>Name:</b><br />

<input type="input" name="name" size="25" maxlength="60" value="<?php if(isset($_POST['name'])) echo $_POST['name']; ?>" /></p>

<p><b>Type:</b><br />

<input type="input" name="type" size="15" maxlength="35" value="<?php if(isset($_POST['type'])) echo $_POST['type']; ?>" /></p>

<p><b>Style:</b><br />

<input type="input" name="style" size="15" maxlength="35" value="<?php if(isset($_POST['style'])) echo $_POST['style']; ?>" /></p>

<p><b>about:</b><br />

<textarea rows="7" cols="55" name="about"><?php if(isset($_POST['about'])) echo $_POST['about']; ?></textarea></p>

<p><b>Notes:</b><br />

<input type="input" name="notes" size="15" maxlength="35" value="<?php if(isset($_POST['notes'])) echo $_POST['notes']; ?>" /></p>

<p><b>Series:</b><br />

<input type="input" name="series" size="15" maxlength="35" value="<?php if(isset($_POST['series'])) echo $_POST['series']; ?>" /></p>

<p><b>Download:</b><br />

<input type="input" name="link" size="15" maxlength="35" value="<?php if(isset($_POST['link'])) echo $_POST['link']; ?>" /></p>

<p><b>Preview:</b><br />

<input type="input" name="view" size="15" maxlength="35" value="<?php if(isset($_POST['view'])) echo $_POST['view']; ?>" /></p>

<p><b>Thumbnail:</b><br />

<input type="input" name="image" size="15" maxlength="35" value="<?php if(isset($_POST['image'])) echo $_POST['image']; ?>" /></p>

<p><b>Front Thumbnail:</b><br />

<input type="input" name="front" size="15" maxlength="35" value="<?php if(isset($_POST['front'])) echo $_POST['front']; ?>" /></p>

<p><input type="submit" name="submit" value="Add data" /></p>

<input type="hidden" name="submitted" value="TRUE" /></p>

</form>

</body>

</html>

PS. it's common practice to keep a separate DB file for everything, then just run your select,insert..etc statements from the php script(s). This way you don't have 100's of files with your db info in them. The code I showed you before also outputs an error if it can't connect.

Oh also theres really no need to add the id field in if its automatic. You can leave it blank and it works just fine. Your choice though. Theres no harm in having it there.

Tell me if the above works. If not then past your db structure so I can test (go to phpmyadmin, browse to the database of this script's, click export at the top, copy past the output here).


sig.php

All hail piggy, king of bacon ^)^

Share this post


Link to post
Share on other sites

I knew it was something stupidly simple. ^_^; But it still says Data can't be added. And you don't have to walk me through everything. If I don't know how to do something you've said, I'll ask.

-- phpMyAdmin SQL Dump
-- version 2.6.4-pl3
-- http://www.phpmyadmin.net
-- 
-- Host: localhost:3306
-- Generation Time: Jun 08, 2007 at 06:44 AM
-- Server version: 4.0.26
-- PHP Version: 5.0.5
-- 
-- Database: `graphics`
-- 

-- --------------------------------------------------------

-- 
-- Table structure for table `testing`
-- 

CREATE TABLE `testing` (
  `id` smallint(50) NOT NULL auto_increment,
  `name` varchar(50) NOT NULL default '',
  `type` varchar(50) NOT NULL default '',
  `style` varchar(50) NOT NULL default '',
  `about` text NOT NULL,
  `notes` varchar(150) NOT NULL default '',
  `series` varchar(50) NOT NULL default '',
  `link` varchar(50) NOT NULL default '',
  `view` varchar(50) NOT NULL default '',
  `image` varchar(50) NOT NULL default '',
  `front` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=70 ;

-- 
-- Dumping data for table `testing`
-- 

Also, I don't really need a check to see if a field is filled out. Depending on what I'm doing, I may need to leave a field blank. I'm not sure of the best way to take it out of the code you've got and make it work. (but, frankly, I'll be happy just to get the code to work before I worry about that! ^_^; )


Yesterday was the deadline for all complaints!

acsig2016.jpg

Share this post


Link to post
Share on other sites

ahh found your other problem. You removed my "date" field in the insert but your left the now() function in it, so I removed it. everything works fine now.

PS. if you want to remove the check for empty spots then just remove the code that looks like this for the specific data you don't care if its empty.

//checks if the front field is empty

if (empty($_POST['front'])) {

echo '<p><font color="red">You need to enter front.</font></p>';

} else {

$front = $_POST['front'];

}

If you remove it then replace it with $front = $_POST['front'];

that way the code doesn't brake. get what i'm saying?

Finished code here:

<html>

<head>

<title>Insert New Record</title>

</head>

<body bgcolor="#ffffff">

<h2>Insert New Record</h2>

<?php

// Connect to the database server

$dbc = @mysql_connect("localhost","***","***");

if (!$dbc) {

echo( "<P>Unable to connect to the " .

"database server at this time.</P>" );

exit();

}

// Select the graphics database

if (! @mysql_select_db("graphics") ) {

echo( "<P>Unable to locate the graphics " .

"database at this time.</P>" );

exit();

}

//checks if someone clicked the submit button.

if (isset($_POST['submitted'])) {

//checks if the name field is empty

if (empty($_POST['name'])) {

echo '<p><font color="red">You need to enter a name.</font></p>';

} else {

$name = $_POST['name'];

}

//checks if the type field is empty

if (empty($_POST['type'])) {

echo '<p><font color="red">You need to enter a type of layout.</font></p>';

} else {

$type = $_POST['type'];

}

//checks if the style field is empty

if (empty($_POST['style'])) {

echo '<p><font color="red">You need to enter a catagory (blog, anime, generic).</font></p>';

} else {

$style = $_POST['style'];

}

//checks if the about field is empty

if (empty($_POST['about'])) {

echo '<p><font color="red">You need to about.</font></p>';

} else {

$about = $_POST['about'];

}

//checks if the notes field is empty

if (empty($_POST['notes'])) {

echo '<p><font color="red">You need to enter notes.</font></p>';

} else {

$notes = $_POST['notes'];

}

//checks if the series field is empty

if (empty($_POST['series'])) {

echo '<p><font color="red">You need to enter series.</font></p>';

} else {

$series = $_POST['series'];

}

//checks if the link field is empty

if (empty($_POST['link'])) {

echo '<p><font color="red">You need to enter link.</font></p>';

} else {

$link = $_POST['link'];

}

//checks if the view field is empty

if (empty($_POST['view'])) {

echo '<p><font color="red">You need to enter preview.</font></p>';

} else {

$view = $_POST['view'];

}

//checks if the image field is empty

if (empty($_POST['image'])) {

echo '<p><font color="red">You need to enter thumbnail.</font></p>';

} else {

$image = $_POST['image'];

}

//checks if the front field is empty

if (empty($_POST['front'])) {

echo '<p><font color="red">You need to enter front.</font></p>';

} else {

$front = $_POST['front'];

}

//grabs the data for name, type, style and inserts it.

if ($name && $type && $style && $about && $notes && $series && $link && $view && $image && $front) {

//inserts data into the testing table

$query = "INSERT INTO testing (name, type, style, about, notes, series, link, view, image, front) VALUES ('$name', '$type', '$style', '$about', '$notes', '$series', '$link', '$view', '$image', '$front')";

$result = @mysql_query($query);

//outputs message if problem or successfull

if ($result) {

echo '<p><font color="red">Data was added! <a href="index.php">Home</a></font></p>';

} else {

echo '<font color="red"><p>Data could not be added! Please try again.</p></font>';

}

} else {

echo '<p><font color="red">Please fill in the appropriate information</font></p>';

}

}

?>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">

<p><b>Name:</b><br />

<input type="input" name="name" size="25" maxlength="60" value="<?php if(isset($_POST['name'])) echo $_POST['name']; ?>" /></p>

<p><b>Type:</b><br />

<input type="input" name="type" size="15" maxlength="35" value="<?php if(isset($_POST['type'])) echo $_POST['type']; ?>" /></p>

<p><b>Style:</b><br />

<input type="input" name="style" size="15" maxlength="35" value="<?php if(isset($_POST['style'])) echo $_POST['style']; ?>" /></p>

<p><b>about:</b><br />

<textarea rows="7" cols="55" name="about"><?php if(isset($_POST['about'])) echo $_POST['about']; ?></textarea></p>

<p><b>Notes:</b><br />

<input type="input" name="notes" size="15" maxlength="35" value="<?php if(isset($_POST['notes'])) echo $_POST['notes']; ?>" /></p>

<p><b>Series:</b><br />

<input type="input" name="series" size="15" maxlength="35" value="<?php if(isset($_POST['series'])) echo $_POST['series']; ?>" /></p>

<p><b>Download:</b><br />

<input type="input" name="link" size="15" maxlength="35" value="<?php if(isset($_POST['link'])) echo $_POST['link']; ?>" /></p>

<p><b>Preview:</b><br />

<input type="input" name="view" size="15" maxlength="35" value="<?php if(isset($_POST['view'])) echo $_POST['view']; ?>" /></p>

<p><b>Thumbnail:</b><br />

<input type="input" name="image" size="15" maxlength="35" value="<?php if(isset($_POST['image'])) echo $_POST['image']; ?>" /></p>

<p><b>Front Thumbnail:</b><br />

<input type="input" name="front" size="15" maxlength="35" value="<?php if(isset($_POST['front'])) echo $_POST['front']; ?>" /></p>

<p><input type="submit" name="submit" value="Add data" /></p>

<input type="hidden" name="submitted" value="TRUE" /></p>

</form>

</body>

</html>


sig.php

All hail piggy, king of bacon ^)^

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Sign in to follow this  

×
×
  • Create New...