Jump to content

[SOLVED] entering no variables


contra10

Recommended Posts

hey i have a code and its not entering the values into php...im wondering if its because i have other forms on the same page and its follwing that php script instead of this one...well here it is

<?php
// Connects to your Database 
mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error()); 

//This code runs if the form has been submitted
if (isset($_POST['submitpost'])) { 

//This makes sure they did not leave any fields blank
if (!$_POST['userpost']) {
die('You did not enter a post');
}
$userpostg = mysql_real_escape_string($_POST['userpost']);

//This gets today's date 
$date = time () ; 


//This puts the day, month, and year in seperate variables 
$day = date('d', $date) ; 
$month = date('F', $date) ; 
$year = date('Y', $date) ;

// now we insert it into the database
$insertpost = "INSERT INTO posts_groups (gid, gname, uid, uname, post, month, day, year)
VALUES ('$id', '$groupname', '$userid', '$username', '$userpost', '$month', '$day', '$year')";
echo ($insertpost);
}
?>


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" width="800" align="center" height="100">
<tr>
<td align="center"><textarea name="userpost" type="description" cols="50" rows="5" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr>
<tr><td align="center"><input type="hidden" name="postuserid" value="<?php echo ($userid);?>"></td></tr>
<tr><td align="center"><input type="hidden" name="postusername" value="<?php echo ($username);?>"></td></tr>
<tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr>
</table>
</form>
<table border="1" width="800" align="center">
<tr><td width="800"height="500">Posts2</td></tr>
</table>

Link to comment
Share on other sites

ok i tried to enter it with one variable ($id)

 

<?php
// Connects to your Database 
mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error()); 

//This code runs if the form has been submitted
if (isset($_POST['submitpost'])) { 

//This makes sure they did not leave any fields blank
if (!$_POST['userpost']) {
die('You did not enter a post');
}
$userpostg = mysql_real_escape_string($_POST['userpost']);
$userid = mysql_real_escape_string($_POST['useridpost']);
//This gets today's date 
$date = time () ; 


//This puts the day, month, and year in seperate variables 
$day = date('d', $date) ; 
$month = date('F', $date) ; 
$year = date('Y', $date) ;

// now we insert it into the database
$insertpost = "INSERT INTO posts_groups (gid, gname, uid, uname, post, month, day, year)
VALUES ('$id', '$groupname', '$userid', '$username', '$userpost', '$month', '$day', '$year')";
echo ($insertpost);
}
?>


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" width="800" align="center" height="100">
<tr>
<td align="center"><textarea name="userpost" type="description" cols="50" rows="5" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr>
<tr><?php echo"<input type='hidden' name='useridpost' value='$userid'>"?></td></tr>
<tr><td align="center"><input type="hidden" name="postusername" value="<?php echo $_POST['username'];?>"></td></tr>
<tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr>
</table>
</form>
<table border="1" width="800" align="center">
<tr><td width="800"height="500">Posts2</td></tr>
</table>

 

thats wat i did jus to see if it was going to work but it didn't enter

 

I have other issets on the page is it possible that the code is following the other issets...note this isset is submitpost as $_POST the other one is just submit

Link to comment
Share on other sites

try to replace this code

$insertpost = "INSERT INTO posts_groups (gid, gname, uid, uname, post, month, day, year)
VALUES ('$id', '$groupname', '$userid', '$username', '$userpost', '$month', '$day', '$year')";

 

by this code

$insertpost = "INSERT INTO posts_groups (gname, uid, uname, post, month, day, year)
VALUES ('$groupname', '$userid', '$username', '$userpost', '$month', '$day', '$year')";

but you ought to enable auto increment for the table

Link to comment
Share on other sites

woops but i do the mysql query() b4 and still never got anywhere here was the statments

 

<?php
// Connects to your Database 
mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error()); 

//This code runs if the form has been submitted
if (isset($_POST['submitpost'])) { 

//This makes sure they did not leave any fields blank
if (!$_POST['userpost']) {
die('You did not enter a post');
}
$userpostg = mysql_real_escape_string($_POST['userpost']);
$userid = mysql_real_escape_string($_POST['useridpost']);
//This gets today's date 
$date = time () ; 


//This puts the day, month, and year in seperate variables 
$day = date('d', $date) ; 
$month = date('F', $date) ; 
$year = date('Y', $date) ;

// now we insert it into the database
$insertpost = "INSERT INTO posts_groups (uid, uname)
VALUES ('$userid', '$username', '$userpostg')";
$add_post2 = mysql_query($insertpost) or die(mysql_error()); 
}
?>


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" width="800" align="center" height="100">
<tr>
<td align="center"><textarea name="userpost" type="description" cols="50" rows="5" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr>
<tr><?php echo"<input type='hidden' name='useridpost' value='$userid'>"?></td></tr>
<tr><?php echo"<input type='hidden' name='username' value='$username'>"?></td></tr>
<tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr>
</table>
</form>

