Click to See Complete Forum and Search --> : SQL Insert
lukezweb
01-05-2004, 12:47 PM
Hi im having problems with this script I keep getting different errors, Im to get the board name from createboard in the session, then it goes to createboard2 where the session opnes again and it transfers the data to insert the values into the sql tbale then the session is closed, any help is greatfully appreciated :)
<?php
} else if ($action == "createboard") {
session_start();
session_register($name);
$name = $post['boardname'];
?>
<table width=92% cellspacing=1 border=0 align=center bgcolor=005177 cellpadding=4>
<tr>
<td class=catbg>
Simple Forums :: Admin :: Create A Board
</td>
</tr>
<tr>
<td class=windowbg>
<form method=post name=createboard action=index.php?action=createboard2>
Board Name:
<br/><input type=text id=boardname>
<p><input type=submit value=Submit name=submit id=submit>
</form>
</td>
</table>
<?php
} else if ($action == "createboard2") {
session_start();
$user = "shoutbox_admin";
$host = "localhost";
$password = "admin";
$database = "shoutbox_simple";
$connection = mysql_connect($host,$user,$password)
$db = mysql_select_db($database,$connection)
$sql = 'INSERT INTO `boards` ( `id` , `name` , `topics` , `posts` , `lastreply` ) ';
$sql .= 'VALUES ( "", "$name", "0", "0", "N/A" );';
$sql .= '';
$result = mysql_query($sql);
session_end();
} else {
?>
Luke :)
What part is causing trouble and what errors are you getting?
lukezweb
01-05-2004, 02:01 PM
Originally posted by pyro
What part is causing trouble and what errors are you getting?
i figured it was that part, i got Parse Errors
Which line, specifically? The more info you give, the easier it is on me/us, and I like easy. ;)
lukezweb
01-05-2004, 02:11 PM
Originally posted by pyro
Which line, specifically? The more info you give, the easier it is on me/us, and I like easy. ;)
i have no idea but i reduced my whole file to jsut that i eliminated that area :)
It should be giving you a line number with the error message, but no matter.
Try putting $name = $post['boardname']; before the session_register on line 4 and then chage your SQL to something more like this:
$sql = "INSERT INTO `boards` (`id`, `name`, `topics`, `posts`, `lastreply`) VALUES ('', '$name', '0', '0', 'N/A')";
lukezweb
01-05-2004, 02:50 PM
Originally posted by pyro
It should be giving you a line number with the error message, but no matter.
Try putting $name = $post['boardname']; before the session_register on line 4 and then chage your SQL to something more like this:
$sql = "INSERT INTO `boards` (`id`, `name`, `topics`, `posts`, `lastreply`) VALUES ('', '$name', '0', '0', 'N/A')";
am trying it now ;)
lukezweb
01-05-2004, 02:54 PM
Originally posted by lukezweb
am trying it now ;)
i get:
Parse error: parse error in /home/shoutbox/public_html/simpleforum/index.php on line 214
lukezweb
01-05-2004, 02:57 PM
Originally posted by lukezweb
i get:
thata line had....
$db = mysql_select_db($database,$connection)
so i added a semi-colon and it worked but now ig et on the create boards page......
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/shoutbox/public_html/simpleforum/index.php:3) in /home/shoutbox/public_html/simpleforum/index.php on line 180
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/shoutbox/public_html/simpleforum/index.php:3) in /home/shoutbox/public_html/simpleforum/index.php on line 180
lukezweb
01-05-2004, 03:02 PM
Originally posted by pyro
Which is...?
the sessions part I think i may knwo where the problem is.....
i have the basic page layout etc then between the body tags have if action= blah stuff in the action part, i have the session stuff whihc wont be valid as its not in the headers so how can i get around this?
lukezweb
01-05-2004, 04:47 PM
<table width=92% cellspacing=1 border=0 align=center bgcolor=005177 cellpadding=4>
<tr>
<td class=catbg>
Simple Forums :: Admin :: Create A Board
</td>
</tr>
<tr>
<td class=windowbg>
<form method=post name=createboard action=index.php?action=createboard2>
Board Name:
<br/><input type=text id=boardname>
<?php
if ($_POST['submit']) {
$user = "shoutbox_admin";
$host = "localhost";
$password = "admin";
$database = "shoutbox_simple";
$connection = mysql_connect($host,$user,$password)
or die ("Could not connect");
$db = mysql_select_db($database,$connection)
or die ("Could not select");
$sql = "INSERT INTO `boards` (`name`, `topics`, `posts`, `lastreply`) VALUES (' ".$_POST['boardname']." ', '0', '0', 'N/A')";
mysql_query($sql);
}
?>
<p><input type=submit value=Submit name=submit id=submit>
</form>
</td>
</table>
i decided to use this but there are no errors LOL accept it doent add it any help?