Link to comment
Share on other sites

updated...

 

<?php
mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error()); 

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

if(is_numeric($_POST['grp'])){
$id = $_POST['grp'];

$query= "SELECT * FROM groups WHERE id = '$id'";
$result = mysql_query($query) or die(mysql_error());;
$group = mysql_fetch_assoc($result);
$groupname = "{$group['name']}";
$groupid = "{$group['id']}";

$query2= "SELECT id FROM users WHERE username = '$username'";
$result2 = mysql_query($query2) or die(mysql_error());;
$usera = mysql_fetch_assoc($result2);
$userid = "{$usera['id']}";

$userpostg = mysql_real_escape_string($_POST['userpost']);
//This gets today's date 
$date = time () ; 


//This puts the day, month, and year in seperate variables 
$day = date('d', $date) ; 
$month = date('F', $date) ; 
$year = date('Y', $date) ;
}
//This makes sure they did not leave any fields blank
if (!$_POST['userpost']) {
die('You did not enter a post');
}

// now we insert it into the database
$insertpost = "INSERT INTO posts_groups (gid, gname, uid, uname, post, month, day, year)
VALUES ('$groupid', '$groupname', $userid', '$username', '$userpostg', '$month', '$day', '$year')";
$add_post2 = mysql_query($insertpost) or die(mysql_error()); 

  
?>


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" width="800" align="center" height="100">
<tr>
<td align="center"><textarea name="userpost" type="description" cols="50" rows="5" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr>
<tr><input type='hidden' name='grp' value='<?php echo $_GET['grp']; ?>'></td></tr>
<tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr>
</table>
</form>

<?php
}
else
{
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" width="800" align="center" height="100">
<tr>
<td align="center"><textarea name="userpost" type="description" cols="50" rows="5" maxlength="10" STYLE="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr>
<tr><input type='hidden' name='grp' value='<?php echo $_GET['grp']; ?>'></td></tr>
<tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr>
</table>
</form>

<?php
}
?>

Link to comment
Share on other sites

Try this:

 

<?php

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("registration") or die(mysql_error());

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

$test = $_POST['grp'];
$test2 = $_POST['userpost'];

echo "Right here... $test ...there should be the grp field data<br>";
echo "Here should be the textarea data... $test2 ...if submit's working";


if(is_numeric($_POST['grp'])) {

$id = $_POST['grp'];
$result = mysql_query("SELECT * FROM groups WHERE id = '$id'") or die(mysql_error());
$group = mysql_fetch_array($result, MYSQL_ASSOC);
$groupname = $group['name'];
$groupid = $group['id'];

$result2 = mysql_query("SELECT id FROM users WHERE username = '$username'") or die(mysql_error());
$usera = mysql_fetch_array($result2, MYSQL_ASSOC);
$userid = $usera['id'];

$userpostg = mysql_real_escape_string($_POST['userpost']);

// This gets today's date 
$date = time(); 

//This puts the day, month, and year in separate variables 
$day = date('d', $date); 
$month = date('F', $date); 
$year = date('Y', $date);
}

// This makes sure they did not leave any fields blank
if (empty($_POST['userpost'])) {
die('You did not enter a post');
}

// Now we insert it into the database
$add_post2 = mysql_query("INSERT INTO posts_groups (gid, gname, uid, uname, post, month, day, year) VALUES ('$groupid', 

'$groupname', $userid', '$username', '$userpostg', '$month', '$day', '$year')") or die(mysql_error()); 
  

echo <<<chappers
<form action="{$_SERVER['PHP_SELF']}" method="post">
<table border="0" width="800" align="center" height="100">
<tr>
<td align="center"><textarea name="userpost" type="description" cols="50" rows="5" STYLE="color: #FFFFFF; font-family: Verdana; 

font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr>
<tr><input type='hidden' name='grp' value='{$_GET['grp']}'></td></tr>
<tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr>
</table>
</form>
chappers;
}

else {

echo <<<chappers
<form action="{$_SERVER['PHP_SELF']}" method="post">
<table border="0" width="800" align="center" height="100">
<tr>
<td align="center"><textarea name="userpost" type="description" cols="50" rows="5" STYLE="color: #FFFFFF; font-family: Verdana; 

font-weight: bold; font-size: 12px; background-color: #72A4D2;"></textarea></td></tr>
<tr><input type='hidden' name='grp' value='{$_GET['grp']}'></td></tr>
<tr><td align="center"><input type="submit" name="submitpost" value="Post"></td></tr>
</table>
</form>
chappers;
}
?>

 

And if it doesn't work, say what's happening or not happening. You'll notice I've added echo "Right here... $_POST['grp'] ...there should be the grp field data"; and same for textarea field. That's to make sure that when you submit the form, everything's being sent across.

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.